From e895fb544f95d5fb36f6388e3e88a2479da28d7c Mon Sep 17 00:00:00 2001 From: kyle Date: Mon, 29 Jul 2019 21:44:14 -0500 Subject: [PATCH] fix: use `null` as a notSetValue for examplesForMediaType (via #5503) * fix: use null as a notSetValue for examplesForMediaType fixes #5455 * tests! --- .../plugins/oas3/components/request-body.jsx | 2 +- .../static/documents/bugs/5455.yaml | 25 +++++++++++++++++++ test/e2e-cypress/tests/bugs/5455.js | 11 ++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/e2e-cypress/static/documents/bugs/5455.yaml create mode 100644 test/e2e-cypress/tests/bugs/5455.js diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index 00b5d97d..4b287f12 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -67,7 +67,7 @@ const RequestBody = ({ const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap()) const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap()) - const examplesForMediaType = mediaTypeValue.get("examples", OrderedMap()) + const examplesForMediaType = mediaTypeValue.get("examples", null) const handleExamplesSelect = (key /*, { isSyntheticChange } */) => { updateActiveExamplesKey(key) diff --git a/test/e2e-cypress/static/documents/bugs/5455.yaml b/test/e2e-cypress/static/documents/bugs/5455.yaml new file mode 100644 index 00000000..70d9ae14 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/5455.yaml @@ -0,0 +1,25 @@ +openapi: 3.0.2 +info: + title: test + version: 1.0.0 +paths: + /foo: + post: + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Foo' + responses: + 201: + description: Created + +components: + schemas: + Foo: + type: object + properties: + foo: + type: string + example: bar diff --git a/test/e2e-cypress/tests/bugs/5455.js b/test/e2e-cypress/tests/bugs/5455.js new file mode 100644 index 00000000..338cb580 --- /dev/null +++ b/test/e2e-cypress/tests/bugs/5455.js @@ -0,0 +1,11 @@ +// http://github.com/swagger-api/swagger-ui/issues/5455 + +describe("#5455: Request bodies w/o `examples` should not render a dropdown", () => { + it("should not render a