1
1
#!/usr/bin/env node
2
2
3
3
import { readFile } from "node:fs/promises" ;
4
- import yaml from "yaml" ;
4
+ import YAML from "yaml" ;
5
5
import { setMetaSchemaOutputFormat , validate } from "@hyperjump/json-schema/openapi-3-1" ;
6
6
import { BASIC } from "@hyperjump/json-schema/experimental" ;
7
7
8
+ import contentTypeParser from "content-type" ;
9
+ import { addMediaTypePlugin } from "@hyperjump/browser" ;
10
+ import { buildSchemaDocument } from "@hyperjump/json-schema/experimental" ;
11
+
12
+ addMediaTypePlugin ( "application/schema+yaml" , {
13
+ parse : async ( response ) => {
14
+ const contentType = contentTypeParser . parse ( response . headers . get ( "content-type" ) ?? "" ) ;
15
+ const contextDialectId = contentType . parameters . schema ?? contentType . parameters . profile ;
16
+
17
+ const foo = YAML . parse ( await response . text ( ) ) ;
18
+ return buildSchemaDocument ( foo , response . url , contextDialectId ) ;
19
+ } ,
20
+ fileMatcher : ( path ) => path . endsWith ( ".yaml" )
21
+ } ) ;
8
22
9
23
const defaultOutputFormat = BASIC ;
10
24
@@ -29,10 +43,10 @@ const outputFormat = args.format || defaultOutputFormat;
29
43
setMetaSchemaOutputFormat ( outputFormat ) ;
30
44
31
45
// Compile / meta-validate
32
- const validateOpenApi = await validate ( `./schemas/v3.1/${ schemaType } .json ` ) ;
46
+ const validateOpenApi = await validate ( `./schemas/v3.1/${ schemaType } .yaml ` ) ;
33
47
34
48
// Validate instance
35
49
const instanceYaml = await readFile ( `${ process . argv [ process . argv . length - 1 ] } ` , "utf8" ) ;
36
- const instance = yaml . parse ( instanceYaml ) ;
50
+ const instance = YAML . parse ( instanceYaml ) ;
37
51
const results = validateOpenApi ( instance , outputFormat ) ;
38
52
console . log ( JSON . stringify ( results , null , " " ) ) ;
0 commit comments