Skip to content

Commit 1598fb2

Browse files
committed
Issue 3257: Add format field to CodegenParameter and CodegenProperty. Add format to static html template.
1 parent be4f4eb commit 1598fb2

File tree

8 files changed

+17
-7
lines changed

8 files changed

+17
-7
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class CodegenParameter {
99
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
1010
isCookieParam, isBodyParam, hasMore, isContainer,
1111
secondaryParam, isCollectionFormatMulti, isPrimitiveType;
12-
public String baseName, paramName, dataType, datatypeWithEnum, collectionFormat, description, unescapedDescription, baseType, defaultValue;
12+
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue;
1313
public String example; // example value (x-example)
1414
public String jsonSchema;
1515
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
@@ -85,6 +85,7 @@ public CodegenParameter copy() {
8585
output.paramName = this.paramName;
8686
output.dataType = this.dataType;
8787
output.datatypeWithEnum = this.datatypeWithEnum;
88+
output.dataFormat = this.dataFormat;
8889
output.collectionFormat = this.collectionFormat;
8990
output.isCollectionFormatMulti = this.isCollectionFormatMulti;
9091
output.description = this.description;
@@ -181,6 +182,8 @@ public boolean equals(Object o) {
181182
return false;
182183
if (datatypeWithEnum != null ? !datatypeWithEnum.equals(that.datatypeWithEnum) : that.datatypeWithEnum != null)
183184
return false;
185+
if (dataFormat != null ? !dataFormat.equals(that.dataFormat) : that.dataFormat != null)
186+
return false;
184187
if (collectionFormat != null ? !collectionFormat.equals(that.collectionFormat) : that.collectionFormat != null)
185188
return false;
186189
if (description != null ? !description.equals(that.description) : that.description != null)
@@ -276,6 +279,7 @@ public int hashCode() {
276279
result = 31 * result + (paramName != null ? paramName.hashCode() : 0);
277280
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
278281
result = 31 * result + (datatypeWithEnum != null ? datatypeWithEnum.hashCode() : 0);
282+
result = 31 * result + (dataFormat != null ? dataFormat.hashCode() : 0);
279283
result = 31 * result + (collectionFormat != null ? collectionFormat.hashCode() : 0);
280284
result = 31 * result + (description != null ? description.hashCode() : 0);
281285
result = 31 * result + (unescapedDescription != null ? unescapedDescription.hashCode() : 0);

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class CodegenProperty implements Cloneable {
88
public String baseName, complexType, getter, setter, description, datatype, datatypeWithEnum,
9-
name, min, max, defaultValue, defaultValueWithParam, baseType, containerType;
9+
dataFormat, name, min, max, defaultValue, defaultValueWithParam, baseType, containerType;
1010

1111
public String unescapedDescription;
1212

@@ -66,6 +66,7 @@ public int hashCode()
6666
result = prime * result + ((containerType == null) ? 0 : containerType.hashCode());
6767
result = prime * result + ((datatype == null) ? 0 : datatype.hashCode());
6868
result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode());
69+
result = prime * result + ((dataFormat == null) ? 0 : dataFormat.hashCode());
6970
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
7071
result = prime * result + ((defaultValueWithParam == null) ? 0 : defaultValueWithParam.hashCode());
7172
result = prime * result + ((description == null) ? 0 : description.hashCode());
@@ -143,6 +144,9 @@ public boolean equals(Object obj) {
143144
if ((this.datatypeWithEnum == null) ? (other.datatypeWithEnum != null) : !this.datatypeWithEnum.equals(other.datatypeWithEnum)) {
144145
return false;
145146
}
147+
if ((this.dataFormat == null) ? (other.dataFormat != null) : !this.dataFormat.equals(other.dataFormat)) {
148+
return false;
149+
}
146150
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
147151
return false;
148152
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,7 @@ public CodegenProperty fromProperty(String name, Property p) {
15431543
}
15441544
}
15451545
property.datatype = getTypeDeclaration(p);
1546+
property.dataFormat = p.getFormat();
15461547

15471548
// this can cause issues for clients which don't support enums
15481549
if (property.isEnum) {
@@ -2143,6 +2144,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
21432144
setParameterBooleanFlagWithCodegenProperty(p, cp);
21442145

21452146
p.dataType = cp.datatype;
2147+
p.dataFormat = cp.dataFormat;
21462148
if(cp.isEnum) {
21472149
p.datatypeWithEnum = cp.datatypeWithEnum;
21482150
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{#isFormParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
22

3-
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}
3+
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isFormParam}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{#isHeaderParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
22

3-
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}
3+
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isHeaderParam}}

modules/swagger-codegen/src/main/resources/htmlDocs/index.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
<div class="model">
165165
<h3 class="field-label"><a name="{{name}}">{{name}}</a> <a class="up" href="#__Models">Up</a></h3>
166166
<div class="field-items">
167-
{{#vars}}<div class="param">{{name}} {{^required}}(optional){{/required}}</div><div class="param-desc"><span class="param-type">{{^isPrimitiveType}}<a href="#{{complexType}}">{{datatype}}</a>{{/isPrimitiveType}}</span> {{description}}</div>
167+
{{#vars}}<div class="param">{{name}} {{^required}}(optional){{/required}}</div><div class="param-desc"><span class="param-type">{{^isPrimitiveType}}<a href="#{{complexType}}">{{datatype}}</a>{{/isPrimitiveType}}</span> {{description}} {{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>
168168
{{#isEnum}}
169169
<div class="param-enum-header">Enum:</div>
170170
{{#_enum}}<div class="param-enum">{{this}}</div>{{/_enum}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{#isPathParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
22

3-
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}
3+
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isPathParam}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{#isQueryParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
22

3-
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}
3+
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isQueryParam}}

0 commit comments

Comments
 (0)