Skip to content

Commit 5f2eae7

Browse files
author
rcatoio
committed
set discriminators types before other types than enums
1 parent e4fa687 commit 5f2eae7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/code-gen-process.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export class CodeGenProcess {
127127
}),
128128
);
129129

130+
//set all discriminators at the top
131+
this.schemaComponentsMap.discriminatorsFirst();
132+
// put all enums at the top (before discriminators)
130133
this.schemaComponentsMap.enumsFirst();
131134

132135
const componentsToParse: SchemaComponent[] =

src/schema-components-map.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ export class SchemaComponentsMap {
7777
return 0;
7878
});
7979
}
80+
81+
// Ensure discriminators are at the top of components list
82+
discriminatorsFirst() {
83+
this._data.sort((a, b) => {
84+
if (Object.keys(a.rawTypeData || {}).includes("discriminator")) return -1;
85+
if (Object.keys(b.rawTypeData || {}).includes("discriminator")) return 1;
86+
return 0;
87+
});
88+
}
8089
}

0 commit comments

Comments
 (0)