Skip to content

Commit 96f62b8

Browse files
committed
Fix coverage with custom vocabulary
1 parent ee625d6 commit 96f62b8

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"yargs": "^18.0.0"
2828
},
2929
"devDependencies": {
30-
"@hyperjump/json-schema-coverage": "^1.0.0",
30+
"@hyperjump/json-schema-coverage": "^1.0.1",
3131
"c8": "^10.1.3",
3232
"markdownlint-cli2": "^0.18.1",
3333
"nyc": "^17.1.0",

tests/schema/oas-schema.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { registerSchema } from "@hyperjump/json-schema/draft-2020-12";
2+
import { defineVocabulary } from "@hyperjump/json-schema/experimental";
3+
import { readFile } from "node:fs/promises";
4+
import YAML from "yaml";
5+
6+
const parseYamlFromFile = async (filePath) => {
7+
const schemaYaml = await readFile(filePath, "utf8");
8+
return YAML.parse(schemaYaml, { prettyErrors: true });
9+
};
10+
11+
export default async () => {
12+
const dialect = await parseYamlFromFile("./src/schemas/validation/dialect.yaml");
13+
const meta = await parseYamlFromFile("./src/schemas/validation/meta.yaml");
14+
const oasBaseVocab = Object.keys(meta.$vocabulary)[0];
15+
16+
defineVocabulary(oasBaseVocab, {
17+
"discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
18+
"example": "https://spec.openapis.org/oas/3.0/keyword/example",
19+
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
20+
"xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
21+
});
22+
23+
registerSchema(meta);
24+
registerSchema(dialect);
25+
};

tests/schema/schema.test.mjs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import { readdirSync, readFileSync } from "node:fs";
22
import YAML from "yaml";
33
import { describe, test, expect } from "vitest";
4-
import { defineVocabulary, registerSchema } from "@hyperjump/json-schema-coverage/vitest";
4+
import { registerSchema } from "@hyperjump/json-schema-coverage/vitest";
5+
import registerOasSchema from "./oas-schema.mjs";
56

67
const parseYamlFromFile = (filePath) => {
78
const schemaYaml = readFileSync(filePath, "utf8");
89
return YAML.parse(schemaYaml, { prettyErrors: true });
910
};
1011

11-
const meta = parseYamlFromFile("./src/schemas/validation/meta.yaml");
12-
const oasBaseVocab = Object.keys(meta.$vocabulary)[0];
13-
14-
defineVocabulary(oasBaseVocab, {
15-
"discriminator": "https://spec.openapis.org/oas/3.0/keyword/discriminator",
16-
"example": "https://spec.openapis.org/oas/3.0/keyword/example",
17-
"externalDocs": "https://spec.openapis.org/oas/3.0/keyword/externalDocs",
18-
"xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
19-
});
20-
21-
await registerSchema("./src/schemas/validation/meta.yaml");
22-
await registerSchema("./src/schemas/validation/dialect.yaml");
12+
await registerOasSchema();
2313
await registerSchema("./src/schemas/validation/schema.yaml");
2414
const fixtures = './tests/schema';
2515

vitest.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'
22

33
export default defineConfig({
44
test: {
5+
globalSetup: ["tests/schema/oas-schema.mjs"],
56
coverage: {
67
provider: "custom",
78
customProviderModule: "@hyperjump/json-schema-coverage/vitest/coverage-provider",

0 commit comments

Comments
 (0)