-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render response examples as highlighted text, if it is not an Object. (…
…#82) Closes #81 Closes #77 - Examples may be provided as string and need not be a JSON object see https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/api-with-examples.yaml - in such a case, we don't want to JSON.stringify() the example but display it as is.
- Loading branch information
Showing
5 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/response-string-example/response-string-example-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*! | ||
* bootprint-swagger <https://github.com/nknapp/bootprint-swagger> | ||
* | ||
* Copyright (c) 2015 Nils Knappmeier. | ||
* Released under the MIT license. | ||
*/ | ||
|
||
/* global describe */ | ||
/* global it */ | ||
/* global before */ | ||
var expect = require('chai').expect | ||
var core = require('../core') | ||
|
||
describe('The response string-examples fixture', function () { | ||
this.timeout(10000) | ||
var context = {} | ||
before(function () { | ||
return core.run(require.resolve('./swagger.yaml'), __dirname, context) | ||
}) | ||
it('should render the response examples', function () { | ||
expect(context.$('dd.sw-response-200 .sw-response-examples').text(), | ||
'Examples consisting of only a string should not be JSON.stringified').not.to.match(/\\n/) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# From: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/api-with-examples.yaml | ||
swagger: "2.0" | ||
info: | ||
title: Simple API overview | ||
version: v2 | ||
paths: | ||
/: | ||
get: | ||
operationId: listVersionsv2 | ||
summary: List API versions | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: |- | ||
200 300 response | ||
examples: | ||
application/json: |- | ||
{ | ||
"versions": [ | ||
{ | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
application/xml: |- | ||
<xml> | ||
<some random="element">with contents</some> | ||
</xml> | ||
"300": | ||
description: |- | ||
200 300 response | ||
examples: | ||
application/json: |- | ||
{ | ||
"versions": [ | ||
{ | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
} | ||
] | ||
}, | ||
{ | ||
"status": "EXPERIMENTAL", | ||
"updated": "2013-07-23T11:33:21Z", | ||
"id": "v3.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v3/", | ||
"rel": "self" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
/v2: | ||
get: | ||
operationId: getVersionDetailsv2 | ||
summary: Show API version details | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: |- | ||
200 203 response | ||
examples: | ||
application/json: |- | ||
{ | ||
"version": { | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"media-types": [ | ||
{ | ||
"base": "application/xml", | ||
"type": "application/vnd.openstack.compute+xml;version=2" | ||
}, | ||
{ | ||
"base": "application/json", | ||
"type": "application/vnd.openstack.compute+json;version=2" | ||
} | ||
], | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
}, | ||
{ | ||
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", | ||
"type": "application/pdf", | ||
"rel": "describedby" | ||
}, | ||
{ | ||
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", | ||
"type": "application/vnd.sun.wadl+xml", | ||
"rel": "describedby" | ||
}, | ||
{ | ||
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", | ||
"type": "application/vnd.sun.wadl+xml", | ||
"rel": "describedby" | ||
} | ||
] | ||
} | ||
} | ||
"203": | ||
description: |- | ||
200 203 response | ||
examples: | ||
application/json: |- | ||
{ | ||
"version": { | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"media-types": [ | ||
{ | ||
"base": "application/xml", | ||
"type": "application/vnd.openstack.compute+xml;version=2" | ||
}, | ||
{ | ||
"base": "application/json", | ||
"type": "application/vnd.openstack.compute+json;version=2" | ||
} | ||
], | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://23.253.228.211:8774/v2/", | ||
"rel": "self" | ||
}, | ||
{ | ||
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", | ||
"type": "application/pdf", | ||
"rel": "describedby" | ||
}, | ||
{ | ||
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", | ||
"type": "application/vnd.sun.wadl+xml", | ||
"rel": "describedby" | ||
} | ||
] | ||
} | ||
} | ||
consumes: | ||
- application/json |