Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tilfin/writing-openapi-helper
Help you write OpenAPI definition for Node.js JSON API server
https://github.com/tilfin/writing-openapi-helper
nodejs openapi
Last synced: about 1 month ago
JSON representation
Help you write OpenAPI definition for Node.js JSON API server
- Host: GitHub
- URL: https://github.com/tilfin/writing-openapi-helper
- Owner: tilfin
- License: mit
- Created: 2020-01-29T05:57:44.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T12:52:11.000Z (almost 5 years ago)
- Last Synced: 2024-10-24T01:37:13.495Z (3 months ago)
- Topics: nodejs, openapi
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Writing OpenAPI helper
helps you write OpenAPI definition.
## Install
```
$ npm i tilfin/writing-openapi-helper.git
```## How to use
```js
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const request = require('supertest')
const { createHookListener, dumpDefinition } = require('writing-openapi-helper')const app = new Koa()
app.use(bodyParser())
app.use(async (ctx, next) => {
ctx.body = {
data: {
items: [
{
id: 1,
name: 'A',
},
{
id: 2,
name: 'B',
}
],
totalItems: 2,
},
metadata: {
cursor: 'abcdef'
}
}
})request(createHookListener(app.callback()))
.post('/items/search')
.send({ q: 'A' })
.set('x-app-key', 'app_key')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
console.log(dumpDefinition())
})
```## Result
```yaml
openapi: 3.0.0
paths:
/items/search:
post:
summary: API
operationId: operationId
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required: []
properties:
data:
type: object
required: []
properties:
items:
type: array
items:
type: object
required: []
properties:
id:
type: number
name:
type: string
totalItems:
type: number
metadata:
type: object
required: []
properties:
cursor:
type: string
requestBody:
content:
application/json:
schema:
type: object
required: []
properties:
q:
type: string
parameters:
- schema:
type: string
in: header
name: x-app-key
required: true
```