Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 1, 2020
2 parents 7a0efc3 + bff486c commit 89153ea
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/all.of.spec.ts
@@ -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'");
}));
});
46 changes: 46 additions & 0 deletions test/resources/all.of.yaml
@@ -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

0 comments on commit 89153ea

Please sign in to comment.