-
-
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
Feb 29, 2020
1 parent
4a40ab4
commit 23936a0
Showing
2 changed files
with
104 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,58 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
import * as packageJson from '../package.json'; | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join('test', 'resources', 'all.of.yaml'); | ||
app = await createApp({ apiSpec }, 3005, app => | ||
app.use( | ||
`${app.basePath}`, | ||
express.Router().post(`/all_of`, (req, res) => res.json(req.body)), | ||
), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should validate allOf', async () => | ||
request(app) | ||
.post(`${app.basePath}/all_of`) | ||
.send({ | ||
id: 1, | ||
name: 'jim', | ||
}) | ||
.expect(200)); | ||
|
||
it('should fail validation due to missing required id field', async () => | ||
request(app) | ||
.post(`${app.basePath}/all_of`) | ||
.send({ | ||
name: 1, | ||
}) | ||
.expect(400) | ||
.then(r => { | ||
const e = r.body; | ||
expect(e.message).to.contain("required property 'id'"); | ||
})); | ||
|
||
it('should fail validation due to missing required name field', async () => | ||
request(app) | ||
.post(`${app.basePath}/all_of`) | ||
.send({ | ||
id: 1, | ||
}) | ||
.expect(400) | ||
.then(r => { | ||
const e = r.body; | ||
expect(e.message).to.contain("required property 'name'"); | ||
})); | ||
}); |
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,46 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Test | ||
|
||
servers: | ||
- url: /v1 | ||
paths: | ||
/all_of: | ||
post: | ||
requestBody: | ||
description: body | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Pet" | ||
|
||
responses: | ||
"200": | ||
description: success | ||
|
||
components: | ||
schemas: | ||
NewPet: | ||
# The following causes AJV validation to fail - https://github.com/epoberezkin/ajv/issues/837 | ||
# additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
name: | ||
type: string | ||
nullable: true | ||
tag: | ||
type: string | ||
|
||
Pet: | ||
# This causes AVJ validation to fail - https://github.com/epoberezkin/ajv/issues/837 | ||
# additionalProperties: false | ||
allOf: | ||
- $ref: "#/components/schemas/NewPet" | ||
- required: | ||
- id | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 |