Skip to content

Commit ff496fa

Browse files
authored
fix: type safety for operation summary handling (via #5191)
* fix: gracefully handle non-string operation summaries * use lodash for more summary type safety
1 parent 1e184e8 commit ff496fa

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/core/components/operation-summary.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { PureComponent } from "react"
22
import PropTypes from "prop-types"
33
import { Iterable, List } from "immutable"
44
import ImPropTypes from "react-immutable-proptypes"
5+
import toString from "lodash/toString"
56

67

78
export default class OperationSummary extends PureComponent {
@@ -63,7 +64,7 @@ export default class OperationSummary extends PureComponent {
6364

6465
{!showSummary ? null :
6566
<div className="opblock-summary-description">
66-
{(resolvedSummary || summary).toString()}
67+
{toString(resolvedSummary || summary)}
6768
</div>
6869
}
6970

test/e2e-cypress/static/documents/bugs/5188.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ paths:
88
/pet:
99
get:
1010
tags:
11-
- pet
11+
- default
1212
summary:
13-
$ref:
14-
operationId: addPet
13+
whatever: 123
14+
operationId: objectSummary
15+
responses:
16+
'405':
17+
description: Invalid input
18+
post:
19+
tags:
20+
- default
21+
operationId: noSummary
1522
responses:
1623
'405':
1724
description: Invalid input

test/e2e-cypress/tests/bugs/5188.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ describe("#5188: non-string operation summary value", () => {
22
it("should gracefully handle an object value for an operation summary", () => {
33
cy
44
.visit("?url=/documents/bugs/5188.yaml")
5-
.get("#operations-pet-addPet")
5+
.get("#operations-default-objectSummary")
66
.click()
77
.get(".opblock-summary-description")
88
.contains("[object Object]")
9-
})
9+
})
10+
it("should gracefully handle a missing value for an operation summary", () => {
11+
cy
12+
.visit("?url=/documents/bugs/5188.yaml")
13+
.get("#operations-default-noSummary")
14+
.click()
15+
// check for response rendering; makes sure the Operation itself rendered
16+
.contains("Invalid input")
17+
})
1018
})

0 commit comments

Comments
 (0)