Created
December 7, 2018 21:29
-
-
Save wesleytodd/abfe092a0b3ea6b8c6ff4f64d7615f70 to your computer and use it in GitHub Desktop.
Proposal for an open api package for express
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
'use strict' | |
const app = require('express')() | |
const openapi = require('@express/openapi') | |
const oapi = openapi('/api/swagger.json', { | |
info: { | |
title: 'Test swagger', | |
description: 'testing the express swagger api', | |
version: '0.0.1' | |
}, | |
externalDocs: { | |
url: 'https://swagger.io', | |
description: 'Find more info here' | |
}, | |
host: 'localhost', | |
schemes: ['http'], | |
consumes: ['application/json'], | |
produces: ['application/json'] | |
}) | |
// Register the general swagger handling | |
app.use(oapi) | |
// Define the hello world route schema | |
const helloWorldSchema = oapi.schema({ | |
description: 'get some data', | |
summary: 'Hello World', | |
response: { | |
200: { | |
description: 'Successful response', | |
type: 'object', | |
properties: { | |
hello: { type: 'string' } | |
} | |
} | |
} | |
}) | |
app.get('/', helloWorldSchema, (req, res) => { | |
res.json({ | |
hello: 'world' | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment