Skip to content

Commit 246073b

Browse files
committed
Use full schema (schema-base.yaml) for coverage
1 parent c504ea4 commit 246073b

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

scripts/schema-test-coverage.mjs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { readFileSync } from "node:fs";
12
import { readdir, readFile } from "node:fs/promises";
23
import YAML from "yaml";
34
import { join } from "node:path";
45
import { argv } from "node:process";
5-
import { validate } from "@hyperjump/json-schema/draft-2020-12";
6+
import { registerSchema, validate } from "@hyperjump/json-schema/draft-2020-12";
67
import "@hyperjump/json-schema/draft-04";
7-
import { BASIC } from "@hyperjump/json-schema/experimental";
8+
import { BASIC, addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental";
89

910
/**
1011
* @import { EvaluationPlugin } from "@hyperjump/json-schema/experimental"
@@ -37,6 +38,10 @@ class TestCoveragePlugin {
3738
}
3839

3940
beforeSchema(_schemaUri, _instance, context) {
41+
console.log(
42+
"Before:",
43+
_schemaUri,
44+
);
4045
if (this.allLocations) {
4146
return;
4247
}
@@ -110,6 +115,68 @@ const runTests = async (schemaUri, testDirectory) => {
110115
};
111116
};
112117

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

115182
const { allLocations, visitedLocations } = await runTests(argv[2], argv[3]);
@@ -134,4 +201,4 @@ console.log(
134201

135202
if (visitedLocations.size != allLocations.length) {
136203
process.exitCode = 1;
137-
}
204+
}

scripts/schema-test-coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ echo
1212
echo "Schema Test Coverage"
1313
echo
1414

15-
node scripts/schema-test-coverage.mjs src/schemas/validation/schema.yaml tests/schema/pass
15+
node scripts/schema-test-coverage.mjs src/schemas/validation/schema-base.yaml tests/schema/pass
1616
rc=$?
1717

1818
[[ "$branch" == "dev" ]] || exit $rc

0 commit comments

Comments
 (0)