File tree Expand file tree Collapse file tree 3 files changed +41
-38
lines changed
openapi-ts-tests/main/test/__snapshots__
3.0.x/transformers-all-of
3.1.x/transformers-all-of
openapi-ts/src/plugins/@hey-api/transformers Expand file tree Collapse file tree 3 files changed +41
-38
lines changed Original file line number Diff line number Diff line change 22
33import type { GetFooResponse } from './types.gen' ;
44
5- const quxSchemaResponseTransformer = ( data : any ) => {
6- if ( data . baz ) {
7- data . baz = new Date ( data . baz ) ;
8- }
9- return data ;
10- } ;
11-
12- const bazSchemaResponseTransformer = ( data : any ) => {
13- data = quxSchemaResponseTransformer ( data ) ;
14- data . bar = new Date ( data . bar ) ;
5+ const fooSchemaResponseTransformer = ( data : any ) => {
6+ data . foo = data . foo . map ( ( item : any ) => {
7+ return barSchemaResponseTransformer ( item ) ;
8+ } ) ;
159 return data ;
1610} ;
1711
@@ -22,10 +16,16 @@ const barSchemaResponseTransformer = (data: any) => {
2216 return data ;
2317} ;
2418
25- const fooSchemaResponseTransformer = ( data : any ) => {
26- data . foo = data . foo . map ( ( item : any ) => {
27- return barSchemaResponseTransformer ( item ) ;
28- } ) ;
19+ const bazSchemaResponseTransformer = ( data : any ) => {
20+ data = quxSchemaResponseTransformer ( data ) ;
21+ data . bar = new Date ( data . bar ) ;
22+ return data ;
23+ } ;
24+
25+ const quxSchemaResponseTransformer = ( data : any ) => {
26+ if ( data . baz ) {
27+ data . baz = new Date ( data . baz ) ;
28+ }
2929 return data ;
3030} ;
3131
Original file line number Diff line number Diff line change 22
33import type { GetFooResponse } from './types.gen' ;
44
5- const quxSchemaResponseTransformer = ( data : any ) => {
6- if ( data . baz ) {
7- data . baz = new Date ( data . baz ) ;
8- }
9- return data ;
10- } ;
11-
12- const bazSchemaResponseTransformer = ( data : any ) => {
13- data = quxSchemaResponseTransformer ( data ) ;
14- data . bar = new Date ( data . bar ) ;
5+ const fooSchemaResponseTransformer = ( data : any ) => {
6+ data . foo = data . foo . map ( ( item : any ) => {
7+ return barSchemaResponseTransformer ( item ) ;
8+ } ) ;
159 return data ;
1610} ;
1711
@@ -22,10 +16,16 @@ const barSchemaResponseTransformer = (data: any) => {
2216 return data ;
2317} ;
2418
25- const fooSchemaResponseTransformer = ( data : any ) => {
26- data . foo = data . foo . map ( ( item : any ) => {
27- return barSchemaResponseTransformer ( item ) ;
28- } ) ;
19+ const bazSchemaResponseTransformer = ( data : any ) => {
20+ data = quxSchemaResponseTransformer ( data ) ;
21+ data . bar = new Date ( data . bar ) ;
22+ return data ;
23+ } ;
24+
25+ const quxSchemaResponseTransformer = ( data : any ) => {
26+ if ( data . baz ) {
27+ data . baz = new Date ( data . baz ) ;
28+ }
2929 return data ;
3030} ;
3131
Original file line number Diff line number Diff line change @@ -63,6 +63,19 @@ const processSchemaType = ({
6363 if ( ! plugin . getSymbol ( selector ) ) {
6464 // TODO: remove
6565 // create each schema response transformer only once
66+
67+ // Register symbol early to prevent infinite recursion with self-referential schemas
68+ const symbol = plugin . registerSymbol ( {
69+ name : buildName ( {
70+ config : {
71+ case : 'camelCase' ,
72+ name : '{{name}}SchemaResponseTransformer' ,
73+ } ,
74+ name : refToName ( schema . $ref ) ,
75+ } ) ,
76+ selector,
77+ } ) ;
78+
6679 const refSchema = plugin . context . resolveIrRef < IR . SchemaObject > (
6780 schema . $ref ,
6881 ) ;
@@ -71,16 +84,6 @@ const processSchemaType = ({
7184 schema : refSchema ,
7285 } ) ;
7386 if ( nodes . length ) {
74- const symbol = plugin . registerSymbol ( {
75- name : buildName ( {
76- config : {
77- case : 'camelCase' ,
78- name : '{{name}}SchemaResponseTransformer' ,
79- } ,
80- name : refToName ( schema . $ref ) ,
81- } ) ,
82- selector,
83- } ) ;
8487 const node = tsc . constVariable ( {
8588 expression : tsc . arrowFunction ( {
8689 async : false ,
You can’t perform that action at this time.
0 commit comments