-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial openapi_3 integration * update readme * add support for openapi 3.x * Update README.md * add error handler for openapi3 * update deps * Update error.handler.js
- Loading branch information
Showing
11 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% if (specification === 'openapi_3') { %> | ||
// eslint-disable-next-line no-unused-vars, no-shadow | ||
export default function errorHandler(err, req, res, next) { | ||
const errors = err.errors || [{ message: err.message }]; | ||
res.status(err.status || 500).json({ errors }) | ||
} | ||
<% } else { %> | ||
// Error handler to display the error as HTML | ||
// eslint-disable-next-line no-unused-vars, no-shadow | ||
export default function errorHandler(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.send( | ||
`<h1>${err.status || 500} Error</h1>` + | ||
`<pre>${err.message}</pre>`); | ||
} | ||
<% } %> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: <%= title %> | ||
description: <%= description %> | ||
version: <%= version %> | ||
servers: | ||
- url: <%= apiRoot %> | ||
tags: | ||
- name: Examples | ||
description: Simple example endpoints | ||
- name: Specification | ||
description: The swagger API specification | ||
paths: | ||
/examples: | ||
get: | ||
tags: | ||
- Examples | ||
description: Fetch all examples | ||
responses: | ||
200: | ||
description: Returns all examples | ||
content: {} | ||
post: | ||
tags: | ||
- Examples | ||
description: Create a new example | ||
requestBody: | ||
description: an example | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ExampleBody' | ||
required: true | ||
responses: | ||
200: | ||
description: Returns all examples | ||
content: {} | ||
/examples/{id}: | ||
get: | ||
tags: | ||
- Examples | ||
parameters: | ||
- name: id | ||
in: path | ||
description: The id of the example to retrieve | ||
required: true | ||
schema: | ||
type: integer | ||
responses: | ||
200: | ||
description: Return the example with the specified id | ||
content: {} | ||
404: | ||
description: Example not found | ||
content: {} | ||
/spec: | ||
get: | ||
tags: | ||
- Specification | ||
responses: | ||
200: | ||
description: Return the API specification | ||
content: {} | ||
components: | ||
schemas: | ||
ExampleBody: | ||
title: example | ||
required: | ||
- name | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
example: no_stress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters