swagger-typescript-api 13.0.1 → 13.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "13.0.1",
3
+ "version": "13.0.3",
4
4
  "description": "Generate typescript/javascript api from swagger schema",
5
5
  "scripts": {
6
6
  "update-deps-to-latest": "npx --yes npm-check-updates && npm i",
@@ -74,36 +74,36 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
74
74
  });
75
75
 
76
76
  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
+ }),
87
90
  ),
91
+ 'Type',
88
92
  ]);
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
+ },
104
102
  });
105
103
 
106
- mappingTypeName = mappingTypeNameSchema.typeData.name;
104
+ component.typeData.content = content;
105
+
106
+ mappingTypeName = this.typeNameFormatter.format(component.typeName);
107
107
  }
108
108
 
109
109
  /** returns (GenericType<"mapping_key", MappingType>) or ({ discriminatorProperty: "mapping_key" } & MappingType) */
@@ -259,9 +259,12 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
259
259
  const { discriminator, ...noDiscriminatorSchema } = this.schema;
260
260
  const complexSchemaKeys = _.keys(this.schemaParser._complexSchemaParsers);
261
261
  const schema = _.omit(_.clone(noDiscriminatorSchema), complexSchemaKeys);
262
+ const schemaIsAny =
263
+ this.schemaParserFabric.getInlineParseContent(_.cloneDeep(schema)) ===
264
+ this.config.Ts.Keyword.Any;
262
265
  const schemaIsEmpty = !_.keys(schema).length;
263
266
 
264
- if (schemaIsEmpty) return null;
267
+ if (schemaIsEmpty || schemaIsAny) return null;
265
268
 
266
269
  const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
267
270
  prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
@@ -79,6 +79,7 @@ class SchemaParserFabric {
79
79
  schemaCopy,
80
80
  );
81
81
  const parsed = this.parseSchema(schemaCopy, null, schemaPath);
82
+
82
83
  parsed.name = typeName;
83
84
  customComponent.typeData = parsed;
84
85
 
@@ -41,13 +41,7 @@ class TypeNameFormatter {
41
41
  ? this.config.enumKeySuffix
42
42
  : this.config.typeSuffix;
43
43
 
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}`;
51
45
 
52
46
  if (typeof name !== 'string') {
53
47
  this.logger.warn('wrong name of the model name', name);