Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

feat: adding support for handling default responses #846

Merged
merged 2 commits into from
Jul 17, 2020
Merged
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
17 changes: 5 additions & 12 deletions example/swagger-files/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
"openapi": "3.0.0",
"servers": [
{
"url": "http://example.com"
"url": "https://httpbin.org/"
}
],
"info": {
"title": "example results",
"version": "1.0"
},
"paths": {
"/results": {
"/examples": {
"get": {
"description": "",
"responses": {
"200": {
"default": {
"description": "OK",
"content": {
"application/json": {
Expand Down Expand Up @@ -80,8 +79,7 @@
"400": {
"$ref": "#/components/responses/400-Response-Ref"
}
},
"summary": "Update Password"
}
}
}
},
Expand All @@ -101,12 +99,7 @@
}
}
}
},
"parameters": {},
"examples": {},
"requestBodies": {},
"securitySchemes": {},
"headers": {}
}
},
"x-explorer-enabled": true,
"x-samples-enabled": true,
Expand Down
6 changes: 3 additions & 3 deletions packages/api-explorer/__tests__/ExampleTabs.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const props = {
test('if endpoint has an example, tabs should show', () => {
const exampleTabs = mount(<ExampleTabs {...props} />);

expect(exampleTabs.find('a.tabber-tab')).toHaveLength(2);
expect(exampleTabs.find('a.tabber-tab')).toHaveLength(3);
});

test('should select matching tab by index', () => {
Expand All @@ -34,11 +34,11 @@ test('should call setExampleTab on click', () => {

secondTab.simulate('click', { preventDefault() {} });

expect(setExampleTab.mock.calls[0][0]).toBe(1);
expect(setExampleTab.mock.calls[0][0]).toBe(2);
});

test('should display status codes', () => {
const exampleTabs = shallow(<ExampleTabs {...props} />);

expect(exampleTabs.find('IconStatus')).toHaveLength(2);
expect(exampleTabs.find('IconStatus')).toHaveLength(3);
});
7 changes: 6 additions & 1 deletion packages/api-explorer/__tests__/ResponseExample.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const string = require('./__fixtures__/string/oas.json');
const exampleResults = require('./__fixtures__/example-results/oas');

const ResponseExample = require('../src/ResponseExample');
const ExampleTabs = require('../src/ExampleTabs');

const oas = new Oas(petstore);

Expand Down Expand Up @@ -38,7 +39,11 @@ test('should show each example', () => {
<ResponseExample {...props} oas={exampleOas} operation={exampleOas.operation('/results', 'get')} />
);

expect(example.find('pre')).toHaveLength(2);
expect(example.find(ExampleTabs).render().find('.tabber-tab').text().trim()).toStrictEqual(
'200 OK 400 Bad Request Default'
);

expect(example.find('pre')).toHaveLength(3);
});

test('should display json viewer', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/__tests__/ResponseSchema.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('should display a header with a dropdown', () => {
const responseSchema = shallow(<ResponseSchema {...props} />);

expect(responseSchema.find('h3').text()).toContain('Response');
expect(responseSchema.find('select option').map(el => el.text())).toStrictEqual(['200', '400', '404']);
expect(responseSchema.find('select option').map(el => el.text())).toStrictEqual(['200', '400', '404', 'Default']);
});

test('selectedStatus should change state of selectedStatus', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
}
}
}
},
"default": {
"description": "OK",
"content": {
"application/json": {
"examples": {
"response": {
"value": {
"user": {
"id": 12343354,
"email": "test@example.com",
"name": "Test user name"
}
}
}
}
}
}
}
},
"summary": "Update Password"
Expand Down Expand Up @@ -223,6 +241,24 @@
},
"400": {
"$ref": "#/components/responses/400-Response-Ref"
},
"default": {
"description": "OK",
"content": {
"application/json": {
"examples": {
"response": {
"value": {
"user": {
"id": 12343354,
"email": "test@example.com",
"name": "Test user name"
}
}
}
}
}
}
}
},
"summary": "Update Password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@
},
"404": {
"description": "Pet not found"
},
"default": {
"description": "successful response"
}
},
"security": [
Expand Down
16 changes: 16 additions & 0 deletions packages/api-explorer/__tests__/lib/create-code-shower.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('createCodeShower', () => {
],
status: '400',
},
{
languages: [
{
code: encodeJsonExample({
user: {
id: 12343354,
email: 'test@example.com',
name: 'Test user name',
},
}),
language: 'application/json',
multipleExamples: false,
},
],
status: 'default',
},
]);
});

Expand Down
Loading