Skip to content

Commit c4919c3

Browse files
committed
Merge pull request #1227 from ponelat/fix/default-boolean
allow default to be false, tweak "required" in param_list
2 parents 9ba75c0 + a126c17 commit c4919c3

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/main/javascript/view/ParameterView.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
3030
this.model.paramType = this.model.in || this.model.paramType;
3131
this.model.isBody = this.model.paramType === 'body' || this.model.in === 'body';
3232
this.model.isFile = type && type.toLowerCase() === 'file';
33-
this.model.default = (this.model.default || this.model.defaultValue);
33+
34+
// Allow for default === false
35+
if(typeof this.model.default === 'undefined') {
36+
this.model.default = this.model.defaultValue;
37+
}
38+
39+
this.model.hasDefault = (typeof this.model.default !== 'undefined');
3440
this.model.valueId = 'm' + this.model.name + Math.random();
3541

3642
if (this.model.allowableValues) {
@@ -99,4 +105,4 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
99105
}
100106
}
101107
}
102-
});
108+
});

src/main/template/param_list.handlebars

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
<td class='code{{#if required}} required{{/if}}'><label for='{{valueId}}'>{{name}}</labe></td>
22
<td>
3-
<select {{#isArray this}} multiple='multiple'{{/isArray}} class={{#if required}}'parameter required'{{else}}'parameter'{{/if}} name='{{name}}' id='{{valueId}}'>
4-
{{#if required}}
5-
{{else}}
6-
{{#if default}}
7-
{{else}}
8-
{{#isArray this}}
9-
{{else}}
10-
<option selected="" value=''></option>
11-
{{/isArray}}
12-
{{/if}}
13-
{{/if}}
3+
<select {{#isArray this}} multiple="multiple"{{/isArray}} class="parameter {{#if required}} required {{/if}}" name="{{name}}" id="{{valueId}}">
4+
5+
{{#unless required}}
6+
<option {{#unless hasDefault}} selected="" {{/unless}} value=''></option>
7+
{{/unless}}
8+
149
{{#each allowableValues.descriptiveValues}}
15-
{{#if isDefault}}
16-
<option selected="" value='{{value}}'>{{value}} (default)</option>
17-
{{else}}
18-
<option value='{{value}}'>{{value}}</option>
19-
{{/if}}
10+
11+
<option {{#if isDefault}} selected="" {{/if}} value='{{value}}'> {{value}} {{#if isDefault}} (default) {{/if}} </option>
12+
2013
{{/each}}
14+
2115
</select>
2216
</td>
2317
<td class="markdown">{{#if required}}<strong>{{/if}}{{{description}}}{{#if required}}</strong>{{/if}}</td>

0 commit comments

Comments
 (0)