Skip to content

Commit

Permalink
Fix broken type of ID scalar in generated swagger document (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Feb 12, 2020
1 parent 611fb92 commit 25fb213
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
11 changes: 4 additions & 7 deletions example/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"name": "id",
"required": true,
"schema": {
"$ref": "#/components/schemas/ID"
"type": "string"
}
}
],
Expand Down Expand Up @@ -141,7 +141,7 @@
"name": "id",
"required": true,
"schema": {
"$ref": "#/components/schemas/ID"
"type": "string"
}
}
],
Expand Down Expand Up @@ -323,7 +323,7 @@
],
"properties": {
"id": {
"type": "object"
"type": "string"
},
"name": {
"type": "string"
Expand Down Expand Up @@ -365,7 +365,7 @@
"required": ["id", "title"],
"properties": {
"id": {
"type": "object"
"type": "string"
},
"title": {
"type": "string"
Expand Down Expand Up @@ -410,9 +410,6 @@
"$ref": "#/components/schemas/Book"
}
}
},
"ID": {
"type": "string"
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions example/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ paths:
name: id
required: true
schema:
$ref: '#/components/schemas/ID'
type: string
responses:
'200':
description: ""
Expand Down Expand Up @@ -92,7 +92,7 @@ paths:
name: id
required: true
schema:
$ref: '#/components/schemas/ID'
type: string
responses:
'200':
description: ""
Expand Down Expand Up @@ -208,7 +208,7 @@ components:
- shelf
properties:
id:
type: object
type: string
name:
type: string
favoritePizza:
Expand Down Expand Up @@ -239,7 +239,7 @@ components:
- title
properties:
id:
type: object
type: string
title:
type: string
Salad:
Expand Down Expand Up @@ -268,5 +268,3 @@ components:
properties:
onBook:
$ref: '#/components/schemas/Book'
ID:
type: string
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"yamljs": "0.3.0"
},
"scripts": {
"start": "ts-node example/index.ts",
"start": "ts-node -O \"{\\\"module\\\": \\\"commonjs\\\"}\" example/index.ts",
"clean": "rm -rf dist",
"prebuild": "yarn clean",
"build": "bob",
Expand Down
6 changes: 1 addition & 5 deletions src/open-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function OpenAPI({
basePath?: string;
}
) {
const basePath = (config && config.basePath) || '';
const basePath = config?.basePath || '';
const path =
basePath +
info.path.replace(
Expand All @@ -65,10 +65,6 @@ export function OpenAPI({
schema,
useRequestBody: ['POST', 'PUT', 'PATCH'].includes(info.method),
});

swagger.components.schemas.ID = {
type: 'string',
};
},
get() {
return swagger;
Expand Down
3 changes: 3 additions & 0 deletions src/open-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export function mapToPrimitive(type: string) {
Boolean: {
type: 'boolean',
},
ID: {
type: 'string',
},
};

if (formatMap[type]) {
Expand Down

0 comments on commit 25fb213

Please sign in to comment.