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"
@@ -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
115182const { allLocations, visitedLocations } = await runTests ( argv [ 2 ] , argv [ 3 ] ) ;
@@ -134,4 +201,4 @@ console.log(
134201
135202if ( visitedLocations . size != allLocations . length ) {
136203 process . exitCode = 1 ;
137- }
204+ }
0 commit comments