@@ -133,7 +133,7 @@ const RequestBody = ({
133
133
< table >
134
134
< tbody >
135
135
{
136
- Map . isMap ( bodyProperties ) && bodyProperties . entrySeq ( ) . map ( ( [ key , prop ] ) => {
136
+ Map . isMap ( bodyProperties ) && bodyProperties . entrySeq ( ) . map ( ( [ key , prop ] ) => {
137
137
if ( prop . get ( "readOnly" ) ) return
138
138
139
139
let commonExt = showCommonExtensions ? getCommonExtensions ( prop ) : null
@@ -143,67 +143,65 @@ const RequestBody = ({
143
143
const description = prop . get ( "description" )
144
144
const currentValue = requestBodyValue . getIn ( [ key , "value" ] )
145
145
const currentErrors = requestBodyValue . getIn ( [ key , "errors" ] ) || requestBodyErrors
146
-
147
- let initialValue = prop . get ( "default" ) || prop . get ( "example" ) || ""
148
-
149
- if ( initialValue === "" ) {
150
- if ( type === "object" ) {
151
- initialValue = getSampleSchema ( prop , false , {
152
- includeWriteOnly : true
153
- } )
154
- } else if ( type === "array" ) {
155
- initialValue = [ ]
156
- }
146
+ const included = requestBodyInclusionSetting . get ( key ) || false
147
+ let hasNonEmptyInitialVal = prop . has ( "default" ) || prop . has ( "example" ) || prop . has ( "enum" ) && prop . get ( "enum" ) . size === 1
148
+ let initialValue = ""
149
+ if ( type === "array" ) {
150
+ initialValue = [ ]
151
+ } else if ( hasNonEmptyInitialVal ) {
152
+ // TODO: what about example or examples from requestBody could be passed as exampleOverride
153
+ initialValue = getSampleSchema ( prop , false , {
154
+ includeWriteOnly : true
155
+ } )
157
156
}
158
-
159
157
if ( typeof initialValue !== "string" && type === "object" ) {
160
- initialValue = stringify ( initialValue )
158
+ initialValue = stringify ( initialValue )
161
159
}
162
160
163
161
const isFile = type === "string" && ( format === "binary" || format === "base64" )
164
162
165
163
return < tr key = { key } className = "parameters" data-property-name = { key } >
166
- < td className = "parameters-col_name" >
167
- < div className = { required ? "parameter__name required" : "parameter__name" } >
168
- { key }
169
- { ! required ? null : < span > *</ span > }
170
- </ div >
171
- < div className = "parameter__type" >
172
- { type }
173
- { format && < span className = "prop-format" > (${ format } )</ span > }
174
- { ! showCommonExtensions || ! commonExt . size ? null : commonExt . entrySeq ( ) . map ( ( [ key , v ] ) => < ParameterExt key = { `${ key } -${ v } ` } xKey = { key } xVal = { v } /> ) }
175
- </ div >
176
- < div className = "parameter__deprecated" >
177
- { prop . get ( "deprecated" ) ? "deprecated" : null }
178
- </ div >
179
- </ td >
180
- < td className = "parameters-col_description" >
181
- < Markdown source = { description } > </ Markdown >
182
- { isExecute ? < div >
183
- < JsonSchemaForm
184
- fn = { fn }
185
- dispatchInitialValue = { ! isFile }
186
- schema = { prop }
187
- description = { key }
188
- getComponent = { getComponent }
189
- value = { currentValue === undefined ? initialValue : currentValue }
190
- required = { required }
191
- errors = { currentErrors }
192
- onChange = { ( value ) => {
193
- onChange ( value , [ key ] )
194
- } }
195
- />
196
- { required ? null : (
197
- < ParameterIncludeEmpty
198
- onChange = { ( value ) => onChangeIncludeEmpty ( key , value ) }
199
- isIncluded = { requestBodyInclusionSetting . get ( key ) || false }
200
- isIncludedOptions = { setIsIncludedOptions ( key ) }
201
- isDisabled = { Array . isArray ( currentValue ) ? currentValue . length !== 0 : ! isEmptyValue ( currentValue ) }
202
- />
203
- ) }
204
- </ div > : null }
205
- </ td >
206
- </ tr >
164
+ < td className = "parameters-col_name" >
165
+ < div className = { required ? "parameter__name required" : "parameter__name" } >
166
+ { key }
167
+ { ! required ? null : < span > *</ span > }
168
+ </ div >
169
+ < div className = "parameter__type" >
170
+ { type }
171
+ { format && < span className = "prop-format" > (${ format } )</ span > }
172
+ { ! showCommonExtensions || ! commonExt . size ? null : commonExt . entrySeq ( ) . map ( ( [ key , v ] ) => < ParameterExt key = { `${ key } -${ v } ` } xKey = { key } xVal = { v } /> ) }
173
+ </ div >
174
+ < div className = "parameter__deprecated" >
175
+ { prop . get ( "deprecated" ) ? "deprecated" : null }
176
+ </ div >
177
+ </ td >
178
+ < td className = "parameters-col_description" >
179
+ < Markdown source = { description } > </ Markdown >
180
+ { isExecute ? < div >
181
+ < JsonSchemaForm
182
+ fn = { fn }
183
+ dispatchInitialValue = { ! isFile }
184
+ schema = { prop }
185
+ description = { key }
186
+ getComponent = { getComponent }
187
+ value = { currentValue === undefined ? initialValue : currentValue }
188
+ required = { required }
189
+ errors = { currentErrors }
190
+ onChange = { ( value ) => {
191
+ onChange ( value , [ key ] )
192
+ } }
193
+ />
194
+ { required ? null : (
195
+ < ParameterIncludeEmpty
196
+ onChange = { ( value ) => onChangeIncludeEmpty ( key , value ) }
197
+ isIncluded = { included }
198
+ isIncludedOptions = { setIsIncludedOptions ( key ) }
199
+ isDisabled = { Array . isArray ( currentValue ) ? currentValue . length !== 0 : ! isEmptyValue ( currentValue ) }
200
+ />
201
+ ) }
202
+ </ div > : null }
203
+ </ td >
204
+ </ tr >
207
205
} )
208
206
}
209
207
</ tbody >
0 commit comments