File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ import { readdirSync , readFileSync } from "node:fs" ;
2+ import YAML from "yaml" ;
3+ import { validate , setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1" ;
4+ import { BASIC } from "@hyperjump/json-schema/experimental" ;
5+ import { describe , test , expect } from "vitest" ;
6+
7+ const parseYamlFromFile = ( filePath ) => {
8+ const schemaYaml = readFileSync ( filePath , "utf8" ) ;
9+ return YAML . parse ( schemaYaml , { prettyErrors : true } ) ;
10+ } ;
11+
12+ setMetaSchemaOutputFormat ( BASIC ) ;
13+
14+ const validateOpenApi = await validate ( "./schemas/v3.1/schema.json" ) ;
15+ const folder = './examples/v3.1/' ;
16+
17+ describe ( "v3.1 - Validate examples" , async ( ) => {
18+ readdirSync ( folder , { withFileTypes : true } )
19+ . filter ( ( entry ) => entry . isFile ( ) && / \. y a m l $ / . test ( entry . name ) )
20+ . forEach ( ( entry ) => {
21+ test ( entry . name , ( ) => {
22+ const instance = parseYamlFromFile ( folder + entry . name ) ;
23+ const output = validateOpenApi ( instance , BASIC ) ;
24+ expect ( output . valid ) . to . equal ( true ) ;
25+ } ) ;
26+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments