File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ function stripIllegalKeywords(schema) {
29
29
function convertSchema ( schema , path , parent , parentPath ) {
30
30
schema = stripIllegalKeywords ( schema ) ;
31
31
schema = convertTypes ( schema ) ;
32
+ schema = rewriteConst ( schema ) ;
32
33
schema = convertDependencies ( schema ) ;
33
34
34
35
if ( typeof schema [ 'patternProperties' ] === 'object' ) {
@@ -137,7 +138,17 @@ function convertTypes(schema) {
137
138
function convertPatternProperties ( schema ) {
138
139
schema [ 'x-patternProperties' ] = schema [ 'patternProperties' ] ;
139
140
delete schema [ 'patternProperties' ] ;
141
+ if ( typeof schema . additionalProperties === 'undefined' ) schema . additionalProperties = true ;
142
+ return schema ;
143
+ }
144
+
145
+ function rewriteConst ( schema ) {
146
+ if ( schema . const ) {
147
+ schema . enum = [ schema . const ] ;
148
+ delete schema . const ;
149
+ }
140
150
return schema ;
141
151
}
142
152
143
153
module . exports = convert ;
154
+
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const convert = require ( '../' ) ;
4
+ const should = require ( 'should' ) ;
5
+
6
+ it ( 'const' , ( ) => {
7
+ const schema = {
8
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
9
+ type : 'string' ,
10
+ const : 'hello'
11
+ } ;
12
+
13
+ const result = convert ( schema ) ;
14
+
15
+ const expected = {
16
+ type : 'string' ,
17
+ enum : [ 'hello' ]
18
+ } ;
19
+
20
+ should ( result ) . deepEqual ( expected , 'converted' ) ;
21
+ } ) ;
You can’t perform that action at this time.
0 commit comments