Merge pull request #3260 from gokl/format-field

Issue 3257: Add format field to CodegenParameter and CodegenProperty.…
This commit is contained in:
wing328 2016-07-01 14:05:06 +08:00 committed by GitHub
commit 021f554a6b
8 changed files with 17 additions and 7 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,3 +1,3 @@
{{#isFormParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isFormParam}}

View File

@ -1,3 +1,3 @@
{{#isHeaderParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isHeaderParam}}

View File

@ -164,7 +164,7 @@
<div class="model">
<h3 class="field-label"><a name="{{name}}">{{name}}</a> <a class="up" href="#__Models">Up</a></h3>
<div class="field-items">
{{#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>
{{#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>
{{#isEnum}}
<div class="param-enum-header">Enum:</div>
{{#_enum}}<div class="param-enum">{{this}}</div>{{/_enum}}

View File

@ -1,3 +1,3 @@
{{#isPathParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isPathParam}}

View File

@ -1,3 +1,3 @@
{{#isQueryParam}}<div class="param">{{baseName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}} {{/defaultValue}}{{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>{{/isQueryParam}}