Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate if server object is empty in an openapi definition.
- Loading branch information
Showing
3 changed files
with
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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; | ||
|
||
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 => { | ||
console.log(r) | ||
})); | ||
}); |
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,214 @@ | ||
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' | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
|
||
post: | ||
description: Creates a new pet in the store. Duplicates are allowed | ||
operationId: addPet | ||
security: | ||
- ApiKeyAuth: [] | ||
requestBody: | ||
description: Pet to add to the store | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/NewPet' | ||
responses: | ||
'200': | ||
description: pet response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Pet' | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
|
||
/pets/{id}: | ||
get: | ||
description: Returns a user based on a single ID, if the user does not have access to the pet | ||
operationId: find pet by id | ||
parameters: | ||
- name: id | ||
in: path | ||
description: ID of pet to fetch | ||
required: true | ||
schema: | ||
type: integer | ||
format: int64 | ||
responses: | ||
'200': | ||
description: pet response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Pet' | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
delete: | ||
description: deletes a single pet based on the ID supplied | ||
operationId: deletePet | ||
parameters: | ||
- name: id | ||
in: path | ||
description: ID of pet to delete | ||
required: true | ||
schema: | ||
type: integer | ||
format: int64 | ||
responses: | ||
'204': | ||
description: pet deleted | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
|
||
/pets/{id}/photos: | ||
post: | ||
description: upload a photo of the pet | ||
operationId: uploadPetPhoto | ||
parameters: | ||
- name: id | ||
in: path | ||
description: ID of pet to fetch | ||
required: true | ||
schema: | ||
type: integer | ||
format: int64 | ||
requestBody: | ||
content: | ||
multipart/form-data: | ||
schema: | ||
# $ref: '#/components/schemas/NewPhoto' | ||
type: object | ||
required: | ||
- file | ||
properties: | ||
file: | ||
description: The photo | ||
type: string | ||
format: binary | ||
required: true | ||
responses: | ||
201: | ||
description: Created | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
success: | ||
type: boolean | ||
|
||
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 | ||
|
||
securitySchemes: | ||
ApiKeyAuth: | ||
type: apiKey | ||
in: header | ||
name: X-API-Key |