1
1
import React , { Component } from "react"
2
- import { Map , List } from "immutable"
2
+ import { Map } from "immutable"
3
3
import PropTypes from "prop-types"
4
4
import ImPropTypes from "react-immutable-proptypes"
5
5
import win from "core/window"
@@ -97,22 +97,16 @@ export default class ParameterRow extends Component {
97
97
let { specSelectors, pathMethod, rawParam, oas3Selectors } = this . props
98
98
99
99
const paramWithMeta = specSelectors . parameterWithMetaByIdentity ( pathMethod , rawParam ) || Map ( )
100
+ if ( ! paramWithMeta || paramWithMeta . get ( "value" ) !== undefined ) {
101
+ return
102
+ }
103
+
100
104
const { schema } = getParameterSchema ( paramWithMeta , { isOAS3 : specSelectors . isOAS3 ( ) } )
101
105
const parameterMediaType = paramWithMeta
102
106
. get ( "content" , Map ( ) )
103
107
. keySeq ( )
104
108
. first ( )
105
109
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
-
116
110
if ( paramWithMeta . get ( "in" ) !== "body" ) {
117
111
let initialValue
118
112
@@ -127,7 +121,7 @@ export default class ParameterRow extends Component {
127
121
: ( schema && schema . getIn ( [ "default" ] ) )
128
122
} else if ( specSelectors . isOAS3 ( ) ) {
129
123
const currentExampleKey = oas3Selectors . activeExamplesMember ( ...pathMethod , "parameters" , this . getParamKey ( ) )
130
- initialValue =
124
+ initialValue =
131
125
paramWithMeta . getIn ( [ "examples" , currentExampleKey , "value" ] ) !== undefined
132
126
? paramWithMeta . getIn ( [ "examples" , currentExampleKey , "value" ] )
133
127
: paramWithMeta . getIn ( [ "content" , parameterMediaType , "example" ] ) !== undefined
@@ -141,35 +135,17 @@ export default class ParameterRow extends Component {
141
135
: paramWithMeta . get ( "default" ) // ensures support for `parameterMacro`
142
136
}
143
137
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
+ )
150
146
151
147
//// 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 ) )
173
149
}
174
150
}
175
151
0 commit comments