fix: Swagger 2.0 Response.examples (via #5464)

This commit is contained in:
kyle
2019-07-13 00:25:43 -05:00
committed by GitHub
parent eaa1f4a8b4
commit 9749a47853
3 changed files with 67 additions and 4 deletions

View File

@@ -136,10 +136,18 @@ export default class Response extends React.Component {
}) })
} }
} else { } else {
sampleResponse = schema ? getSampleSchema(schema.toJS(), activeContentType, { if(response.getIn(["examples", activeContentType])) {
sampleResponse = response.getIn(["examples", activeContentType])
} else {
sampleResponse = schema ? getSampleSchema(
schema.toJS(),
activeContentType,
{
includeReadOnly: true, includeReadOnly: true,
includeWriteOnly: true // writeOnly has no filtering effect in swagger 2.0 includeWriteOnly: true // writeOnly has no filtering effect in swagger 2.0
}) : null }
) : null
}
} }
let example = getExampleComponent( sampleResponse, HighlightCode ) let example = getExampleComponent( sampleResponse, HighlightCode )

View File

@@ -0,0 +1,37 @@
swagger: "2.0"
info:
title: test
version: 1.0.0
paths:
/foo1:
get:
summary: Response without a schema
produces:
- application/json
responses:
200:
description: Successful response
examples:
application/json:
foo: custom value
/foo2:
get:
summary: Response with schema
produces:
- application/json
responses:
200:
description: Successful response
schema:
$ref: '#/definitions/Foo'
examples:
application/json:
foo: custom value
definitions:
Foo:
type: object
properties:
foo:
type: string
example: bar

View File

@@ -0,0 +1,18 @@
// http://github.com/swagger-api/swagger-ui/issues/5458
describe("#5458: Swagger 2.0 `Response.examples` mappings", () => {
it("should render a custom example when a schema is not defined", () => {
cy.visit("/?url=/documents/bugs/5458.yaml")
.get("#operations-default-get_foo1")
.click()
.get(".model-example .highlight-code")
.contains("custom value")
})
it("should render a custom example when a schema is defined", () => {
cy.visit("/?url=/documents/bugs/5458.yaml")
.get("#operations-default-get_foo2")
.click()
.get(".model-example .highlight-code")
.contains("custom value")
})
})