Skip to content

Commit

Permalink
bump: 13.0.2 version; fix: problem with incorrect settings type suffi…
Browse files Browse the repository at this point in the history
…x for internal discriminator mappings
  • Loading branch information
js2me committed Jul 25, 2023
1 parent 1366ece commit 6c71884
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next release

## 13.0.2

fix: problem with incorrect settings type suffix for internal discriminator mappings

## 13.0.1

feat: `const` keyword OpenAPI 3.0 draft
fix: problem with using `anyOf`
feat: `--extract-responses` (nodejs: `extractResponses`) option to extract all schemas from `/components/responses`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-typescript-api",
"version": "13.0.0",
"version": "13.0.2",
"description": "Generate typescript/javascript api from swagger schema",
"scripts": {
"update-deps-to-latest": "npx --yes npm-check-updates && npm i",
Expand Down
52 changes: 26 additions & 26 deletions src/schema-parser/base-schema-parsers/discriminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,36 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
});

if (ableToCreateMappingType) {
const mappingTypeNameRef = this.schemaComponentsMap.createRef([
'components',
'schemas',
this.schemaUtils.resolveTypeName(
`${abstractSchemaStruct.typeName} ${discriminator.propertyName}`,
{
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
resolver:
this.config.extractingOptions.discriminatorMappingNameResolver,
},
const rawTypeName = `${abstractSchemaStruct.typeName}_${discriminator.propertyName}`;
const generatedTypeName = this.schemaUtils.resolveTypeName(rawTypeName, {
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
resolver:
this.config.extractingOptions.discriminatorMappingNameResolver,
});

const content = ts.IntersectionType([
ts.ObjectWrapper(
ts.TypeField({
key: ts.StringValue(discriminator.propertyName),
value: 'Key',
}),
),
'Type',
]);
const mappingTypeNameComponent =
this.schemaComponentsMap.createComponent(mappingTypeNameRef);
const mappingTypeNameSchema = this.schemaParserFabric.createSchema({
linkedComponent: mappingTypeNameComponent,
content: ts.IntersectionType([
ts.ObjectWrapper(
ts.TypeField({
key: ts.StringValue(discriminator.propertyName),
value: 'Key',
}),
),
'Type',
]),
genericArgs: [{ name: 'Key' }, { name: 'Type' }],
internal: true,

const component = this.schemaParserFabric.createParsedComponent({
typeName: generatedTypeName,
schema: {
type: 'object',
properties: {},
genericArgs: [{ name: 'Key' }, { name: 'Type' }],
internal: true,
},
});

mappingTypeName = mappingTypeNameSchema.typeData.name;
component.typeData.content = content;

mappingTypeName = this.typeNameFormatter.format(component.typeName);
}

/** returns (GenericType<"mapping_key", MappingType>) or ({ discriminatorProperty: "mapping_key" } & MappingType) */
Expand Down
1 change: 1 addition & 0 deletions src/schema-parser/schema-parser-fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class SchemaParserFabric {
schemaCopy,
);
const parsed = this.parseSchema(schemaCopy, null, schemaPath);

parsed.name = typeName;
customComponent.typeData = parsed;

Expand Down
8 changes: 1 addition & 7 deletions src/type-name-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ class TypeNameFormatter {
? this.config.enumKeySuffix
: this.config.typeSuffix;

const existedFormattedEntry = Array.from(
this.formattedModelNamesMap.entries(),
).find((entry) => entry[1] === name);

const hashKey = existedFormattedEntry
? existedFormattedEntry[0]
: `${typePrefix}_${name}_${typeSuffix}`;
const hashKey = `${typePrefix}_${name}_${typeSuffix}`;

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

0 comments on commit 6c71884

Please sign in to comment.