Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class CodegenParameter implements IJsonSchemaValidationProperties {
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
isCookieParam, isBodyParam, hasMore, isContainer,
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode;
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, jsonEncoding;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In OAI 3.0, encoding can be specified besides application/json, so this method seems to have low extensibility.
This change will affect the entire openapi-generator and will require a maintainers review.

cc. @wing328 @jimschubert

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. If you need custom logic, I think a vendor extension would be more appropriate.

Copy link
Copy Markdown
Author

@milesressler milesressler Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure I follow - from what I read about vendor extensions on the docs, they are meant for functionality that is not covered by the standard OpenAPI Specification . This isn't custom logic, this is functionality that is part of the OAI specification, and is currently ignored by the OAI generator.

I do agree that other encoding types can be specified and should be supported as well, but since the objects already include a ToJson(), it seemed like an easy win for those that need it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milesressler please follow isJson approach in Dart client generator:

Let me know if you need help. You can PM me via Slack (mentioned in the readme)

public String baseName, paramName, dataType, datatypeWithEnum, dataFormat,
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style;

Expand Down Expand Up @@ -96,6 +96,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
public CodegenParameter copy() {
CodegenParameter output = new CodegenParameter();
output.isFile = this.isFile;
output.jsonEncoding = this.jsonEncoding;
output.hasMore = this.hasMore;
output.isContainer = this.isContainer;
output.secondaryParam = this.secondaryParam;
Expand Down Expand Up @@ -183,7 +184,7 @@ public CodegenParameter copy() {

@Override
public int hashCode() {
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, hasMore, isContainer, secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isListContainer, isMapContainer, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), multipleOf);
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, hasMore, isContainer, secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, jsonEncoding, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isListContainer, isMapContainer, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), multipleOf);
}

@Override
Expand Down Expand Up @@ -227,6 +228,7 @@ public boolean equals(Object o) {
hasValidation == that.hasValidation &&
isNullable == that.isNullable &&
required == that.required &&
jsonEncoding == that.jsonEncoding &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getUniqueItems() == that.getUniqueItems() &&
Expand Down Expand Up @@ -310,6 +312,7 @@ public String toString() {
sb.append(", isListContainer=").append(isListContainer);
sb.append(", isMapContainer=").append(isMapContainer);
sb.append(", isFile=").append(isFile);
sb.append(", jsonEncoding=").append(jsonEncoding);
sb.append(", isEnum=").append(isEnum);
sb.append(", _enum=").append(_enum);
sb.append(", allowableValues=").append(allowableValues);
Expand Down Expand Up @@ -465,6 +468,5 @@ public Number getMultipleOf() {
public void setMultipleOf(Number multipleOf) {
this.multipleOf = multipleOf;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4917,6 +4917,15 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
Content c = body.getContent();
String contentType = getContentType(body);
Map<String, Encoding> parameterEncoding = null;
if (c != null && contentType != null) {
MediaType mediaType = c.get(contentType);
if (mediaType != null) {
parameterEncoding = mediaType.getEncoding();
}
}
if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
Map<String, Schema> properties = schema.getProperties();
for (Map.Entry<String, Schema> entry : properties.entrySet()) {
Expand Down Expand Up @@ -4974,6 +4983,13 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
codegenParameter.required = schema.getRequired().contains(entry.getKey());
}

if (parameterEncoding != null && parameterEncoding.containsKey(entry.getKey())) {
String overrideContentType = parameterEncoding.getOrDefault(entry.getKey(), new Encoding()).getContentType();
if (overrideContentType != null) {
codegenParameter.jsonEncoding = overrideContentType.toLowerCase(Locale.ENGLISH).trim().equals("application/json");
}
}

parameters.add(codegenParameter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace {{packageName}}.{{apiPackage}}
if ({{paramName}} != null) localVarHeaderParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToString({{paramName}})); // header parameter
{{/headerParams}}
{{#formParams}}
if ({{paramName}} != null) {{#isFile}}localVarFileParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}localVarFormParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
if ({{paramName}} != null) {{#isFile}}localVarFileParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}localVarFormParams.Add("{{baseName}}", {{#jsonEncoding}}{{paramName}}.ToJson(){{/jsonEncoding}}{{^jsonEncoding}}this.Configuration.ApiClient.ParameterToString({{paramName}}){{/jsonEncoding}}); // form parameter{{/isFile}}
{{/formParams}}
{{#bodyParam}}
if ({{paramName}} != null && {{paramName}}.GetType() != typeof(byte[]))
Expand Down Expand Up @@ -384,7 +384,7 @@ namespace {{packageName}}.{{apiPackage}}
if ({{paramName}} != null) localVarHeaderParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToString({{paramName}})); // header parameter
{{/headerParams}}
{{#formParams}}
if ({{paramName}} != null) {{#isFile}}localVarFileParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}localVarFormParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
if ({{paramName}} != null) {{#isFile}}localVarFileParams.Add("{{baseName}}", this.Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}localVarFormParams.Add("{{baseName}}", {{#jsonEncoding}}{{paramName}}.ToJson(){{/jsonEncoding}}{{^jsonEncoding}}this.Configuration.ApiClient.ParameterToString({{paramName}}){{/jsonEncoding}}); // form parameter{{/isFile}}
{{/formParams}}
{{#bodyParam}}
if ({{paramName}} != null && {{paramName}}.GetType() != typeof(byte[]))
Expand Down