Skip to content

Commit 7eecb1e

Browse files
committed
fix(rendering): components should rely on getSampleSchema utility
1 parent feccdcc commit 7eecb1e

File tree

1 file changed

+15
-39
lines changed

1 file changed

+15
-39
lines changed

src/core/components/parameter-row.jsx

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from "react"
2-
import { Map, List } from "immutable"
2+
import { Map } from "immutable"
33
import PropTypes from "prop-types"
44
import ImPropTypes from "react-immutable-proptypes"
55
import win from "core/window"
@@ -97,22 +97,16 @@ export default class ParameterRow extends Component {
9797
let { specSelectors, pathMethod, rawParam, oas3Selectors } = this.props
9898

9999
const paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
100+
if (!paramWithMeta || paramWithMeta.get("value") !== undefined) {
101+
return
102+
}
103+
100104
const { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
101105
const parameterMediaType = paramWithMeta
102106
.get("content", Map())
103107
.keySeq()
104108
.first()
105109

106-
// getSampleSchema could return null
107-
const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, {
108-
109-
includeWriteOnly: true
110-
}) : null
111-
112-
if (!paramWithMeta || paramWithMeta.get("value") !== undefined) {
113-
return
114-
}
115-
116110
if( paramWithMeta.get("in") !== "body" ) {
117111
let initialValue
118112

@@ -127,7 +121,7 @@ export default class ParameterRow extends Component {
127121
: (schema && schema.getIn(["default"]))
128122
} else if (specSelectors.isOAS3()) {
129123
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
130-
initialValue =
124+
initialValue =
131125
paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined
132126
? paramWithMeta.getIn(["examples", currentExampleKey, "value"])
133127
: paramWithMeta.getIn(["content", parameterMediaType, "example"]) !== undefined
@@ -141,35 +135,17 @@ export default class ParameterRow extends Component {
141135
: paramWithMeta.get("default") // ensures support for `parameterMacro`
142136
}
143137

144-
//// Process the initial value
145-
146-
if(initialValue !== undefined && !List.isList(initialValue)) {
147-
// Stringify if it isn't a List
148-
initialValue = stringify(initialValue)
149-
}
138+
const generatedSampleValue = getSampleSchema(
139+
schema,
140+
parameterMediaType,
141+
{
142+
includeWriteOnly: true
143+
},
144+
initialValue
145+
)
150146

151147
//// Dispatch the initial value
152-
153-
if(initialValue !== undefined) {
154-
this.onChangeWrapper(initialValue)
155-
} else if(
156-
schema && schema.get("type") === "object"
157-
&& generatedSampleValue
158-
&& !paramWithMeta.get("examples")
159-
) {
160-
// Object parameters get special treatment.. if the user doesn't set any
161-
// default or example values, we'll provide initial values generated from
162-
// the schema.
163-
// However, if `examples` exist for the parameter, we won't do anything,
164-
// so that the appropriate `examples` logic can take over.
165-
this.onChangeWrapper(
166-
List.isList(generatedSampleValue) ? (
167-
generatedSampleValue
168-
) : (
169-
stringify(generatedSampleValue)
170-
)
171-
)
172-
}
148+
this.onChangeWrapper(stringify(generatedSampleValue))
173149
}
174150
}
175151

0 commit comments

Comments
 (0)