refactor: use samples plugin to generate schemas examples (#8728)

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-05-30 15:26:50 +02:00
parent 027f53c302
commit 1ce9ce0cda
8 changed files with 22 additions and 98 deletions

View File

@@ -104,7 +104,6 @@ const JSONSchema202012Plugin = () => ({
},
fn: {
upperFirst,
memoizedSampleFromSchema: null,
jsonSchema202012: {
isExpandable,
hasKeyword,

View File

@@ -2,10 +2,10 @@ import React from "react"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import { Map, OrderedMap, List } from "immutable"
import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "core/utils"
import { getCommonExtensions, stringify, isEmptyValue } from "core/utils"
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey) => {
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey, fn) => {
const mediaTypeValue = requestBody.getIn(["content", mediaType])
const schema = mediaTypeValue.get("schema").toJS()
@@ -19,7 +19,7 @@ export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExample
])
: exampleSchema
const exampleValue = getSampleSchema(
const exampleValue = fn.getSampleSchema(
schema,
mediaType,
{
@@ -92,6 +92,7 @@ const RequestBody = ({
requestBody,
contentType,
key,
fn,
), val)
}
return container

View File

@@ -76,7 +76,7 @@ export const shouldRetainRequestBodyValue = onlyOAS3((state, path, method) => {
export const selectDefaultRequestBodyValue =
(state, path, method) => (system) => {
const { oas3Selectors, specSelectors } = system.getSystem()
const { oas3Selectors, specSelectors, fn } = system.getSystem()
if (specSelectors.isOAS3()) {
const currentMediaType = oas3Selectors.requestContentType(path, method)
@@ -94,7 +94,8 @@ export const selectDefaultRequestBodyValue =
method,
"requestBody",
"requestBody"
)
),
fn
)
}
}