From db15435138f5709c95815c1626e47b069ee2c271 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Sat, 9 Jan 2021 12:40:54 -0500 Subject: [PATCH] test: add circular test --- test/circular.spec.ts | 42 ++++++++++++++++++++++++++++++++++++ test/resources/circular.yaml | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 test/circular.spec.ts create mode 100644 test/resources/circular.yaml diff --git a/test/circular.spec.ts b/test/circular.spec.ts new file mode 100644 index 00000000..0a32b595 --- /dev/null +++ b/test/circular.spec.ts @@ -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)); +}); diff --git a/test/resources/circular.yaml b/test/resources/circular.yaml new file mode 100644 index 00000000..f0a2397f --- /dev/null +++ b/test/resources/circular.yaml @@ -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' + + \ No newline at end of file