-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
carmine.dimacsio
committed
Jul 14, 2020
1 parent
b114070
commit b662d51
Showing
8 changed files
with
1,446 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const cookieParser = require('cookie-parser'); | ||
const bodyParser = require('body-parser'); | ||
const logger = require('morgan'); | ||
const http = require('http'); | ||
// const { Pets } = require('./services'); | ||
const { OpenApiValidator } = require('express-openapi-validator'); | ||
|
||
const port = 3000; | ||
const app = express(); | ||
const apiSpec = path.join(__dirname, 'ems.yaml'); | ||
|
||
// 1. Install bodyParsers for the request types your API will support | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.text()); | ||
app.use(bodyParser.json()); | ||
|
||
app.use(logger('dev')); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/spec', express.static(apiSpec)); | ||
|
||
// 2. Install the OpenApiValidator on your express app | ||
new OpenApiValidator({ | ||
apiSpec, | ||
validateResponses: true, | ||
}) | ||
.install(app) | ||
.then(() => { | ||
// const pets = new Pets(); | ||
// 3. Add routes | ||
app.put('/api/v1.0/queries', function (req, res, next) { | ||
res.status(200).json([]); | ||
}); | ||
app.post('/api/v1.0/queries', function (req, res, next) { | ||
res.status(201).json({}); | ||
}); | ||
app.get('/api/v1.0/queries', function (req, res, next) { | ||
res.json([]); | ||
}); | ||
|
||
// 4. Create a custom error handler | ||
app.use((err, req, res, next) => { | ||
// format errors | ||
res.status(err.status || 500).json({ | ||
message: err.message, | ||
errors: err.errors, | ||
}); | ||
}); | ||
|
||
http.createServer(app).listen(port); | ||
console.log(`Listening on port ${port}`); | ||
}); | ||
|
||
module.exports = app; |
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,96 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: EMS | ||
description: Spec for EMS API | ||
version: 1.0.0 | ||
servers: | ||
- url: /api/v1.0 | ||
paths: | ||
/queries: | ||
get: | ||
summary: Returns all queries | ||
operationId: getQueries | ||
parameters: | ||
- name: offset | ||
in: query | ||
required: false | ||
description: The record index to start returning (e.g. 1 = second record) | ||
schema: | ||
type: integer | ||
responses: | ||
'200': | ||
description: An array of query objects | ||
content: | ||
'application/json': | ||
schema: | ||
$ref: 'schemas/queries.yaml' | ||
'500': | ||
description: Server error | ||
# post: | ||
# summary: Create a new query | ||
# operationId: createQuery | ||
# requestBody: | ||
# description: A JSON object describing a query | ||
# required: true | ||
# content: | ||
# 'application/json': | ||
# schema: | ||
# $ref: 'schemas/queryrequest.yaml' | ||
# responses: | ||
# '201': | ||
# description: The created query object | ||
# content: | ||
# 'application/json': | ||
# schema: | ||
# $ref: 'schemas/queryresponse.yaml' | ||
# '404': | ||
# description: Query not found | ||
# '500': | ||
# description: Server error | ||
post: | ||
summary: Create a new query | ||
operationId: createQuery | ||
requestBody: | ||
$ref: '#/components/requestBodies/QueryBody' | ||
responses: | ||
'201': | ||
description: The created query object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'schemas/queryresponse.yaml' | ||
'404': | ||
description: Query not found | ||
'500': | ||
description: Server error | ||
put: | ||
summary: Update queries in bulk | ||
operationId: updateQueryBulk | ||
requestBody: | ||
$ref: '#/components/requestBodies/QueriesBody' | ||
responses: | ||
'200': | ||
description: An array of updated query objects | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'schemas/queries.yaml' | ||
'500': | ||
description: Server error | ||
|
||
components: | ||
requestBodies: | ||
QueryBody: | ||
description: A JSON object describing a query request | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'schemas/queryrequest.yaml' | ||
QueriesBody: | ||
description: An array of JSON objects describing query requests | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'schemas/queryrequest.yaml' |
Oops, something went wrong.