From ccb8d2c0791e112d0e92fcd095a5b7113afe67d9 Mon Sep 17 00:00:00 2001 From: mathis-m Date: Tue, 9 Feb 2021 02:45:06 +0100 Subject: [PATCH 1/3] feat: use example gen for multiple example value retainer examples Signed-off-by: mathis-m --- src/core/plugins/oas3/components/request-body.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index 42abaa20dff..d6268b64e69 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -83,7 +83,20 @@ const RequestBody = ({ const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap()) const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap()) - const examplesForMediaType = mediaTypeValue.get("examples", null) + let examplesForMediaType = mediaTypeValue.get("examples", null) + if(examplesForMediaType) { + examplesForMediaType = examplesForMediaType.map((container, key) => { + const val = container?.get("value", null) + if(val) { + container = container.set("value", getDefaultRequestBodyValue( + requestBody, + contentType, + key, + )) + } + return container + }) + } const handleExamplesSelect = (key /*, { isSyntheticChange } */) => { updateActiveExamplesKey(key) From 9ee31adc66a4347417df797eab87da3042f19670 Mon Sep 17 00:00:00 2001 From: mathis-m Date: Tue, 9 Feb 2021 02:45:44 +0100 Subject: [PATCH 2/3] fix: multiple examples with same value jumps to first example Signed-off-by: mathis-m --- .../components/examples-select-value-retainer.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/components/examples-select-value-retainer.jsx b/src/core/components/examples-select-value-retainer.jsx index 9f0386243ec..a7149b59877 100644 --- a/src/core/components/examples-select-value-retainer.jsx +++ b/src/core/components/examples-select-value-retainer.jsx @@ -189,7 +189,7 @@ 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 @@ -197,8 +197,15 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent { 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 ( From aa4247c99fe0be813f014f51bf03848ab84e87d3 Mon Sep 17 00:00:00 2001 From: mathis-m Date: Wed, 10 Feb 2021 20:36:28 +0100 Subject: [PATCH 3/3] fix: naming and revert to const Signed-off-by: mathis-m --- .../plugins/oas3/components/request-body.jsx | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index d6268b64e69..db9f8aab395 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -83,20 +83,18 @@ const RequestBody = ({ const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap()) const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap()) - let examplesForMediaType = mediaTypeValue.get("examples", null) - if(examplesForMediaType) { - examplesForMediaType = examplesForMediaType.map((container, key) => { - const val = container?.get("value", null) - if(val) { - container = container.set("value", getDefaultRequestBodyValue( - requestBody, - contentType, - key, - )) - } - return container - }) - } + 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) @@ -236,10 +234,10 @@ const RequestBody = ({ } { - examplesForMediaType ? ( + sampleForMediaType ? (