Skip to content

Commit 8db5766

Browse files
authored
Release 1.8.4 (#57)
* [Bugfix] multiple types swagger 2 (#56) * fix: problem of multiple types for a swagger v2 schemes (type: string[]) * bump: up version to 1.8.4 * docs: update CHANGELOG
1 parent dcb2dd2 commit 8db5766

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

CHANGELOG.md

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

3+
# 1.8.4
4+
5+
Fixes:
6+
- Multiple types for a property in Swagger 2 are not handled correctly ([#55 issue](https://github.com/acacode/swagger-typescript-api/issues/55))
7+
38
# 1.8.3
49

510
Fixes:

package-lock.json

Lines changed: 1 addition & 1 deletion
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": "1.8.3",
3+
"version": "1.8.4",
44
"description": "Create typescript api module from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",

src/schema.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ const schemaParsers = {
204204
contentType = `Record<string, ${fieldType}>`;
205205
}
206206

207+
if (_.isArray(type) && type.length) {
208+
contentType = complexSchemaParsers.oneOf({
209+
oneOf: type.map((type) => ({ type })),
210+
description,
211+
});
212+
}
213+
207214
return attachParsedRef(schema, {
208215
$parsedSchema: true,
209216
schemaType: "primitive",

tests/generated/v2.0/petstore-minimal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Pet {
1414
id: number;
1515
name: string;
1616
tag?: string;
17+
multiple?: string | number;
1718
}
1819

1920
export type RequestParams = Omit<RequestInit, "body" | "method"> & {

tests/schemas/v2.0/petstore-minimal.json

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@
1414
},
1515
"host": "petstore.swagger.io",
1616
"basePath": "/api",
17-
"schemes": [
18-
"http"
19-
],
20-
"consumes": [
21-
"application/json"
22-
],
23-
"produces": [
24-
"application/json"
25-
],
17+
"schemes": ["http"],
18+
"consumes": ["application/json"],
19+
"produces": ["application/json"],
2620
"paths": {
2721
"/pets": {
2822
"get": {
2923
"description": "Returns all pets from the system that the user has access to",
30-
"produces": [
31-
"application/json"
32-
],
24+
"produces": ["application/json"],
3325
"responses": {
3426
"200": {
3527
"description": "A list of pets.",
@@ -47,10 +39,7 @@
4739
"definitions": {
4840
"Pet": {
4941
"type": "object",
50-
"required": [
51-
"id",
52-
"name"
53-
],
42+
"required": ["id", "name"],
5443
"properties": {
5544
"id": {
5645
"type": "integer",
@@ -61,8 +50,11 @@
6150
},
6251
"tag": {
6352
"type": "string"
53+
},
54+
"multiple": {
55+
"type": ["string", "number"]
6456
}
6557
}
6658
}
6759
}
68-
}
60+
}

0 commit comments

Comments
 (0)