Skip to content

Commit 835059f

Browse files
authored
Merge pull request #4702 from handrews/redundant
Use full schema (schema-base.yaml) in schema.test.mjs
2 parents c504ea4 + 3a0a025 commit 835059f

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: 3.1.0
2+
info:
3+
summary: Testing jsonSchemaDialect
4+
title: My API
5+
version: 1.0.0
6+
license:
7+
name: Apache 2.0
8+
identifier: Apache-2.0
9+
jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/WORK-IN-PROGRESS
10+
components:
11+
schemas:
12+
WithDollarSchema:
13+
$id: "locked-metaschema"
14+
$schema: https://spec.openapis.org/oas/3.1/dialect/WORK-IN-PROGRESS
15+
paths: {}

tests/schema/pass/mega.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ info:
66
license:
77
name: Apache 2.0
88
identifier: Apache-2.0
9-
jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/base
109
paths:
1110
/:
1211
get:

tests/schema/schema.test.mjs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readdirSync, readFileSync } from "node:fs";
22
import YAML from "yaml";
3-
import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1";
4-
import { BASIC } from "@hyperjump/json-schema/experimental";
3+
import { registerSchema, validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1";
4+
import { BASIC, addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental";
55
import { describe, test, expect } from "vitest";
66

77
import contentTypeParser from "content-type";
@@ -26,7 +26,64 @@ const parseYamlFromFile = (filePath) => {
2626

2727
setMetaSchemaOutputFormat(BASIC);
2828

29-
const validateOpenApi = await validate("./src/schemas/validation/schema.yaml");
29+
addKeyword({
30+
id: "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
31+
interpret: (discriminator, instance, context) => {
32+
return true;
33+
},
34+
/* discriminator is not exactly an annotation, but it's not allowed
35+
* to change the validation outcome (hence returing true from interopret())
36+
* and for our purposes of testing, this is sufficient.
37+
*/
38+
annotation: (discriminator) => {
39+
return discriminator;
40+
},
41+
});
42+
43+
addKeyword({
44+
id: "https://spec.openapis.org/oas/schema/vocab/keyword/example",
45+
interpret: (example, instance, context) => {
46+
return true;
47+
},
48+
annotation: (example) => {
49+
return example;
50+
},
51+
});
52+
53+
addKeyword({
54+
id: "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
55+
interpret: (externalDocs, instance, context) => {
56+
return true;
57+
},
58+
annotation: (externalDocs) => {
59+
return externalDocs;
60+
},
61+
});
62+
63+
addKeyword({
64+
id: "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
65+
interpret: (xml, instance, context) => {
66+
return true;
67+
},
68+
annotation: (xml) => {
69+
return xml;
70+
},
71+
});
72+
73+
defineVocabulary(
74+
"https://spec.openapis.org/oas/3.1/vocab/base",
75+
{
76+
"discriminator": "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
77+
"example": "https://spec.openapis.org/oas/schema/vocab/keyword/example",
78+
"externalDocs": "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
79+
"xml": "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
80+
},
81+
);
82+
83+
registerSchema(parseYamlFromFile("./src/schemas/validation/meta.yaml"));
84+
registerSchema(parseYamlFromFile("./src/schemas/validation/dialect.yaml"));
85+
registerSchema(parseYamlFromFile("./src/schemas/validation/schema.yaml"));
86+
const validateOpenApi = await validate("./src/schemas/validation/schema-base.yaml");
3087
const fixtures = './tests/schema';
3188

3289
describe("v3.1", () => {

0 commit comments

Comments
 (0)