@@ -22,28 +22,14 @@ export default class ParameterRow extends Component {
2222 constructor ( props , context ) {
2323 super ( props , context )
2424
25- let { specSelectors, pathMethod, param } = props
26- let defaultValue = param . get ( "default" )
27- let xExampleValue = param . get ( "x-example" )
28- let parameter = specSelectors . parameterWithMeta ( pathMethod , param . get ( "name" ) , param . get ( "in" ) )
29- let value = parameter ? parameter . get ( "value" ) : ""
30-
31- if ( param . get ( "in" ) !== "body" ) {
32- if ( xExampleValue !== undefined && value === undefined && specSelectors . isSwagger2 ( ) ) {
33- this . onChangeWrapper ( xExampleValue )
34- } else if ( defaultValue !== undefined && value === undefined ) {
35- this . onChangeWrapper ( defaultValue )
36- }
37- }
38-
25+ this . setDefaultValue ( )
3926 }
4027
4128 componentWillReceiveProps ( props ) {
4229 let { specSelectors, pathMethod, param } = props
4330 let { isOAS3 } = specSelectors
4431
4532 let example = param . get ( "example" )
46- let defaultValue = param . get ( "default" )
4733 let parameter = specSelectors . parameterWithMeta ( pathMethod , param . get ( "name" ) , param . get ( "in" ) )
4834 let enumValue
4935
@@ -61,8 +47,6 @@ export default class ParameterRow extends Component {
6147 value = paramValue
6248 } else if ( example !== undefined ) {
6349 value = example
64- } else if ( defaultValue !== undefined ) {
65- value = defaultValue
6650 } else if ( param . get ( "required" ) && enumValue && enumValue . size ) {
6751 value = enumValue . first ( )
6852 }
@@ -77,6 +61,29 @@ export default class ParameterRow extends Component {
7761 return onChange ( param , value )
7862 }
7963
64+ setDefaultValue = ( ) => {
65+ let { specSelectors, pathMethod, param } = this . props
66+
67+ if ( param . get ( "value" ) !== undefined ) {
68+ return
69+ }
70+
71+ let schema = specSelectors . isOAS3 ( ) ? param . get ( "schema" , Map ( { } ) ) : param
72+
73+ let defaultValue = schema . get ( "default" )
74+ let xExampleValue = param . get ( "x-example" ) // Swagger 2 only
75+ let parameter = specSelectors . parameterWithMeta ( pathMethod , param . get ( "name" ) , param . get ( "in" ) )
76+ let value = parameter ? parameter . get ( "value" ) : ""
77+
78+ if ( param . get ( "in" ) !== "body" ) {
79+ if ( xExampleValue !== undefined && value === undefined && specSelectors . isSwagger2 ( ) ) {
80+ this . onChangeWrapper ( xExampleValue )
81+ } else if ( defaultValue !== undefined && value === undefined ) {
82+ this . onChangeWrapper ( defaultValue )
83+ }
84+ }
85+ }
86+
8087 render ( ) {
8188 let { param, onChange, getComponent, getConfigs, isExecute, fn, onChangeConsumes, specSelectors, pathMethod, specPath} = this . props
8289
0 commit comments