-
-
Notifications
You must be signed in to change notification settings - Fork 211
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 DiMascio
committed
Nov 25, 2019
1 parent
42c776a
commit 8dfd871
Showing
4 changed files
with
142 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
|
||
describe('express-openapi-validator', () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join('test', 'resources', 'empty.servers.yaml'); | ||
app = await createApp({ apiSpec }, 3007, app => | ||
app.use( | ||
``, | ||
express | ||
.Router() | ||
.get(`/pets`, (req, res) => res.json(req.body)), | ||
), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should throw 400', async () => | ||
request(app) | ||
.get(`/pets`) | ||
.expect(400) | ||
.then(r => { | ||
expect(r.body.errors).to.be.an('array'); | ||
expect(r.body.errors).to.have.length(2); | ||
})); | ||
}); |
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,94 @@ | ||
openapi: '3.0.0' | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
description: A sample API | ||
termsOfService: http://swagger.io/terms/ | ||
license: | ||
name: Apache 2.0 | ||
url: https://www.apache.org/licenses/LICENSE-2.0.html | ||
servers: [] | ||
paths: | ||
/pets: | ||
get: | ||
description: | | ||
Returns all pets | ||
operationId: findPets | ||
parameters: | ||
- name: type | ||
in: query | ||
description: maximum number of results to return | ||
required: true | ||
schema: | ||
type: string | ||
enum: | ||
- dog | ||
- cat | ||
- name: tags | ||
in: query | ||
description: tags to filter by | ||
required: false | ||
style: form | ||
schema: | ||
type: array | ||
items: | ||
type: string | ||
- name: limit | ||
in: query | ||
description: maximum number of results to return | ||
required: true | ||
schema: | ||
type: integer | ||
format: int32 | ||
minimum: 1 | ||
maximum: 20 | ||
responses: | ||
'200': | ||
description: pet response | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Pet' | ||
|
||
components: | ||
schemas: | ||
NewPet: | ||
required: | ||
- name | ||
properties: | ||
name: | ||
type: string | ||
tag: | ||
type: string | ||
type: | ||
$ref: '#/components/schemas/PetType' | ||
|
||
Pet: | ||
allOf: | ||
- $ref: '#/components/schemas/NewPet' | ||
- required: | ||
- id | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
|
||
PetType: | ||
type: string | ||
enum: | ||
- dog | ||
- cat | ||
|
||
Error: | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
message: | ||
type: string | ||
|