Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/resources/576/components/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
properties:
cluster_id:
type: string
cluster_name:
type: string
required:
- cluster_id
- cluster_name
example:
cluster_id: abcdefgh123456789
cluster_name: MyCluster
9 changes: 9 additions & 0 deletions test/resources/576/components/user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: object
properties:
user_id:
type: string
name:
type: string
example:
user_id: "1"
name: John
13 changes: 13 additions & 0 deletions test/resources/576/errors/400.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
properties:
error:
type: object
properties:
type:
type: number
message:
type: string
example:
error:
type: 400
message: 'Bad request'
17 changes: 17 additions & 0 deletions test/resources/576/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: '3.0.3'
info:
version: 0.0.1
title: My API
description: Best API ever
contact:
name: My Support
email: [email protected]
servers:
- url: 127.0.0.1/v1
paths:
$ref: paths.yaml
components:
schemas: {}
tags:
- name: Clusters
- name: Users
4 changes: 4 additions & 0 deletions test/resources/576/paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/clusters:
$ref: "paths/clusters.yaml"
/users:
$ref: "paths/users.yaml"
10 changes: 10 additions & 0 deletions test/resources/576/paths/clusters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get:
tags:
- Clusters
description: Returns a list of clusters
operationId: getClusters
responses:
"200":
$ref: "../responses/clusters.yaml"
"400":
$ref: "../responses/400.yaml"
10 changes: 10 additions & 0 deletions test/resources/576/paths/users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get:
tags:
- Users
description: Returns a list of users
operationId: getUsers
responses:
'200':
$ref: '../responses/users.yaml'
'400':
$ref: '../responses/400.yaml'
5 changes: 5 additions & 0 deletions test/resources/576/responses/400.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Bad request
content:
'application/json':
schema:
$ref: '../errors/400.yaml'
5 changes: 5 additions & 0 deletions test/resources/576/responses/404.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Not found
content:
"application/json":
schema:
$ref: "../errors/404.yaml"
7 changes: 7 additions & 0 deletions test/resources/576/responses/clusters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: Clusters
content:
'application/json':
schema:
type: array
items:
$ref: '../components/cluster.yaml'
7 changes: 7 additions & 0 deletions test/resources/576/responses/users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: Users
content:
"application/json":
schema:
type: array
items:
$ref: "../components/user.yaml"
41 changes: 41 additions & 0 deletions test/response.validation.576.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as path from 'path';
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './common/app';

const apiSpecPath = path.join('test', 'resources', '576', 'index.yaml');

describe('response validation for multiple responses', () => {
let app = null;

before(async () => {
// set up express app
app = await createApp(
{
apiSpec: apiSpecPath,
validateResponses: true,
$refParser: {
mode: 'dereference',
},
},
3005,
(app) => {
app.get(`${app.basePath}/clusters`, (req, res) => {
return res.status(200).json({ data: 'bad' });
});
},
);
});

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

it('should validate bad response', async () =>
request(app)
.get(`${app.basePath}/clusters`)
.expect(500)
.then((r) => {
expect(r.body.message).to.include('.response should be array');
}));
});