File tree Expand file tree Collapse file tree
openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties
plugins/@hey-api/transformers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,9 +9,14 @@ const fooSchemaResponseTransformer = (data: any) => {
99
1010const barSchemaResponseTransformer = ( data : any ) => {
1111 data . bar = new Date ( data . bar ) ;
12- if ( data . baz ) {
13- for ( const key of Object . keys ( data . baz ) ) {
14- data . baz [ key ] = fooSchemaResponseTransformer ( data . baz [ key ] ) ;
12+ for ( const key of Object . keys ( data . baz ) ) {
13+ data . baz [ key ] = fooSchemaResponseTransformer ( data . baz [ key ] ) ;
14+ }
15+ if ( data . qux ) {
16+ for ( const key of Object . keys ( data . qux ) ) {
17+ if ( ! [ 'quux' ] . includes ( key ) ) {
18+ data . qux [ key ] = new Date ( data . qux [ key ] ) ;
19+ }
1520 }
1621 }
1722 return data ;
Original file line number Diff line number Diff line change @@ -10,9 +10,13 @@ export type Foo = {
1010
1111export type Bar = {
1212 bar : Date ;
13- baz ? : {
13+ baz : {
1414 [ key : string ] : Foo ;
1515 } ;
16+ qux ?: {
17+ quux ?: string ;
18+ [ key : string ] : Date | string | undefined ;
19+ } ;
1620} ;
1721
1822export type PostFooData = {
Original file line number Diff line number Diff line change @@ -202,10 +202,24 @@ function processSchemaType({
202202 } ) ;
203203
204204 if ( entryValueNodes . length ) {
205+ const properties = Object . keys ( schema . properties ?? { } ) ;
205206 nodes . push (
206207 $ . for ( $ . const ( 'key' ) )
207208 . of ( $ ( 'Object' ) . attr ( 'keys' ) . call ( dataExpression ) )
208- . do ( ...entryValueNodes ) ,
209+ . $if (
210+ properties . length ,
211+ ( f ) =>
212+ f . do (
213+ $ . if (
214+ $ . not (
215+ $ . array ( ...properties )
216+ . attr ( 'includes' )
217+ . call ( 'key' ) ,
218+ ) ,
219+ ) . do ( ...entryValueNodes ) ,
220+ ) ,
221+ ( f ) => f . do ( ...entryValueNodes ) ,
222+ ) ,
209223 ) ;
210224 }
211225 }
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ import ts from 'typescript';
44import type { MaybeTsDsl } from '../base' ;
55import { TsDsl } from '../base' ;
66import { AsMixin } from '../mixins/as' ;
7+ import { ExprMixin } from '../mixins/expr' ;
78import { LayoutMixin } from '../mixins/layout' ;
89import { LiteralTsDsl } from './literal' ;
910
10- const Mixed = AsMixin ( LayoutMixin ( TsDsl < ts . ArrayLiteralExpression > ) ) ;
11+ const Mixed = AsMixin ( ExprMixin ( LayoutMixin ( TsDsl < ts . ArrayLiteralExpression > ) ) ) ;
1112
1213export class ArrayTsDsl extends Mixed {
1314 readonly '~dsl' = 'ArrayTsDsl' ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ components:
2626 type : object
2727 required :
2828 - bar
29+ - baz
2930 properties :
3031 bar :
3132 type : string
@@ -34,3 +35,11 @@ components:
3435 type : object
3536 additionalProperties :
3637 $ref : ' #/components/schemas/Foo'
38+ qux :
39+ type : object
40+ properties :
41+ quux :
42+ type : string
43+ additionalProperties :
44+ type : string
45+ format : date-time
You can’t perform that action at this time.
0 commit comments