Skip to content

Commit 60f359f

Browse files
committed
Determine OAS Base Vocab name
and remove unnecessary code, thanks to @jdesrosiers
1 parent eee4d20 commit 60f359f

File tree

1 file changed

+10
-53
lines changed

1 file changed

+10
-53
lines changed

tests/schema/schema.test.mjs

Lines changed: 10 additions & 53 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,63 +26,20 @@ 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.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"));
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

0 commit comments

Comments
 (0)