File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { generate } from '../src'
22import path from 'path'
3- import { inspect } from 'util'
4- import fs from 'fs'
53
64generate ( {
75 tsconfigFilePath : path . resolve ( __dirname , './tsconfig.json' ) ,
86 controllers : [ path . resolve ( __dirname , './*.ts' ) ] ,
97 openapi : {
10- filePath : '/tmp/openapi.yaml' ,
8+ filePath : '.. /tmp/openapi.yaml' ,
119 service : {
1210 name : 'my-service' ,
1311 version : '1.0.0'
@@ -24,15 +22,4 @@ generate({
2422 filePath : './router.ts' ,
2523 securityMiddlewarePath : './security.ts'
2624 }
27- } )
28- . then ( ( ) =>
29- console . log (
30- inspect (
31- JSON . parse ( fs . readFileSync ( '/tmp/openapi.yaml' ) . toString ( ) ) ,
32- false ,
33- 100 ,
34- true
35- )
36- )
37- )
38- . catch ( err => console . error ( 'error' , err ) )
25+ } ) . catch ( err => console . error ( 'error' , err ) )
Original file line number Diff line number Diff line change @@ -558,9 +558,7 @@ function validateAndParseValueAgainstSchema(
558558
559559 if (
560560 ( features ?. enableThrowOnUnexpectedAdditionalData ||
561- features ?. enableLogUnexpectedAdditionalData ) &&
562- ( currentSchema . additionalProperties === false ||
563- typeof currentSchema . additionalProperties === 'undefined' )
561+ features ?. enableLogUnexpectedAdditionalData ) && currentSchema . additionalProperties === false
564562 ) {
565563 if ( additionalKeys . length > 0 ) {
566564 if ( features . enableLogUnexpectedAdditionalData ) {
Original file line number Diff line number Diff line change @@ -56,8 +56,6 @@ type ValidationTestBody = {
5656 boolean : boolean
5757 tuple : [ string , number ]
5858 array : string [ ]
59- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
60- object : { }
6159 record : Record < string , string >
6260 mappedType : { [ key : string ] : number }
6361 objectWithProps : {
Original file line number Diff line number Diff line change @@ -21,9 +21,7 @@ const validBody = {
2121 number : 1 ,
2222 numberEnum : 4 ,
2323 numberWithMinAndMax : 5 ,
24- object : { ignored : 1 } ,
2524 objectWithProps : { string : 'my-string' } ,
26- readonlyProp : 'my prop' ,
2725 record : { foo : '1' } ,
2826 string : 'my-string' ,
2927 stringEnum : 'foo' ,
@@ -93,17 +91,20 @@ after(async () => {
9391
9492describe ( 'Additional properties' , ( ) => {
9593 test ( 'Should reject if a given property does not exist in the schema' , async ( ) => {
94+ const id = randomUUID ( )
9695 const res = await request ( app )
9796 . post ( '/my-controller/' )
9897 . set ( 'x-custom-header' , 'my-header' )
99- . send ( { ...validBody , [ randomUUID ( ) ] : 'random' } )
98+ . send ( { ...validBody , [ id ] : 'random' } )
10099 . expect ( 400 )
101100
102101 assert . deepStrictEqual ( res . body . fields , {
103- ' body.object' : {
104- message : ' Additional properties are not allowed. Found: ignored' ,
102+ body : {
103+ message : ` Additional properties are not allowed. Found: ${ id } ` ,
105104 value : {
106- ignored : 1
105+ ...validBody ,
106+ [ id ] : 'random' ,
107+ stringWithFormat : new Date ( validBody . stringWithFormat ) . toISOString ( )
107108 }
108109 }
109110 } )
You can’t perform that action at this time.
0 commit comments