Skip to content

Commit

Permalink
Merge pull request #1229 from swagger-api/luca-vercelli-issue-1173
Browse files Browse the repository at this point in the history
Luca vercelli issue 1173
  • Loading branch information
HugoMario authored Dec 12, 2023
2 parents b66bdf0 + de04ca9 commit a892f5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2517,6 +2517,8 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataFormat = codegenProperty.dataFormat;

setParameterJson(codegenParameter, parameterSchema);

if (getBooleanValue(codegenProperty, IS_ENUM_EXT_NAME)) {
codegenParameter.datatypeWithEnum = codegenProperty.datatypeWithEnum;
codegenParameter.enumName = codegenProperty.enumName;
Expand Down Expand Up @@ -4407,6 +4409,14 @@ protected void setParameterNullable(CodegenParameter parameter, CodegenProperty
parameter.nullable = property.nullable;
}

protected void setParameterJson(CodegenParameter codegenParameter, Schema parameterSchema) {
String contentType = parameterSchema.getExtensions() == null ? null : (String) parameterSchema.getExtensions().get("x-content-type");
if (contentType != null && contentType.startsWith("application/") && contentType.endsWith("json")) {
// application/json, application/problem+json, application/ld+json, some more?
codegenParameter.isJson = true;
}
}

protected boolean isFileTypeSchema(Schema schema) {
final Schema fileTypeSchema;
if (StringUtils.isNotBlank(schema.get$ref())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ export class {{classname}} {
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
{{/isDateTime}}
{{^isDateTime}}
{{#isJson}}
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', JSON.stringify({{paramName}}));
{{/isJson}}
{{^isJson}}
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', <any>{{paramName}});
{{/isJson}}
{{/isDateTime}}
}
{{/isListContainer}}
Expand Down

0 comments on commit a892f5e

Please sign in to comment.