-
-
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.
Merge pull request #46 from cdimascio/nullable
Reject requests with null value if "nullable" is not set #45
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 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,5 @@ | ||
import * as path from 'path'; | ||
import { createApp } from '../common/app'; | ||
|
||
const apiSpec = path.join('test', 'resources', 'openapi.yaml'); | ||
createApp({ apiSpec }, 3000); |
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,52 @@ | ||
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', 'nullable.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 allow null to be set (name: nullable true)', async () => | ||
request(app) | ||
.post(`${basePath}/pets/nullable`) | ||
.send({ | ||
name: null, | ||
}) | ||
.expect(200) | ||
.then(r => { | ||
expect(r.body.name).to.be.null; | ||
})); | ||
|
||
it('should fill null with default (name: nullable false/default)', async () => | ||
request(app) | ||
.post(`${basePath}/pets`) | ||
.send({ | ||
name: null, | ||
}) | ||
.expect(200) | ||
.then(r => { | ||
expect(r.body.name).to.equal(''); | ||
})); | ||
}); |
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,113 @@ | ||
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: apiteam@swagger.io | ||
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/nullable: | ||
post: | ||
description: Creates a new pet in the store. Duplicates are allowed | ||
operationId: addPet | ||
requestBody: | ||
description: Pet to add to the store | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/NullableNewPet' | ||
responses: | ||
'200': | ||
description: pet response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Pet' | ||
|
||
/pets: | ||
post: | ||
description: Creates a new pet in the store. Duplicates are allowed | ||
operationId: addPet | ||
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' | ||
|
||
components: | ||
parameters: | ||
id: | ||
name: id | ||
in: path | ||
description: ID of pet to fetch | ||
required: true | ||
schema: | ||
type: integer | ||
format: int64 | ||
|
||
schemas: | ||
NullableNewPet: | ||
additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
name: | ||
type: string | ||
nullable: true | ||
tag: | ||
type: string | ||
|
||
NewPet: | ||
additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
name: | ||
type: string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,6 +331,7 @@ components: | |
properties: | ||
name: | ||
type: string | ||
nullable: true | ||
tag: | ||
type: string | ||
|
||
|