Skip to content

Commit

Permalink
fix(request-body): access data of request body in safe way (#9110)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Aug 2, 2023
1 parent 5230d1b commit d4b8485
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit d4b8485

Please sign in to comment.