Skip to content

Commit

Permalink
fix(components): fix rendering for empty examples in responses (#9926)
Browse files Browse the repository at this point in the history
Refs #9499
  • Loading branch information
glowcloud authored May 10, 2024
1 parent a99be53 commit 94f2d82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class Response extends React.Component {
// Goal: find an example value for `sampleResponse`
if(isOAS3) {
sampleSchema = activeMediaType.get("schema")?.toJS()
if(examplesForMediaType) {
if(Map.isMap(examplesForMediaType) && !examplesForMediaType.isEmpty()) {
const targetExamplesKey = this.getTargetExamplesKey()
const targetExample = examplesForMediaType
.get(targetExamplesKey, Map({}))
Expand Down Expand Up @@ -208,7 +208,7 @@ export default class Response extends React.Component {
</small>
) : null}
</div>
{examplesForMediaType ? (
{Map.isMap(examplesForMediaType) && !examplesForMediaType.isEmpty() ? (
<div className="response-control-examples">
<small className="response-control-examples__title">
Examples
Expand Down
16 changes: 16 additions & 0 deletions test/e2e-cypress/e2e/features/response-empty-examples-object.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @prettier
*/

describe("Response examples", () => {
it("should render a generated example when an empty examples object is provided", () => {
cy.visit("/?url=/documents/features/response-empty-examples-object.yaml")
.get("#operations-TEST-test")
.click()
.get(".example.microlight")
.should("exist")
.contains("{}")
.get(".examples-select-element")
.should("not.exist")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.1.0
info:
title: TEST
description: TEST
version: '1.0'
servers:
- url: localhost:8080
tags:
- name: TEST
paths:
/test-endpoint:
get:
summary: Test
operationId: test
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
examples: {}
description: Test
tags:
- TEST

0 comments on commit 94f2d82

Please sign in to comment.