Skip to content

Commit 8604a79

Browse files
authored
Merge pull request #4727 from ralfhandl/3.2-merge-dev
3.2 merge dev
2 parents 58c7445 + bdfbbcf commit 8604a79

File tree

4 files changed

+29
-116
lines changed

4 files changed

+29
-116
lines changed

.github/workflows/schema-tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ name: schema-test
99
#
1010

1111
# run this on push to any branch and creation of pull-requests
12-
on:
13-
push: {}
12+
on:
1413
pull_request: {}
1514
workflow_dispatch: {}
1615

@@ -33,3 +32,5 @@ jobs:
3332

3433
- name: Run tests
3534
run: npm run test
35+
env:
36+
BASE: ${{ github.event.pull_request.base.ref }}

scripts/schema-test-coverage.mjs

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { readdir, readFile } from "node:fs/promises";
33
import YAML from "yaml";
44
import { join } from "node:path";
55
import { argv } from "node:process";
6-
import { registerSchema, validate } from "@hyperjump/json-schema/draft-2020-12";
6+
import { registerSchema, validate } from "@hyperjump/json-schema/openapi-3-1";
77
import "@hyperjump/json-schema/draft-04";
8-
import { BASIC, addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental";
8+
import { BASIC, defineVocabulary } from "@hyperjump/json-schema/experimental";
99

1010
/**
1111
* @import { EvaluationPlugin } from "@hyperjump/json-schema/experimental"
@@ -118,65 +118,22 @@ const runTests = async (schemaUri, testDirectory) => {
118118
};
119119
};
120120

121-
addKeyword({
122-
id: "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
123-
interpret: (discriminator, instance, context) => {
124-
return true;
125-
},
126-
/* discriminator is not exactly an annotation, but it's not allowed
127-
* to change the validation outcome (hence returing true from interopret())
128-
* and for our purposes of testing, this is sufficient.
129-
*/
130-
annotation: (discriminator) => {
131-
return discriminator;
132-
},
133-
});
134-
135-
addKeyword({
136-
id: "https://spec.openapis.org/oas/schema/vocab/keyword/example",
137-
interpret: (example, instance, context) => {
138-
return true;
139-
},
140-
annotation: (example) => {
141-
return example;
142-
},
143-
});
144-
145-
addKeyword({
146-
id: "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
147-
interpret: (externalDocs, instance, context) => {
148-
return true;
149-
},
150-
annotation: (externalDocs) => {
151-
return externalDocs;
152-
},
153-
});
154-
155-
addKeyword({
156-
id: "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
157-
interpret: (xml, instance, context) => {
158-
return true;
159-
},
160-
annotation: (xml) => {
161-
return xml;
162-
},
163-
});
164-
165-
defineVocabulary(
166-
"https://spec.openapis.org/oas/3.2/vocab/base",
167-
{
168-
"discriminator": "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
169-
"example": "https://spec.openapis.org/oas/schema/vocab/keyword/example",
170-
"externalDocs": "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
171-
"xml": "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
172-
},
173-
);
174-
175121
const parseYamlFromFile = (filePath) => {
176122
const schemaYaml = readFileSync(filePath, "utf8");
177123
return YAML.parse(schemaYaml, { prettyErrors: true });
178124
};
179-
registerSchema(parseYamlFromFile("./src/schemas/validation/meta.yaml"));
125+
126+
const meta = parseYamlFromFile("./src/schemas/validation/meta.yaml");
127+
const oasBaseVocab = Object.keys(meta.$vocabulary)[0];
128+
129+
defineVocabulary(oasBaseVocab, {
130+
"discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
131+
"example": "https://spec.openapis.org/oas/3.0/keyword/example",
132+
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
133+
"xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
134+
});
135+
136+
registerSchema(meta);
180137
registerSchema(parseYamlFromFile("./src/schemas/validation/dialect.yaml"));
181138
registerSchema(parseYamlFromFile("./src/schemas/validation/schema.yaml"));
182139

scripts/schema-test-coverage.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
[[ ! -e src/schemas ]] && exit 0
88

9-
branch=$(git branch --show-current)
10-
119
echo
1210
echo "Schema Test Coverage"
1311
echo
1412

1513
node scripts/schema-test-coverage.mjs src/schemas/validation/schema-base.yaml tests/schema/pass
1614
rc=$?
1715

18-
[[ "$branch" == "dev" ]] || exit $rc
16+
[[ "$BASE" == "dev" ]] || exit $rc

tests/schema/schema.test.mjs

Lines changed: 11 additions & 54 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";
33
import { registerSchema, validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1";
4-
import { BASIC, addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental";
4+
import { BASIC, defineVocabulary } from "@hyperjump/json-schema/experimental";
55
import { describe, test, expect } from "vitest";
66

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

2727
setMetaSchemaOutputFormat(BASIC);
2828

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-
});
29+
const meta = parseYamlFromFile("./src/schemas/validation/meta.yaml");
30+
const oasBaseVocab = Object.keys(meta.$vocabulary)[0];
5231

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-
},
32+
defineVocabulary(oasBaseVocab, {
33+
"discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
34+
"example": "https://spec.openapis.org/oas/3.0/keyword/example",
35+
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
36+
"xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
6137
});
6238

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.2/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"));
39+
registerSchema(meta);
8440
registerSchema(parseYamlFromFile("./src/schemas/validation/dialect.yaml"));
8541
registerSchema(parseYamlFromFile("./src/schemas/validation/schema.yaml"));
42+
8643
const validateOpenApi = await validate("./src/schemas/validation/schema-base.yaml");
8744
const fixtures = './tests/schema';
8845

89-
describe("v3.2", () => {
46+
describe("v3.1", () => {
9047
describe("Pass", () => {
9148
readdirSync(`${fixtures}/pass`, { withFileTypes: true })
9249
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))

0 commit comments

Comments
 (0)