File tree 4 files changed +44
-1
lines changed
4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
const { ParserError } = require ( "../util/errors" ) ;
4
4
const yaml = require ( "js-yaml" ) ;
5
+ const { JSON_SCHEMA } = require ( "js-yaml" ) ;
5
6
6
7
module . exports = {
7
8
/**
@@ -45,7 +46,7 @@ module.exports = {
45
46
46
47
if ( typeof data === "string" ) {
47
48
try {
48
- return yaml . load ( data ) ;
49
+ return yaml . load ( data , { schema : JSON_SCHEMA } ) ;
49
50
}
50
51
catch ( e ) {
51
52
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