Skip to content

Commit 2b6db23

Browse files
authored
Merge pull request #581 from acacode/next
Release 13.0.3
2 parents db92855 + 53be5b9 commit 2b6db23

File tree

7 files changed

+276
-3
lines changed

7 files changed

+276
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# next release
22

3+
## 13.0.3
4+
5+
fix: problem with type `any` as base type of discriminator schema (cases when schema without discriminator is empty)
6+
37
## 13.0.2
48

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

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "13.0.2",
3+
"version": "13.0.3",
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,12 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
259259
const { discriminator, ...noDiscriminatorSchema } = this.schema;
260260
const complexSchemaKeys = _.keys(this.schemaParser._complexSchemaParsers);
261261
const schema = _.omit(_.clone(noDiscriminatorSchema), complexSchemaKeys);
262+
const schemaIsAny =
263+
this.schemaParserFabric.getInlineParseContent(_.cloneDeep(schema)) ===
264+
this.config.Ts.Keyword.Any;
262265
const schemaIsEmpty = !_.keys(schema).length;
263266

264-
if (schemaIsEmpty) return null;
267+
if (schemaIsEmpty || schemaIsAny) return null;
265268

266269
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
267270
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,

tests/spec/discriminator/expected.ts

+71
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,77 @@ export type InvalidDiscriminatorPropertyName = BaseInvalidDiscriminatorPropertyN
113113
| BaseInvalidDiscriminatorPropertyNameTypeMapping<"str", string>
114114
);
115115

116+
/** kek pek */
117+
export type Variant =
118+
| ({
119+
type: "update";
120+
} & VariantUpdate)
121+
| ({
122+
type: "undo";
123+
} & VariantUndo)
124+
| ({
125+
type: "rollback";
126+
} & VariantRollback)
127+
| ({
128+
type: "scale";
129+
} & VariantScale)
130+
| ({
131+
type: "resources";
132+
} & VariantResources)
133+
| ({
134+
type: "firewall";
135+
} & VariantFirewall)
136+
| ({
137+
type: "gateway";
138+
} & VariantGateway);
139+
140+
/** Proposal to change firewall rules for deployment. */
141+
export interface VariantFirewall {
142+
/** asdasdasdasdasdsad added to deployment. If not set, no rules are added. */
143+
rules_added?: string[];
144+
/** asdasdasdasdasdsad removed from deployment. If not set, no rules were removed. */
145+
rules_removed?: string[];
146+
}
147+
148+
/** asdasdasdasdasd */
149+
export interface VariantScale {
150+
/**
151+
* asdasdasdasdasdsad
152+
* @example 3
153+
*/
154+
replicas: number;
155+
}
156+
157+
/** asdasdasdasdasd */
158+
export interface VariantResources {
159+
resources: string;
160+
}
161+
162+
/** asdasdasdasdasd */
163+
export interface VariantGateway {
164+
/** asdasdasdasdasdsad */
165+
port?: string;
166+
/** asdasdasdasdasdsad */
167+
name?: string;
168+
/** asdasdasdasdasdsad */
169+
domain?: string;
170+
}
171+
172+
/** Pasdasdasdasdasd. */
173+
export type VariantUpdate = object;
174+
175+
/** asdasdasdasdasd */
176+
export interface VariantRollback {
177+
/**
178+
* asdasdasdasdasdsad
179+
* @example 42
180+
*/
181+
revision_id: number;
182+
}
183+
184+
/** asdasdasdasdasdn */
185+
export type VariantUndo = object;
186+
116187
interface BaseBlockDtoWithEnum {
117188
title: string;
118189
type: BlockDTOEnum;

tests/spec/discriminator/schema.json

+124
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,130 @@
377377
}
378378
}
379379
}
380+
},
381+
"Variant": {
382+
"description": "kek pek",
383+
"discriminator": {
384+
"propertyName": "type",
385+
"mapping": {
386+
"update": "#/components/schemas/VariantUpdate",
387+
"undo": "#/components/schemas/VariantUndo",
388+
"rollback": "#/components/schemas/VariantRollback",
389+
"scale": "#/components/schemas/VariantScale",
390+
"resources": "#/components/schemas/VariantResources",
391+
"firewall": "#/components/schemas/VariantFirewall",
392+
"gateway": "#/components/schemas/VariantGateway"
393+
}
394+
},
395+
"oneOf": [
396+
{
397+
"$ref": "#/components/schemas/VariantUpdate"
398+
},
399+
{
400+
"$ref": "#/components/schemas/VariantUndo"
401+
},
402+
{
403+
"$ref": "#/components/schemas/VariantRollback"
404+
},
405+
{
406+
"$ref": "#/components/schemas/VariantScale"
407+
},
408+
{
409+
"$ref": "#/components/schemas/VariantResources"
410+
},
411+
{
412+
"$ref": "#/components/schemas/VariantFirewall"
413+
},
414+
{
415+
"$ref": "#/components/schemas/VariantGateway"
416+
}
417+
]
418+
},
419+
"VariantFirewall": {
420+
"type": "object",
421+
"description": "Proposal to change firewall rules for deployment.",
422+
"properties": {
423+
"rules_added": {
424+
"type": "array",
425+
"description": "asdasdasdasdasdsad added to deployment. If not set, no rules are added.\n",
426+
"items": {
427+
"type": "string"
428+
}
429+
},
430+
"rules_removed": {
431+
"type": "array",
432+
"description": "asdasdasdasdasdsad removed from deployment. If not set, no rules were removed.\n",
433+
"items": {
434+
"type": "string"
435+
}
436+
}
437+
}
438+
},
439+
"VariantScale": {
440+
"type": "object",
441+
"description": "asdasdasdasdasd",
442+
"required": [
443+
"replicas"
444+
],
445+
"properties": {
446+
"replicas": {
447+
"type": "integer",
448+
"description": "asdasdasdasdasdsad",
449+
"example": 3
450+
}
451+
}
452+
},
453+
"VariantResources": {
454+
"type": "object",
455+
"description": "asdasdasdasdasd",
456+
"required": [
457+
"resources"
458+
],
459+
"properties": {
460+
"resources": {
461+
"type": "string"
462+
}
463+
}
464+
},
465+
"VariantGateway": {
466+
"type": "object",
467+
"description": "asdasdasdasdasd",
468+
"properties": {
469+
"port": {
470+
"type": "string",
471+
"description": "asdasdasdasdasdsad"
472+
},
473+
"name": {
474+
"type": "string",
475+
"description": "asdasdasdasdasdsad"
476+
},
477+
"domain": {
478+
"type": "string",
479+
"description": "asdasdasdasdasdsad"
480+
}
481+
}
482+
},
483+
"VariantUpdate": {
484+
"type": "object",
485+
"description": "Pasdasdasdasdasd."
486+
},
487+
"VariantRollback": {
488+
"type": "object",
489+
"description": "asdasdasdasdasd",
490+
"required": [
491+
"revision_id"
492+
],
493+
"properties": {
494+
"revision_id": {
495+
"type": "integer",
496+
"description": "asdasdasdasdasdsad",
497+
"example": 42
498+
}
499+
}
500+
},
501+
"VariantUndo": {
502+
"type": "object",
503+
"description": "asdasdasdasdasdn"
380504
}
381505
}
382506
}

