@@ -189,6 +189,42 @@ describe('Validation Tests', () => {
189
189
} )
190
190
. then ( done , done ) ;
191
191
} ) ;
192
+
193
+ it ( 'Test that boolean value can be used in enum' , ( done ) => {
194
+ schemaProvider . addSchema ( SCHEMA_ID , {
195
+ type : 'object' ,
196
+ properties : {
197
+ analytics : {
198
+ enum : [ true , false ] ,
199
+ } ,
200
+ } ,
201
+ } ) ;
202
+ const content = 'analytics: true' ;
203
+ const validator = parseSetup ( content ) ;
204
+ validator
205
+ . then ( function ( result ) {
206
+ assert . deepStrictEqual ( result , [ ] ) ;
207
+ } )
208
+ . then ( done , done ) ;
209
+ } ) ;
210
+
211
+ it ( 'Test that boolean value can be used in const' , ( done ) => {
212
+ schemaProvider . addSchema ( SCHEMA_ID , {
213
+ type : 'object' ,
214
+ properties : {
215
+ analytics : {
216
+ const : true ,
217
+ } ,
218
+ } ,
219
+ } ) ;
220
+ const content = 'analytics: true' ;
221
+ const validator = parseSetup ( content ) ;
222
+ validator
223
+ . then ( function ( result ) {
224
+ assert . deepStrictEqual ( result , [ ] ) ;
225
+ } )
226
+ . then ( done , done ) ;
227
+ } ) ;
192
228
} ) ;
193
229
194
230
describe ( 'String tests' , ( ) => {
@@ -2094,4 +2130,87 @@ obj:
2094
2130
const result = await parseSetup ( content ) ;
2095
2131
assert . equal ( result . length , 0 ) ;
2096
2132
} ) ;
2133
+
2134
+ it ( 'value should match as per schema const on boolean' , async ( ) => {
2135
+ schemaProvider . addSchema ( SCHEMA_ID , {
2136
+ type : 'object' ,
2137
+ properties : {
2138
+ prop : {
2139
+ const : true ,
2140
+ type : 'boolean' ,
2141
+ } ,
2142
+ } ,
2143
+ } ) ;
2144
+
2145
+ let content = `prop: false` ;
2146
+ let result = await parseSetup ( content ) ;
2147
+ expect ( result . length ) . to . eq ( 1 ) ;
2148
+ expect ( result [ 0 ] . message ) . to . eq ( 'Value must be true.' ) ;
2149
+
2150
+ content = `prop: true` ;
2151
+ result = await parseSetup ( content ) ;
2152
+ expect ( result . length ) . to . eq ( 0 ) ;
2153
+ } ) ;
2154
+
2155
+ it ( 'draft-04 schema' , async ( ) => {
2156
+ const schema : JSONSchema = {
2157
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
2158
+ type : 'object' ,
2159
+ properties : {
2160
+ myProperty : {
2161
+ $ref : '#/definitions/Interface%3Ctype%3E' ,
2162
+ } ,
2163
+ } ,
2164
+ definitions : {
2165
+ 'Interface<type>' : {
2166
+ type : 'object' ,
2167
+ properties : {
2168
+ foo : {
2169
+ type : 'string' ,
2170
+ } ,
2171
+ multipleOf : {
2172
+ type : 'number' ,
2173
+ minimum : 0 ,
2174
+ exclusiveMinimum : true ,
2175
+ } ,
2176
+ } ,
2177
+ } ,
2178
+ } ,
2179
+ } ;
2180
+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
2181
+ const content = `myProperty:\n foo: bar\n multipleOf: 1` ;
2182
+ const result = await parseSetup ( content ) ;
2183
+ assert . equal ( result . length , 0 ) ;
2184
+ } ) ;
2185
+
2186
+ it ( 'draft-04 schema with https in metaschema URI' , async ( ) => {
2187
+ const schema : JSONSchema = {
2188
+ $schema : 'https://json-schema.org/draft-04/schema#' ,
2189
+ type : 'object' ,
2190
+ properties : {
2191
+ myProperty : {
2192
+ $ref : '#/definitions/Interface%3Ctype%3E' ,
2193
+ } ,
2194
+ } ,
2195
+ definitions : {
2196
+ 'Interface<type>' : {
2197
+ type : 'object' ,
2198
+ properties : {
2199
+ foo : {
2200
+ type : 'string' ,
2201
+ } ,
2202
+ multipleOf : {
2203
+ type : 'number' ,
2204
+ minimum : 0 ,
2205
+ exclusiveMinimum : true ,
2206
+ } ,
2207
+ } ,
2208
+ } ,
2209
+ } ,
2210
+ } ;
2211
+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
2212
+ const content = `myProperty:\n foo: bar\n multipleOf: 1` ;
2213
+ const result = await parseSetup ( content ) ;
2214
+ assert . equal ( result . length , 0 ) ;
2215
+ } ) ;
2097
2216
} ) ;
0 commit comments