@@ -243,6 +243,52 @@ test("enforce should be disabled for excluded paths without excludedSchemas prop
243
243
t . equal ( res . payload , "exclude works" ) ;
244
244
} ) ;
245
245
246
+ test ( "enforce should be disabled for excluded paths via excludeOnFalseSchema option directly on schema" , async ( t ) => {
247
+ t . plan ( 2 ) ;
248
+
249
+ const fastify = Fastify ( ) ;
250
+
251
+ await fastify . register ( enforceSchema , {
252
+ required : [ "response" ] ,
253
+ excludeOnFalseSchema : true ,
254
+ } ) ;
255
+
256
+ fastify . get ( "/foo" , { schema : false } , ( req , reply ) => {
257
+ reply . code ( 200 ) . send ( "exclude works" ) ;
258
+ } ) ;
259
+
260
+ const res = await fastify . inject ( {
261
+ method : "GET" ,
262
+ url : "/foo" ,
263
+ } ) ;
264
+
265
+ t . equal ( res . statusCode , 200 ) ;
266
+ t . equal ( res . payload , "exclude works" ) ;
267
+ } ) ;
268
+
269
+ test ( "enforce should be disabled for excluded paths via excludeOnFalseSchema option directly on schema.response" , async ( t ) => {
270
+ t . plan ( 2 ) ;
271
+
272
+ const fastify = Fastify ( ) ;
273
+
274
+ await fastify . register ( enforceSchema , {
275
+ required : [ "response" ] ,
276
+ excludeOnFalseSchema : true ,
277
+ } ) ;
278
+
279
+ fastify . get ( "/foo" , { schema : { response : false } } , ( req , reply ) => {
280
+ reply . code ( 200 ) . send ( "exclude works" ) ;
281
+ } ) ;
282
+
283
+ const res = await fastify . inject ( {
284
+ method : "GET" ,
285
+ url : "/foo" ,
286
+ } ) ;
287
+
288
+ t . equal ( res . statusCode , 200 ) ;
289
+ t . equal ( res . payload , "exclude works" ) ;
290
+ } ) ;
291
+
246
292
test ( "enforce should be disabled at the body schema" , async t => {
247
293
t . plan ( 2 ) ;
248
294
@@ -273,3 +319,42 @@ test("enforce should be disabled at the body schema", async t => {
273
319
t . equal ( res . statusCode , 200 ) ;
274
320
t . equal ( res . payload , "body schema excluded for /foo" ) ;
275
321
} ) ;
322
+
323
+ test ( "No http status codes set in schema for required schema type" , async ( t ) => {
324
+ t . plan ( 1 ) ;
325
+
326
+ const fastify = Fastify ( ) ;
327
+
328
+ await fastify . register ( enforceSchema , {
329
+ required : [ "response" ] ,
330
+ } ) ;
331
+
332
+ try {
333
+ fastify . get ( "/foo" , { schema : { response : { } } } , ( req , reply ) => {
334
+ reply . code ( 200 ) . send ( "exclude works" ) ;
335
+ } ) ;
336
+ } catch ( err ) {
337
+ t . equal (
338
+ err . message ,
339
+ "No HTTP status codes provided in the response schema"
340
+ ) ;
341
+ }
342
+ } ) ;
343
+
344
+ test ( "Http status code outside support set in schema for required schema type" , async ( t ) => {
345
+ t . plan ( 1 ) ;
346
+
347
+ const fastify = Fastify ( ) ;
348
+
349
+ await fastify . register ( enforceSchema , {
350
+ required : [ "response" ] ,
351
+ } ) ;
352
+
353
+ try {
354
+ fastify . get ( "/foo" , { schema : { response : { 600 : { } } } } , ( req , reply ) => {
355
+ reply . code ( 200 ) . send ( "exclude works" ) ;
356
+ } ) ;
357
+ } catch ( err ) {
358
+ t . equal ( err . message , "HTTP status codes from 100 - 599 supported" ) ;
359
+ }
360
+ } ) ;
0 commit comments