Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 14 additions & 57 deletions scripts/schema-test-coverage.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,9 +3,9 @@ import { readdir, readFile } from "node:fs/promises";
import YAML from "yaml";
import { join } from "node:path";
import { argv } from "node:process";
import { registerSchema, validate } from "@hyperjump/json-schema/draft-2020-12";
import { registerSchema, validate } from "@hyperjump/json-schema/openapi-3-1";
import "@hyperjump/json-schema/draft-04";
import { BASIC, addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental";
import { BASIC, defineVocabulary } from "@hyperjump/json-schema/experimental";

/**
* @import { EvaluationPlugin } from "@hyperjump/json-schema/experimental"
Expand DownExpand Up@@ -118,65 +118,22 @@ const runTests = async (schemaUri, testDirectory) => {
};
};

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
interpret: (discriminator, instance, context) => {
return true;
},
/* discriminator is not exactly an annotation, but it's not allowed
* to change the validation outcome (hence returing true from interopret())
* and for our purposes of testing, this is sufficient.
*/
annotation: (discriminator) => {
return discriminator;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/example",
interpret: (example, instance, context) => {
return true;
},
annotation: (example) => {
return example;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
interpret: (externalDocs, instance, context) => {
return true;
},
annotation: (externalDocs) => {
return externalDocs;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
interpret: (xml, instance, context) => {
return true;
},
annotation: (xml) => {
return xml;
},
});

defineVocabulary(
"https://spec.openapis.org/oas/3.1/vocab/base",
{
"discriminator": "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
"example": "https://spec.openapis.org/oas/schema/vocab/keyword/example",
"externalDocs": "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
"xml": "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
},
);

const parseYamlFromFile = (filePath) => {
const schemaYaml = readFileSync(filePath, "utf8");
return YAML.parse(schemaYaml, { prettyErrors: true });
};
registerSchema(parseYamlFromFile("./src/schemas/validation/meta.yaml"));

const meta = parseYamlFromFile("./src/schemas/validation/meta.yaml");
const oasBaseVocab = Object.keys(meta.$vocabulary)[0];

defineVocabulary(oasBaseVocab, {
"discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
"example": "https://spec.openapis.org/oas/3.0/keyword/example",
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
"xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
});

registerSchema(meta);
registerSchema(parseYamlFromFile("./src/schemas/validation/dialect.yaml"));
registerSchema(parseYamlFromFile("./src/schemas/validation/schema.yaml"));

Expand Down