tests/spec/discriminator/schema.ts

+71
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,77 @@ export type InvalidDiscriminatorPropertyName = BaseInvalidDiscriminatorPropertyN
113113
| BaseInvalidDiscriminatorPropertyNameTypeMapping<"str", string>
114114
);
115115

116+
/** kek pek */
117+
export type Variant =
118+
| ({
119+
type: "update";
120+
} & VariantUpdate)
121+
| ({
122+
type: "undo";
123+
} & VariantUndo)
124+
| ({
125+
type: "rollback";
126+
} & VariantRollback)
127+
| ({
128+
type: "scale";
129+
} & VariantScale)
130+
| ({
131+
type: "resources";
132+
} & VariantResources)
133+
| ({
134+
type: "firewall";
135+
} & VariantFirewall)
136+
| ({
137+
type: "gateway";
138+
} & VariantGateway);
139+
140+
/** Proposal to change firewall rules for deployment. */
141+
export interface VariantFirewall {
142+
/** asdasdasdasdasdsad added to deployment. If not set, no rules are added. */
143+
rules_added?: string[];
144+
/** asdasdasdasdasdsad removed from deployment. If not set, no rules were removed. */
145+
rules_removed?: string[];
146+
}
147+
148+
/** asdasdasdasdasd */
149+
export interface VariantScale {
150+
/**
151+
* asdasdasdasdasdsad
152+
* @example 3
153+
*/
154+
replicas: number;
155+
}
156+
157+
/** asdasdasdasdasd */
158+
export interface VariantResources {
159+
resources: string;
160+
}
161+
162+
/** asdasdasdasdasd */
163+
export interface VariantGateway {
164+
/** asdasdasdasdasdsad */
165+
port?: string;
166+
/** asdasdasdasdasdsad */
167+
name?: string;
168+
/** asdasdasdasdasdsad */
169+
domain?: string;
170+
}
171+
172+
/** Pasdasdasdasdasd. */
173+
export type VariantUpdate = object;
174+
175+
/** asdasdasdasdasd */
176+
export interface VariantRollback {
177+
/**
178+
* asdasdasdasdasdsad
179+
* @example 42
180+
*/
181+
revision_id: number;
182+
}
183+
184+
/** asdasdasdasdasdn */
185+
export type VariantUndo = object;
186+
116187
interface BaseBlockDtoWithEnum {
117188
title: string;
118189
type: BlockDTOEnum;

0 commit comments

Comments
 (0)