diff --git a/test/resources/response.validation.yaml b/test/resources/response.validation.yaml index 26274a53..917532e9 100644 --- a/test/resources/response.validation.yaml +++ b/test/resources/response.validation.yaml @@ -64,6 +64,20 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + /users: + get: + tags: + - Users + summary: Get users + operationId: getUsers + parameters: [] + responses: + '200': + description: the users + content: + application/json: + schema: + $ref: '#/components/schemas/Users' components: schemas: @@ -87,6 +101,12 @@ components: type: integer format: int64 + Users: + description: 'Generic list of values from database schema' + type: array + items: + type: string + Human: required: - id diff --git a/test/response.validation.spec.ts b/test/response.validation.spec.ts index 84cb37c8..b70fc0fc 100644 --- a/test/response.validation.spec.ts +++ b/test/response.validation.spec.ts @@ -16,6 +16,10 @@ describe(packageJson.name, () => { { apiSpec: apiSpecPath, validateResponses: true }, 3005, app => { + app.get(`${app.basePath}/users`, (req, res) => { + const json = ['user1', 'user2', 'user3']; + return res.json(json); + }); app.get(`${app.basePath}/pets`, (req, res) => { let json = {}; if ((req.query.mode = 'bad_type')) { @@ -48,4 +52,14 @@ describe(packageJson.name, () => { .to.have.property('code') .that.equals(500); })); + + it('should pass if response is a list', async () => + request(app) + .get(`${app.basePath}/users`) + .expect(200) + .then((r: any) => { + expect(r.body) + .is.an('array') + .with.length(3); + })); });