fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #3646 from codercms/fix/transformers-additional-properties

fix(transformers): prevent additionalProperties transforms from affecting declared object properties

authored by

Lubos and committed by
GitHub
43b99199 dd7f255b

+39 -6
+8 -3
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/transformers.gen.ts
··· 9 9 10 10 const barSchemaResponseTransformer = (data: any) => { 11 11 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 + } 15 20 } 16 21 } 17 22 return data;
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/types.gen.ts
··· 10 10 11 11 export type Bar = { 12 12 bar: Date; 13 - baz?: { 13 + baz: { 14 14 [key: string]: Foo; 15 + }; 16 + qux?: { 17 + quux?: string; 18 + [key: string]: Date | string | undefined; 15 19 }; 16 20 }; 17 21
+15 -1
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 202 202 }); 203 203 204 204 if (entryValueNodes.length) { 205 + const properties = Object.keys(schema.properties ?? {}); 205 206 nodes.push( 206 207 $.for($.const('key')) 207 208 .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 + ), 209 223 ); 210 224 } 211 225 }
+2 -1
packages/openapi-ts/src/ts-dsl/expr/array.ts
··· 4 4 import type { MaybeTsDsl } from '../base'; 5 5 import { TsDsl } from '../base'; 6 6 import { AsMixin } from '../mixins/as'; 7 + import { ExprMixin } from '../mixins/expr'; 7 8 import { LayoutMixin } from '../mixins/layout'; 8 9 import { LiteralTsDsl } from './literal'; 9 10 10 - const Mixed = AsMixin(LayoutMixin(TsDsl<ts.ArrayLiteralExpression>)); 11 + const Mixed = AsMixin(ExprMixin(LayoutMixin(TsDsl<ts.ArrayLiteralExpression>))); 11 12 12 13 export class ArrayTsDsl extends Mixed { 13 14 readonly '~dsl' = 'ArrayTsDsl';
+9
specs/3.1.x/transformers-additional-properties.yaml
··· 26 26 type: object 27 27 required: 28 28 - bar 29 + - baz 29 30 properties: 30 31 bar: 31 32 type: string ··· 34 35 type: object 35 36 additionalProperties: 36 37 $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