From 1598fb26578e3a903d0f46ef36e1b3cc6cd1b058 Mon Sep 17 00:00:00 2001 From: gokl Date: Thu, 30 Jun 2016 12:10:10 +0200 Subject: [PATCH] Issue 3257: Add format field to CodegenParameter and CodegenProperty. Add format to static html template. --- .../src/main/java/io/swagger/codegen/CodegenParameter.java | 6 +++++- .../src/main/java/io/swagger/codegen/CodegenProperty.java | 6 +++++- .../src/main/java/io/swagger/codegen/DefaultCodegen.java | 2 ++ .../src/main/resources/htmlDocs/formParam.mustache | 2 +- .../src/main/resources/htmlDocs/headerParam.mustache | 2 +- .../src/main/resources/htmlDocs/index.mustache | 2 +- .../src/main/resources/htmlDocs/pathParam.mustache | 2 +- .../src/main/resources/htmlDocs/queryParam.mustache | 2 +- 8 files changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index a69f719718..289fd60c2c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -9,7 +9,7 @@ public class CodegenParameter { public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, hasMore, isContainer, secondaryParam, isCollectionFormatMulti, isPrimitiveType; - public String baseName, paramName, dataType, datatypeWithEnum, collectionFormat, description, unescapedDescription, baseType, defaultValue; + public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue; public String example; // example value (x-example) public String jsonSchema; public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; @@ -85,6 +85,7 @@ public class CodegenParameter { output.paramName = this.paramName; output.dataType = this.dataType; output.datatypeWithEnum = this.datatypeWithEnum; + output.dataFormat = this.dataFormat; output.collectionFormat = this.collectionFormat; output.isCollectionFormatMulti = this.isCollectionFormatMulti; output.description = this.description; @@ -181,6 +182,8 @@ public class CodegenParameter { return false; if (datatypeWithEnum != null ? !datatypeWithEnum.equals(that.datatypeWithEnum) : that.datatypeWithEnum != null) return false; + if (dataFormat != null ? !dataFormat.equals(that.dataFormat) : that.dataFormat != null) + return false; if (collectionFormat != null ? !collectionFormat.equals(that.collectionFormat) : that.collectionFormat != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) @@ -276,6 +279,7 @@ public class CodegenParameter { result = 31 * result + (paramName != null ? paramName.hashCode() : 0); result = 31 * result + (dataType != null ? dataType.hashCode() : 0); result = 31 * result + (datatypeWithEnum != null ? datatypeWithEnum.hashCode() : 0); + result = 31 * result + (dataFormat != null ? dataFormat.hashCode() : 0); result = 31 * result + (collectionFormat != null ? collectionFormat.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (unescapedDescription != null ? unescapedDescription.hashCode() : 0); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index 8f6f716152..7462094acc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -6,7 +6,7 @@ import java.util.Objects; public class CodegenProperty implements Cloneable { public String baseName, complexType, getter, setter, description, datatype, datatypeWithEnum, - name, min, max, defaultValue, defaultValueWithParam, baseType, containerType; + dataFormat, name, min, max, defaultValue, defaultValueWithParam, baseType, containerType; public String unescapedDescription; @@ -66,6 +66,7 @@ public class CodegenProperty implements Cloneable { result = prime * result + ((containerType == null) ? 0 : containerType.hashCode()); result = prime * result + ((datatype == null) ? 0 : datatype.hashCode()); result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode()); + result = prime * result + ((dataFormat == null) ? 0 : dataFormat.hashCode()); result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode()); result = prime * result + ((defaultValueWithParam == null) ? 0 : defaultValueWithParam.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); @@ -143,6 +144,9 @@ public class CodegenProperty implements Cloneable { if ((this.datatypeWithEnum == null) ? (other.datatypeWithEnum != null) : !this.datatypeWithEnum.equals(other.datatypeWithEnum)) { return false; } + if ((this.dataFormat == null) ? (other.dataFormat != null) : !this.dataFormat.equals(other.dataFormat)) { + return false; + } if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { return false; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index d2bb3aed87..786119b49f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1543,6 +1543,7 @@ public class DefaultCodegen { } } property.datatype = getTypeDeclaration(p); + property.dataFormat = p.getFormat(); // this can cause issues for clients which don't support enums if (property.isEnum) { @@ -2143,6 +2144,7 @@ public class DefaultCodegen { setParameterBooleanFlagWithCodegenProperty(p, cp); p.dataType = cp.datatype; + p.dataFormat = cp.dataFormat; if(cp.isEnum) { p.datatypeWithEnum = cp.datatypeWithEnum; } diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs/formParam.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs/formParam.mustache index 33b4610141..5f8392f34e 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs/formParam.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs/formParam.mustache @@ -1,3 +1,3 @@ {{#isFormParam}}
{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}
-
Form Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}
{{/isFormParam}} \ No newline at end of file +
Form Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}
{{/isFormParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs/headerParam.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs/headerParam.mustache index f5390e7aea..bd18f9e15c 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs/headerParam.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs/headerParam.mustache @@ -1,3 +1,3 @@ {{#isHeaderParam}}
{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}
-
Header Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}
{{/isHeaderParam}} \ No newline at end of file +
Header Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}
{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs/index.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs/index.mustache index 4f2519fbef..b94414d5b2 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs/index.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs/index.mustache @@ -164,7 +164,7 @@

{{name}} Up

- {{#vars}}
{{name}} {{^required}}(optional){{/required}}
{{^isPrimitiveType}}{{datatype}}{{/isPrimitiveType}} {{description}}
+ {{#vars}}
{{name}} {{^required}}(optional){{/required}}
{{^isPrimitiveType}}{{datatype}}{{/isPrimitiveType}} {{description}} {{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}
{{#isEnum}}
Enum:
{{#_enum}}
{{this}}
{{/_enum}} diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs/pathParam.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs/pathParam.mustache index b3590871cf..a198c1765b 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs/pathParam.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs/pathParam.mustache @@ -1,3 +1,3 @@ {{#isPathParam}}
{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}
-
Path Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}
{{/isPathParam}} \ No newline at end of file +
Path Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}
{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs/queryParam.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs/queryParam.mustache index 27f02a23d8..b5599b3469 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs/queryParam.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs/queryParam.mustache @@ -1,3 +1,3 @@ {{#isQueryParam}}
{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}
-
Query Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}
{{/isQueryParam}} \ No newline at end of file +
Query Parameter — {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}
{{/isQueryParam}} \ No newline at end of file