-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Sep 9, 2019
1 parent
9491a0a
commit 9940fe6
Showing
6 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
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
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,55 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
|
||
const packageJson = require('../package.json'); | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
let basePath = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join('test', 'resources', 'query.params.yaml'); | ||
app = await createApp({ apiSpec }, 3005); | ||
basePath = app.basePath; | ||
|
||
app.use( | ||
`${basePath}`, | ||
express.Router().post(`/pets/nullable`, (req, res) => res.json(req.body)), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should pass if known query params are specified', async () => | ||
request(app) | ||
.get(`${basePath}/pets`) | ||
.query({ | ||
tags: 'one,two,three', | ||
limit: 10, | ||
breed: 'german_shepherd', | ||
owner_name: 'carmine', | ||
}) | ||
.expect(200)); | ||
|
||
it('should fail if unknown query param is specified', async () => | ||
request(app) | ||
.get(`${basePath}/pets`) | ||
.query({ | ||
tags: 'one,two,three', | ||
limit: 10, | ||
breed: 'german_shepherd', | ||
owner_name: 'carmine', | ||
unknown_prop: 'test', | ||
}) | ||
.expect(400) | ||
.then(r => { | ||
console.log(r.body); | ||
expect(r.body.errors).to.be.an('array'); | ||
})); | ||
}); |
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,104 @@ | ||
openapi: '3.0.0' | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification | ||
termsOfService: http://swagger.io/terms/ | ||
contact: | ||
name: Swagger API Team | ||
email: [email protected] | ||
url: http://swagger.io | ||
license: | ||
name: Apache 2.0 | ||
url: https://www.apache.org/licenses/LICENSE-2.0.html | ||
servers: | ||
- url: /v1/ | ||
- url: http://{name}.swagger.io:{port}/{version} | ||
variables: | ||
name: | ||
default: petstore | ||
enum: | ||
- petstore | ||
- storeofpets | ||
port: | ||
enum: | ||
- '443' | ||
- '8443' | ||
default: '443' | ||
version: | ||
default: v1 | ||
enum: | ||
- v1 | ||
paths: | ||
/pets: | ||
get: | ||
description: | | ||
Returns all pets from the system that the user has access tp | ||
parameters: | ||
- 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: 5 | ||
- name: breed | ||
in: query | ||
description: maximum number of results to return | ||
required: true | ||
schema: | ||
type: string | ||
enum: | ||
- german_shepherd | ||
- golden_retreiver | ||
- $ref: '#/components/parameters/owner_name' | ||
responses: | ||
'200': | ||
description: pet response | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Pet' | ||
components: | ||
parameters: | ||
owner_name: | ||
name: owner_name | ||
in: query | ||
description: owner's name | ||
required: true | ||
schema: | ||
type: string | ||
|
||
schemas: | ||
NewPet: | ||
additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
name: | ||
type: string | ||
nullable: true | ||
tag: | ||
type: string | ||
|
||
Pet: | ||
allOf: | ||
- $ref: '#/components/schemas/NewPet' | ||
- required: | ||
- id | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 |
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