File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 22
33const { ParserError } = require ( "../util/errors" ) ;
44const yaml = require ( "js-yaml" ) ;
5+ const { JSON_SCHEMA } = require ( "js-yaml" ) ;
56
67module . exports = {
78 /**
@@ -45,7 +46,7 @@ module.exports = {
4546
4647 if ( typeof data === "string" ) {
4748 try {
48- return yaml . load ( data ) ;
49+ return yaml . load ( data , { schema : JSON_SCHEMA } ) ;
4950 }
5051 catch ( e ) {
5152 throw new ParserError ( e . message , file . url ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const { expect } = require ( "chai" ) ;
4+ const $RefParser = require ( "../../.." ) ;
5+ const helper = require ( "../../utils/helper" ) ;
6+ const path = require ( "../../utils/path" ) ;
7+ const parsedSchema = require ( "./parsed" ) ;
8+
9+ describe ( "Schema with date strings" , ( ) => {
10+ it ( "should parse successfully" , async ( ) => {
11+ let parser = new $RefParser ( ) ;
12+ const schema = await parser . parse ( path . rel ( "specs/date-strings/date-strings.yaml" ) ) ;
13+ expect ( schema ) . to . equal ( parser . schema ) ;
14+ expect ( schema ) . to . deep . equal ( parsedSchema . schema ) ;
15+ expect ( parser . $refs . paths ( ) ) . to . deep . equal ( [ path . abs ( "specs/date-strings/date-strings.yaml" ) ] ) ;
16+ } ) ;
17+
18+ it ( "should resolve successfully" , helper . testResolve (
19+ path . rel ( "specs/date-strings/date-strings.yaml" ) ,
20+ path . abs ( "specs/date-strings/date-strings.yaml" ) , parsedSchema . schema ,
21+ ) ) ;
22+ } ) ;
Original file line number Diff line number Diff line change 1+ title : Date Strings
2+ type : object
3+ properties :
4+ name :
5+ description : 2015-04-22T10:03:19.323-07:00
6+ type : string
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ module . exports = {
4+ schema : {
5+ title : "Date Strings" ,
6+ type : "object" ,
7+ properties : {
8+ name : {
9+ description : "2015-04-22T10:03:19.323-07:00" ,
10+ type : "string"
11+ }
12+ }
13+ }
14+ } ;
You can’t perform that action at this time.
0 commit comments