1+ import { readFileSync } from "node:fs" ;
12import { readdir , readFile } from "node:fs/promises" ;
23import YAML from "yaml" ;
34import { join } from "node:path" ;
45import { 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" ;
67import "@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"
@@ -45,7 +46,10 @@ class TestCoveragePlugin {
4546 this . allLocations = [ ] ;
4647
4748 for ( const schemaLocation in context . ast ) {
48- if ( schemaLocation === "metaData" ) {
49+ if (
50+ schemaLocation === "metaData" ||
51+ schemaLocation . includes ( "json-schema.org" )
52+ ) {
4953 continue ;
5054 }
5155
@@ -110,6 +114,68 @@ const runTests = async (schemaUri, testDirectory) => {
110114 } ;
111115} ;
112116
117+ addKeyword ( {
118+ id : "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator" ,
119+ interpret : ( discriminator , instance , context ) => {
120+ return true ;
121+ } ,
122+ /* discriminator is not exactly an annotation, but it's not allowed
123+ * to change the validation outcome (hence returing true from interopret())
124+ * and for our purposes of testing, this is sufficient.
125+ */
126+ annotation : ( discriminator ) => {
127+ return discriminator ;
128+ } ,
129+ } ) ;
130+
131+ addKeyword ( {
132+ id : "https://spec.openapis.org/oas/schema/vocab/keyword/example" ,
133+ interpret : ( example , instance , context ) => {
134+ return true ;
135+ } ,
136+ annotation : ( example ) => {
137+ return example ;
138+ } ,
139+ } ) ;
140+
141+ addKeyword ( {
142+ id : "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs" ,
143+ interpret : ( externalDocs , instance , context ) => {
144+ return true ;
145+ } ,
146+ annotation : ( externalDocs ) => {
147+ return externalDocs ;
148+ } ,
149+ } ) ;
150+
151+ addKeyword ( {
152+ id : "https://spec.openapis.org/oas/schema/vocab/keyword/xml" ,
153+ interpret : ( xml , instance , context ) => {
154+ return true ;
155+ } ,
156+ annotation : ( xml ) => {
157+ return xml ;
158+ } ,
159+ } ) ;
160+
161+ defineVocabulary (
162+ "https://spec.openapis.org/oas/3.1/vocab/base" ,
163+ {
164+ "discriminator" : "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator" ,
165+ "example" : "https://spec.openapis.org/oas/schema/vocab/keyword/example" ,
166+ "externalDocs" : "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs" ,
167+ "xml" : "https://spec.openapis.org/oas/schema/vocab/keyword/xml" ,
168+ } ,
169+ ) ;
170+
171+ const parseYamlFromFile = ( filePath ) => {
172+ const schemaYaml = readFileSync ( filePath , "utf8" ) ;
173+ return YAML . parse ( schemaYaml , { prettyErrors : true } ) ;
174+ } ;
175+ registerSchema ( parseYamlFromFile ( "./src/schemas/validation/meta.yaml" ) ) ;
176+ registerSchema ( parseYamlFromFile ( "./src/schemas/validation/dialect.yaml" ) ) ;
177+ registerSchema ( parseYamlFromFile ( "./src/schemas/validation/schema.yaml" ) ) ;
178+
113179///////////////////////////////////////////////////////////////////////////////
114180
115181const { allLocations, visitedLocations } = await runTests ( argv [ 2 ] , argv [ 3 ] ) ;
@@ -134,4 +200,4 @@ console.log(
134200
135201if ( visitedLocations . size != allLocations . length ) {
136202 process . exitCode = 1 ;
137- }
203+ }
0 commit comments