Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON stringify for query parameters #1220

Merged
merged 3 commits into from
Dec 12, 2023
Merged
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 @@ -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
Loading