Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request-body): access data of request body in safe way #9110

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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