Skip to content

Commit

Permalink
test: add circular test
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jan 9, 2021
1 parent 8a058fe commit db15435
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/circular.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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', 'circular.yaml');
app = await createApp({ apiSpec }, 3005, (app) =>
app.use(
`${app.basePath}`,
express.Router().post(`/circular`, (req, res) => res.json(req.body)),
),
);
});

after(() => {
app.server.close();
});

it('should validate circular ref successfully', async () =>
request(app)
.post(`${app.basePath}/circular`)
.send({
id: 1,
name: 'dad',
favorite: {
id: 1,
name: 'dad',
},
children: [
{ id: 2, name: 'tyler' },
{ id: 3, name: 'taylor' },
],
})
.expect(200));
});
40 changes: 40 additions & 0 deletions test/resources/circular.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
openapi: '3.0.3'
info:
version: 1.0.0
title: Swagger
servers:
- url: /v1
paths:
/circular:
post:
description: creates user
requestBody:
description: creates user
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'200':
description: Updated

components:
schemas:
User:
type: object
required:
- id
properties:
id:
type: number
name:
type: string
favorite:
$ref: '#/components/schemas/User'
children:
type: array
items:
$ref: '#/components/schemas/User'


0 comments on commit db15435

Please sign in to comment.