Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken type of ID scalar in generated swagger document #280

Merged
merged 3 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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