From d4b84851da2387301ed62cc712c736c1fdde149f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 2 Aug 2023 15:26:02 +0200 Subject: [PATCH] fix(request-body): access data of request body in safe way (#9110) --- src/core/plugins/oas3/components/request-body.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index 29594364..9b652ca8 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -6,8 +6,8 @@ import { getCommonExtensions, stringify, isEmptyValue } from "core/utils" import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse" export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey, fn) => { - const mediaTypeValue = requestBody.getIn(["content", mediaType]) - const schema = mediaTypeValue.get("schema").toJS() + const mediaTypeValue = requestBody.getIn(["content", mediaType]) ?? OrderedMap() + const schema = mediaTypeValue.get("schema", OrderedMap()).toJS() const hasExamplesKey = mediaTypeValue.get("examples") !== undefined const exampleSchema = mediaTypeValue.get("example") @@ -78,11 +78,11 @@ const RequestBody = ({ const { showCommonExtensions } = getConfigs() - const requestBodyDescription = (requestBody && requestBody.get("description")) || null - const requestBodyContent = (requestBody && requestBody.get("content")) || new OrderedMap() + const requestBodyDescription = requestBody?.get("description") ?? null + const requestBodyContent = requestBody?.get("content") ?? new OrderedMap() contentType = contentType || requestBodyContent.keySeq().first() || "" - const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap()) + const mediaTypeValue = requestBodyContent.get(contentType) ?? OrderedMap() const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap()) const rawExamplesOfMediaType = mediaTypeValue.get("examples", null) const sampleForMediaType = rawExamplesOfMediaType?.map((container, key) => {