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

Ft/value retainer sample gen #6920

Merged
merged 4 commits into from Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/core/components/examples-select-value-retainer.jsx
Expand Up @@ -189,16 +189,23 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
nextProps
)

const exampleMatchingNewValue = examples.find(
const examplesMatchingNewValue = examples.filter(
(example) =>
example.get("value") === newValue ||
// sometimes data is stored as a string (e.g. in Request Bodies), so
// let's check against a stringified version of our example too
stringify(example.get("value")) === newValue
)

if (exampleMatchingNewValue) {
onSelect(examples.keyOf(exampleMatchingNewValue), {
if (examplesMatchingNewValue.size) {
let key
if(examplesMatchingNewValue.has(nextProps.currentKey))
{
key = nextProps.currentKey
} else {
key = examplesMatchingNewValue.keySeq().first()
}
onSelect(key, {
isSyntheticChange: true,
})
} else if (
Expand Down
21 changes: 16 additions & 5 deletions src/core/plugins/oas3/components/request-body.jsx
Expand Up @@ -83,7 +83,18 @@ const RequestBody = ({

const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap())
const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap())
const examplesForMediaType = mediaTypeValue.get("examples", null)
const rawExamplesOfMediaType = mediaTypeValue.get("examples", null)
const sampleForMediaType = rawExamplesOfMediaType?.map((container, key) => {
const val = container?.get("value", null)
if(val) {
container = container.set("value", getDefaultRequestBodyValue(
requestBody,
contentType,
key,
), val)
}
return container
})

const handleExamplesSelect = (key /*, { isSyntheticChange } */) => {
updateActiveExamplesKey(key)
Expand Down Expand Up @@ -223,10 +234,10 @@ const RequestBody = ({
<Markdown source={requestBodyDescription} />
}
{
examplesForMediaType ? (
sampleForMediaType ? (
<ExamplesSelectValueRetainer
userHasEditedBody={userHasEditedBody}
examples={examplesForMediaType}
examples={sampleForMediaType}
currentKey={activeExamplesKey}
currentUserInputValue={requestBodyValue}
onSelect={handleExamplesSelect}
Expand Down Expand Up @@ -269,9 +280,9 @@ const RequestBody = ({
)
}
{
examplesForMediaType ? (
sampleForMediaType ? (
<Example
example={examplesForMediaType.get(activeExamplesKey)}
example={sampleForMediaType.get(activeExamplesKey)}
getComponent={getComponent}
getConfigs={getConfigs}
/>
Expand Down