@hyperjump/json-schema 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import { getKeywordName } from "../lib/keywords.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import * as Instance from "../lib/instance.js";
4
+
5
+
6
+ const id = "https://spec.openapis.org/oas/3.0/keyword/type";
7
+
8
+ const compile = async (schema, ast, parentSchema) => {
9
+ const nullableKeyword = getKeywordName(schema.dialectId, "https://spec.openapis.org/oas/3.0/keyword/nullable");
10
+ const nullable = await Schema.step(nullableKeyword, parentSchema);
11
+ return Schema.value(nullable) === true ? ["null", Schema.value(schema)] : Schema.value(schema);
12
+ };
13
+
14
+ const interpret = (type, instance) => typeof type === "string" ? Instance.typeOf(instance, type) : type.some(Instance.typeOf(instance));
15
+
16
+ export default { id, compile, interpret };
@@ -0,0 +1,4 @@
1
+ import metaData from "../lib/keywords/meta-data.js";
2
+
3
+
4
+ export default { id: "https://spec.openapis.org/oas/3.0/keyword/xml", ...metaData };
@@ -0,0 +1,21 @@
1
+ export default {
2
+ "$id": "https://spec.openapis.org/oas/3.1/dialect/base",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
6
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
7
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
8
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
9
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
10
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
11
+ "https://json-schema.org/draft/2020-12/vocab/content": true,
12
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+ "$dynamicAnchor": "meta",
15
+
16
+ "title": "OpenAPI 3.1 Schema Object Dialect",
17
+ "allOf": [
18
+ { "$ref": "https://json-schema.org/draft/2020-12/schema" },
19
+ { "$ref": "https://spec.openapis.org/oas/3.1/meta/base" }
20
+ ]
21
+ };
@@ -0,0 +1,88 @@
1
+ import type { Json } from "@hyperjump/json-pointer";
2
+ import type { JsonSchemaType } from "../lib/common.js";
3
+
4
+
5
+ export type OasSchema31 = boolean | {
6
+ $schema?: "https://json-schema.org/draft/2020-12/schema";
7
+ $id?: string;
8
+ $anchor?: string;
9
+ $ref?: string;
10
+ $dynamicRef?: string;
11
+ $dynamicAnchor?: string;
12
+ $vocabulary?: Record<string, boolean>;
13
+ $comment?: string;
14
+ $defs?: Record<string, OasSchema31>;
15
+ additionalItems?: OasSchema31;
16
+ unevaluatedItems?: OasSchema31;
17
+ prefixItems?: OasSchema31[];
18
+ items?: OasSchema31;
19
+ contains?: OasSchema31;
20
+ additionalProperties?: OasSchema31;
21
+ unevaluatedProperties?: OasSchema31;
22
+ properties?: Record<string, OasSchema31>;
23
+ patternProperties?: Record<string, OasSchema31>;
24
+ dependentSchemas?: Record<string, OasSchema31>;
25
+ propertyNames?: OasSchema31;
26
+ if?: OasSchema31;
27
+ then?: OasSchema31;
28
+ else?: OasSchema31;
29
+ allOf?: OasSchema31[];
30
+ anyOf?: OasSchema31[];
31
+ oneOf?: OasSchema31[];
32
+ not?: OasSchema31;
33
+ multipleOf?: number;
34
+ maximum?: number;
35
+ exclusiveMaximum?: number;
36
+ minimum?: number;
37
+ exclusiveMinimum?: number;
38
+ maxLength?: number;
39
+ minLength?: number;
40
+ pattern?: string;
41
+ maxItems?: number;
42
+ minItems?: number;
43
+ uniqueItems?: boolean;
44
+ maxContains?: number;
45
+ minContains?: number;
46
+ maxProperties?: number;
47
+ minProperties?: number;
48
+ required?: string[];
49
+ dependentRequired?: Record<string, string[]>;
50
+ const?: Json;
51
+ enum?: Json[];
52
+ type?: JsonSchemaType | JsonSchemaType[];
53
+ title?: string;
54
+ description?: string;
55
+ default?: Json;
56
+ deprecated?: boolean;
57
+ readOnly?: boolean;
58
+ writeOnly?: boolean;
59
+ examples?: Json[];
60
+ format?: "date-time" | "date" | "time" | "duration" | "email" | "idn-email" | "hostname" | "idn-hostname" | "ipv4" | "ipv6" | "uri" | "uri-reference" | "iri" | "iri-reference" | "uuid" | "uri-template" | "json-pointer" | "relative-json-pointer" | "regex";
61
+ contentMediaType?: string;
62
+ contentEncoding?: string;
63
+ contentSchema?: OasSchema31;
64
+ example: Json;
65
+ discriminator: Discriminator;
66
+ externalDocs: ExternalDocs;
67
+ xml: Xml;
68
+ };
69
+
70
+ type Discriminator = {
71
+ propertyName: string;
72
+ mappings: Record<string, string>;
73
+ };
74
+
75
+ type ExternalDocs = {
76
+ url: string;
77
+ description: string;
78
+ };
79
+
80
+ type Xml = {
81
+ name: string;
82
+ namespace: string;
83
+ prefix: string;
84
+ attribute: boolean;
85
+ wrapped: boolean;
86
+ };
87
+
88
+ export * from "../lib/index.js";
@@ -0,0 +1,48 @@
1
+ import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
2
+ import { addSchema } from "../lib/core.js";
3
+ import "../lib/openapi.js";
4
+
5
+ import dialectSchema from "./dialect/base.js";
6
+ import vocabularySchema from "./meta/base.js";
7
+ import schema20221007 from "./schema/2022-10-07.js";
8
+ import schemaBase20221007 from "./schema-base/2022-10-07.js";
9
+
10
+ import discriminator from "../openapi-3-0/discriminator.js";
11
+ import example from "../openapi-3-0/example.js";
12
+ import externalDocs from "../openapi-3-0/externalDocs.js";
13
+ import xml from "../openapi-3-0/xml.js";
14
+
15
+
16
+ addKeyword(discriminator);
17
+ addKeyword(example);
18
+ addKeyword(externalDocs);
19
+ addKeyword(xml);
20
+
21
+ defineVocabulary("https://spec.openapis.org/oas/3.1/vocab/base", {
22
+ "discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
23
+ "example": "https://spec.openapis.org/oas/3.0/keyword/example",
24
+ "externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
25
+ "xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
26
+ });
27
+
28
+ loadDialect("https://spec.openapis.org/oas/3.1/schema-base", {
29
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
30
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
31
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
32
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
33
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
34
+ "https://json-schema.org/draft/2020-12/vocab/content": true,
35
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
36
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
37
+ }, true);
38
+
39
+ addSchema(vocabularySchema);
40
+ addSchema(dialectSchema);
41
+
42
+ // Current Schemas
43
+ addSchema(schema20221007, "https://spec.openapis.org/oas/3.1/schema");
44
+ addSchema(schema20221007, "https://spec.openapis.org/oas/3.1/schema/latest");
45
+ addSchema(schemaBase20221007, "https://spec.openapis.org/oas/3.1/schema-base");
46
+ addSchema(schemaBase20221007, "https://spec.openapis.org/oas/3.1/schema-base/latest");
47
+
48
+ export * from "../draft-2020-12/index.js";
@@ -0,0 +1,76 @@
1
+ export default {
2
+ "$id": "https://spec.openapis.org/oas/3.1/meta/base",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+ "title": "OAS Base vocabulary",
6
+
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "example": true,
10
+ "discriminator": { "$ref": "#/$defs/discriminator" },
11
+ "externalDocs": { "$ref": "#/$defs/external-docs" },
12
+ "xml": { "$ref": "#/$defs/xml" }
13
+ },
14
+ "$defs": {
15
+ "extensible": {
16
+ "patternProperties": {
17
+ "^x-": true
18
+ }
19
+ },
20
+ "discriminator": {
21
+ "$ref": "#/$defs/extensible",
22
+ "type": "object",
23
+ "properties": {
24
+ "propertyName": {
25
+ "type": "string"
26
+ },
27
+ "mapping": {
28
+ "type": "object",
29
+ "additionalProperties": {
30
+ "type": "string"
31
+ }
32
+ }
33
+ },
34
+ "required": ["propertyName"],
35
+ "unevaluatedProperties": false
36
+ },
37
+ "external-docs": {
38
+ "$ref": "#/$defs/extensible",
39
+ "type": "object",
40
+ "properties": {
41
+ "url": {
42
+ "type": "string",
43
+ "format": "uri-reference"
44
+ },
45
+ "description": {
46
+ "type": "string"
47
+ }
48
+ },
49
+ "required": ["url"],
50
+ "unevaluatedProperties": false
51
+ },
52
+ "xml": {
53
+ "$ref": "#/$defs/extensible",
54
+ "type": "object",
55
+ "properties": {
56
+ "name": {
57
+ "type": "string"
58
+ },
59
+ "namespace": {
60
+ "type": "string",
61
+ "format": "uri"
62
+ },
63
+ "prefix": {
64
+ "type": "string"
65
+ },
66
+ "attribute": {
67
+ "type": "boolean"
68
+ },
69
+ "wrapped": {
70
+ "type": "boolean"
71
+ }
72
+ },
73
+ "unevaluatedProperties": false
74
+ }
75
+ }
76
+ };