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
6 changes: 4 additions & 2 deletions src/core/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default class Response extends React.Component {
const activeMediaType = response.getIn(["content", activeContentType], Map({}))
const examplesForMediaType = activeMediaType.get("examples", null)

const firstExamplesKey = examplesForMediaType.keySeq().first()
const firstExamplesKey = Map.isMap(examplesForMediaType) && !examplesForMediaType.isEmpty()
? examplesForMediaType.keySeq().first()
: undefined
return activeExamplesKey || firstExamplesKey
}

Expand Down Expand Up @@ -246,7 +248,7 @@ export default class Response extends React.Component {
includeReadOnly={ true }/>
) : null }

{ isOAS3 && examplesForMediaType ? (
{ isOAS3 && Map.isMap(examplesForMediaType) && !examplesForMediaType.isEmpty() ? (
<Example
example={examplesForMediaType.get(this.getTargetExamplesKey(), Map({}))}
getComponent={getComponent}
Expand Down
53 changes: 53 additions & 0 deletions test/unit/core/plugins/json-schema-5/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,57 @@ describe("<Response />", function () {
.schema.toJS().properties
expect(Object.keys(modelExampleSchemaProperties)).toEqual(["c", "b", "a"])
})

it("should render without error when OAS3 response has empty examples map", function () {
const oas3Components = {
...components,
ExamplesSelect: dummyComponent,
Example: dummyComponent,
}
const getOAS3System = () => ({
getComponent: (c) => oas3Components[c],
getConfigs: () => {
return {}
},
specSelectors: {
isOAS3() {
return true
},
},
fn: {
inferSchema,
memoizedSampleFromSchema,
memoizedCreateXMLExample,
getJsonSampleSchema: makeGetJsonSampleSchema(getOAS3System),
getYamlSampleSchema: makeGetYamlSampleSchema(getOAS3System),
getXmlSampleSchema: makeGetXmlSampleSchema(getOAS3System),
getSampleSchema: makeGetSampleSchema(getOAS3System),
},
})
const oas3Props = {
...getOAS3System(),
contentType: "application/json",
className: "for-test",
specPath: List(),
response: fromJS({
description: "ok",
content: {
"application/json": {
schema: {
type: "object",
},
examples: {},
},
},
}),
code: "200",
path: "/foo",
method: "get",
oas3Actions: {},
}

expect(() => {
shallow(<Response {...oas3Props} />)
}).not.toThrow()
})
})