Skip to content

Commit db92855

Browse files
authored
Merge pull request #561 from acacode/next
Release 13.0.2
2 parents 5729dcf + 6c71884 commit db92855

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# next release
22

3+
## 13.0.2
4+
5+
fix: problem with incorrect settings type suffix for internal discriminator mappings
6+
7+
## 13.0.1
8+
39
feat: `const` keyword OpenAPI 3.0 draft
410
fix: problem with using `anyOf`
511
feat: `--extract-responses` (nodejs: `extractResponses`) option to extract all schemas from `/components/responses`

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "13.0.0",
3+
"version": "13.0.2",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"update-deps-to-latest": "npx --yes npm-check-updates && npm i",

src/schema-parser/base-schema-parsers/discriminator.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,36 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
7474
});
7575

7676
if (ableToCreateMappingType) {
77-
const mappingTypeNameRef = this.schemaComponentsMap.createRef([
78-
'components',
79-
'schemas',
80-
this.schemaUtils.resolveTypeName(
81-
`${abstractSchemaStruct.typeName} ${discriminator.propertyName}`,
82-
{
83-
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
84-
resolver:
85-
this.config.extractingOptions.discriminatorMappingNameResolver,
86-
},
77+
const rawTypeName = `${abstractSchemaStruct.typeName}_${discriminator.propertyName}`;
78+
const generatedTypeName = this.schemaUtils.resolveTypeName(rawTypeName, {
79+
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
80+
resolver:
81+
this.config.extractingOptions.discriminatorMappingNameResolver,
82+
});
83+
84+
const content = ts.IntersectionType([
85+
ts.ObjectWrapper(
86+
ts.TypeField({
87+
key: ts.StringValue(discriminator.propertyName),
88+
value: 'Key',
89+
}),
8790
),
91+
'Type',
8892
]);
89-
const mappingTypeNameComponent =
90-
this.schemaComponentsMap.createComponent(mappingTypeNameRef);
91-
const mappingTypeNameSchema = this.schemaParserFabric.createSchema({
92-
linkedComponent: mappingTypeNameComponent,
93-
content: ts.IntersectionType([
94-
ts.ObjectWrapper(
95-
ts.TypeField({
96-
key: ts.StringValue(discriminator.propertyName),
97-
value: 'Key',
98-
}),
99-
),
100-
'Type',
101-
]),
102-
genericArgs: [{ name: 'Key' }, { name: 'Type' }],
103-
internal: true,
93+
94+
const component = this.schemaParserFabric.createParsedComponent({
95+
typeName: generatedTypeName,
96+
schema: {
97+
type: 'object',
98+
properties: {},
99+
genericArgs: [{ name: 'Key' }, { name: 'Type' }],
100+
internal: true,
101+
},
104102
});
105103

106-
mappingTypeName = mappingTypeNameSchema.typeData.name;
104+
component.typeData.content = content;
105+
106+
mappingTypeName = this.typeNameFormatter.format(component.typeName);
107107
}
108108

109109
/** returns (GenericType<"mapping_key", MappingType>) or ({ discriminatorProperty: "mapping_key" } & MappingType) */

src/schema-parser/schema-parser-fabric.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SchemaParserFabric {
7979
schemaCopy,
8080
);
8181
const parsed = this.parseSchema(schemaCopy, null, schemaPath);
82+
8283
parsed.name = typeName;
8384
customComponent.typeData = parsed;
8485

src/type-name-formatter.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ class TypeNameFormatter {
4141
? this.config.enumKeySuffix
4242
: this.config.typeSuffix;
4343

44-
const existedFormattedEntry = Array.from(
45-
this.formattedModelNamesMap.entries(),
46-
).find((entry) => entry[1] === name);
47-
48-
const hashKey = existedFormattedEntry
49-
? existedFormattedEntry[0]
50-
: `${typePrefix}_${name}_${typeSuffix}`;
44+
const hashKey = `${typePrefix}_${name}_${typeSuffix}`;
5145

5246
if (typeof name !== 'string') {
5347
this.logger.warn('wrong name of the model name', name);

0 commit comments

Comments
 (0)