Skip to content

Commit b5c84f4

Browse files
authored
fix(oas31): fix re-rendering of the Webhooks component (#9938)
Refs #9937
1 parent 6d2b88e commit b5c84f4

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

src/core/plugins/oas31/components/webhooks.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import React from "react"
55
import PropTypes from "prop-types"
6+
import { List } from "immutable"
67

78
const Webhooks = ({ specSelectors, getComponent }) => {
89
const operationDTOs = specSelectors.selectWebhooksOperations()
@@ -25,7 +26,7 @@ const Webhooks = ({ specSelectors, getComponent }) => {
2526
tag="webhooks"
2627
method={operationDTO.method}
2728
path={pathItemName}
28-
specPath={operationDTO.specPath}
29+
specPath={List(operationDTO.specPath)}
2930
allowTryItOut={false}
3031
/>
3132
))}

src/core/plugins/oas31/spec-extensions/selectors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const selectWebhooksOperations = createSelector(
4242
operation: Map({ operation }),
4343
method,
4444
path: pathItemName,
45-
specPath: List(["webhooks", pathItemName, method]),
45+
specPath: ["webhooks", pathItemName, method],
4646
}))
4747

4848
return allOperations.concat(pathItemOperations)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @prettier
3+
*/
4+
5+
describe("OpenAPI 3.1.0 webhook", () => {
6+
it("should render the correct example for the request body", () => {
7+
cy.visit("/?url=/documents/features/oas31-webhook-examples.yaml")
8+
.get("#operations-webhooks-test-webhook")
9+
.click()
10+
.get(".body-param__example")
11+
.should("contain", '"userId": "userId example from examples"')
12+
.and("contain", '"orderId": "orderId example from examples"')
13+
.get(".examples-select-element")
14+
.eq(0)
15+
.select("TestExample2")
16+
.get(".body-param__example")
17+
.should("contain", '"userId": "second userId example from examples"')
18+
.and("contain", '"orderId": "second orderId example from examples"')
19+
})
20+
21+
it("should render the correct example for the response", () => {
22+
cy.visit("/?url=/documents/features/oas31-webhook-examples.yaml")
23+
.get("#operations-webhooks-test-webhook")
24+
.click()
25+
.get(".example.microlight")
26+
.should("contain", '"userId": "userId example from examples"')
27+
.and("contain", '"orderId": "orderId example from examples"')
28+
.get(".examples-select-element")
29+
.eq(1)
30+
.select("TestExample2")
31+
.get(".example.microlight")
32+
.should("contain", '"userId": "second userId example from examples"')
33+
.and("contain", '"orderId": "second orderId example from examples"')
34+
})
35+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
openapi: 3.1.0
2+
info:
3+
version: 1.0.0
4+
title: Examples
5+
description: ''
6+
webhooks:
7+
test-webhook:
8+
post:
9+
operationId: test-webhook
10+
requestBody:
11+
required: true
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '#/components/schemas/TestSchema'
16+
examples:
17+
TestExample1:
18+
$ref: '#/components/examples/TestExample1'
19+
TestExample2:
20+
$ref: '#/components/examples/TestExample2'
21+
responses:
22+
'200':
23+
description: OK
24+
content:
25+
application/json:
26+
schema:
27+
$ref: '#/components/schemas/TestSchema'
28+
examples:
29+
TestExample1:
30+
$ref: '#/components/examples/TestExample1'
31+
TestExample2:
32+
$ref: '#/components/examples/TestExample2'
33+
components:
34+
schemas:
35+
TestSchema:
36+
type: object
37+
properties:
38+
userId:
39+
type: string
40+
examples: ['userId example from schema']
41+
orders:
42+
type: array
43+
items:
44+
type: object
45+
properties:
46+
orderId:
47+
type: string
48+
examples: ['orderId example from schema']
49+
examples:
50+
TestExample1:
51+
value:
52+
userId: 'userId example from examples'
53+
orders:
54+
- orderId: 'orderId example from examples'
55+
TestExample2:
56+
value:
57+
userId: 'second userId example from examples'
58+
orders:
59+
- orderId: 'second orderId example from examples'

0 commit comments

Comments
 (0)