fix: type safety for operation summary handling (via #5191)
* fix: gracefully handle non-string operation summaries * use lodash for more summary type safety
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { PureComponent } from "react"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { Iterable, List } from "immutable"
|
import { Iterable, List } from "immutable"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
|
import toString from "lodash/toString"
|
||||||
|
|
||||||
|
|
||||||
export default class OperationSummary extends PureComponent {
|
export default class OperationSummary extends PureComponent {
|
||||||
@@ -63,7 +64,7 @@ export default class OperationSummary extends PureComponent {
|
|||||||
|
|
||||||
{!showSummary ? null :
|
{!showSummary ? null :
|
||||||
<div className="opblock-summary-description">
|
<div className="opblock-summary-description">
|
||||||
{(resolvedSummary || summary).toString()}
|
{toString(resolvedSummary || summary)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,17 @@ paths:
|
|||||||
/pet:
|
/pet:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- pet
|
- default
|
||||||
summary:
|
summary:
|
||||||
$ref:
|
whatever: 123
|
||||||
operationId: addPet
|
operationId: objectSummary
|
||||||
|
responses:
|
||||||
|
'405':
|
||||||
|
description: Invalid input
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- default
|
||||||
|
operationId: noSummary
|
||||||
responses:
|
responses:
|
||||||
'405':
|
'405':
|
||||||
description: Invalid input
|
description: Invalid input
|
||||||
@@ -2,9 +2,17 @@ describe("#5188: non-string operation summary value", () => {
|
|||||||
it("should gracefully handle an object value for an operation summary", () => {
|
it("should gracefully handle an object value for an operation summary", () => {
|
||||||
cy
|
cy
|
||||||
.visit("?url=/documents/bugs/5188.yaml")
|
.visit("?url=/documents/bugs/5188.yaml")
|
||||||
.get("#operations-pet-addPet")
|
.get("#operations-default-objectSummary")
|
||||||
.click()
|
.click()
|
||||||
.get(".opblock-summary-description")
|
.get(".opblock-summary-description")
|
||||||
.contains("[object Object]")
|
.contains("[object Object]")
|
||||||
})
|
})
|
||||||
|
it("should gracefully handle a missing value for an operation summary", () => {
|
||||||
|
cy
|
||||||
|
.visit("?url=/documents/bugs/5188.yaml")
|
||||||
|
.get("#operations-default-noSummary")
|
||||||
|
.click()
|
||||||
|
// check for response rendering; makes sure the Operation itself rendered
|
||||||
|
.contains("Invalid input")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user