or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

generic-types.mdindex.mdjson-schema.mdopenapi-v2.mdopenapi-v3_1.mdopenapi-v3.md

json-schema.mddocs/

0

# JSON Schema Types

1

2

Base JSON Schema interface supporting the schema definitions used throughout OpenAPI specifications. This interface provides the foundation for schema validation and type definition across all OpenAPI versions.

3

4

## Capabilities

5

6

### Base JSON Schema Interface

7

8

Core JSON Schema interface providing the fundamental schema definition structure.

9

10

```typescript { .api }

11

/**

12

* Base JSON Schema interface supporting core JSON Schema specification

13

*/

14

interface IJsonSchema {

15

/** Schema identifier */

16

id?: string;

17

/** JSON Schema version */

18

$schema?: string;

19

/** Schema title */

20

title?: string;

21

/** Schema description */

22

description?: string;

23

/** Multiple of constraint for numeric values */

24

multipleOf?: number;

25

/** Maximum value constraint */

26

maximum?: number;

27

/** Exclusive maximum flag */

28

exclusiveMaximum?: boolean;

29

/** Minimum value constraint */

30

minimum?: number;

31

/** Exclusive minimum flag */

32

exclusiveMinimum?: boolean;

33

/** Maximum string length constraint */

34

maxLength?: number;

35

/** Minimum string length constraint */

36

minLength?: number;

37

/** Regular expression pattern for string validation */

38

pattern?: string;

39

/** Additional items schema for arrays */

40

additionalItems?: boolean | IJsonSchema;

41

/** Items schema definition for arrays */

42

items?: IJsonSchema | IJsonSchema[];

43

/** Maximum array length constraint */

44

maxItems?: number;

45

/** Minimum array length constraint */

46

minItems?: number;

47

/** Unique items constraint for arrays */

48

uniqueItems?: boolean;

49

/** Maximum object properties constraint */

50

maxProperties?: number;

51

/** Minimum object properties constraint */

52

minProperties?: number;

53

/** Required properties array */

54

required?: string[];

55

/** Additional properties schema */

56

additionalProperties?: boolean | IJsonSchema;

57

/** Schema definitions collection */

58

definitions?: {

59

[name: string]: IJsonSchema;

60

};

61

/** Object properties schemas */

62

properties?: {

63

[name: string]: IJsonSchema;

64

};

65

/** Pattern-based property schemas */

66

patternProperties?: {

67

[name: string]: IJsonSchema;

68

};

69

/** Property dependencies */

70

dependencies?: {

71

[name: string]: IJsonSchema | string[];

72

};

73

/** Enumeration of valid values */

74

enum?: any[];

75

/** Value type or array of types */

76

type?: string | string[];

77

/** All of constraint - schema must match all sub-schemas */

78

allOf?: IJsonSchema[];

79

/** Any of constraint - schema must match at least one sub-schema */

80

anyOf?: IJsonSchema[];

81

/** One of constraint - schema must match exactly one sub-schema */

82

oneOf?: IJsonSchema[];

83

/** Not constraint - schema must not match the sub-schema */

84

not?: IJsonSchema;

85

/** JSON Reference to another schema */

86

$ref?: string;

87

}

88

```

89

90

**Usage Examples:**

91

92

```typescript

93

import { IJsonSchema } from "openapi-types";

94

95

// Basic string schema

96

const stringSchema: IJsonSchema = {

97

type: "string",

98

minLength: 1,

99

maxLength: 100,

100

pattern: "^[a-zA-Z0-9]+$"

101

};

102

103

// Object schema with properties

104

const userSchema: IJsonSchema = {

105

type: "object",

106

title: "User",

107

description: "User account information",

108

required: ["id", "email"],

109

properties: {

110

id: {

111

type: "string",

112

pattern: "^[0-9]+$"

113

},

114

email: {

115

type: "string",

116

format: "email"

117

},

118

name: {

119

type: "string",

120

minLength: 1

121

},

122

age: {

123

type: "integer",

124

minimum: 0,

125

maximum: 150

126

}

127

},

128

additionalProperties: false

129

};

130

131

// Array schema

132

const tagsSchema: IJsonSchema = {

133

type: "array",

134

items: {

135

type: "string",

136

minLength: 1

137

},

138

uniqueItems: true,

139

maxItems: 10

140

};

141

142

// Schema with definitions and references

143

const petStoreSchema: IJsonSchema = {

144

type: "object",

145

definitions: {

146

Pet: {

147

type: "object",

148

required: ["name", "photoUrls"],

149

properties: {

150

id: {

151

type: "integer",

152

format: "int64"

153

},

154

name: {

155

type: "string"

156

},

157

photoUrls: {

158

type: "array",

159

items: {

160

type: "string"

161

}

162

},

163

status: {

164

type: "string",

165

enum: ["available", "pending", "sold"]

166

}

167

}

168

}

169

},

170

properties: {

171

pets: {

172

type: "array",

173

items: {

174

$ref: "#/definitions/Pet"

175

}

176

}

177

}

178

};

179

180

// Complex schema with constraints

181

const conditionalSchema: IJsonSchema = {

182

type: "object",

183

properties: {

184

type: {

185

type: "string",

186

enum: ["person", "organization"]

187

}

188

},

189

allOf: [

190

{

191

if: {

192

properties: {

193

type: { const: "person" }

194

}

195

},

196

then: {

197

properties: {

198

firstName: { type: "string" },

199

lastName: { type: "string" }

200

},

201

required: ["firstName", "lastName"]

202

}

203

},

204

{

205

if: {

206

properties: {

207

type: { const: "organization" }

208

}

209

},

210

then: {

211

properties: {

212

organizationName: { type: "string" }

213

},

214

required: ["organizationName"]

215

}

216

}

217

]

218

};

219

220

// Validation helper functions

221

function hasRequiredFields(schema: IJsonSchema): boolean {

222

return schema.required != null && schema.required.length > 0;

223

}

224

225

function isObjectSchema(schema: IJsonSchema): boolean {

226

return schema.type === "object" || (Array.isArray(schema.type) && schema.type.includes("object"));

227

}

228

229

function isArraySchema(schema: IJsonSchema): boolean {

230

return schema.type === "array" || (Array.isArray(schema.type) && schema.type.includes("array"));

231

}

232

233

function getSchemaProperties(schema: IJsonSchema): { [name: string]: IJsonSchema } | undefined {

234

return schema.properties;

235

}

236

```