Skip to content

Commit 9164b28

Browse files
Arnaud-Nauwynckciis0
authored andcommitted
when header 'Content-Type: application/json'and returnType=string => still use angular json parse (unwrapping quote and un-escaping)
1 parent 72cf05a commit 9164b28

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,9 @@ public CodegenOperation fromOperation(String path,
23122312
if (Boolean.TRUE.equals(r.isFile) && Boolean.TRUE.equals(r.isDefault)){
23132313
op.isResponseFile = Boolean.TRUE;
23142314
}
2315-
if (Boolean.TRUE.equals(r.isString) && Boolean.TRUE.equals(r.isDefault)){
2315+
if (Boolean.TRUE.equals(r.isString)
2316+
&& operation.getProduces().contains("plain/text") // otherwise if "application/json" => wrap text with "..", and escape
2317+
&& Boolean.TRUE.equals(r.isDefault)){
23162318
op.isResponseText = Boolean.TRUE;
23172319
}
23182320
}

modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class {{classname}} {
314314

315315
{{/hasFormParams}}
316316
{{#useHttpClient}}
317-
return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}}
317+
return this.httpClient.{{httpMethod}}{{#isResponseText}}/*{{/isResponseText}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}{{#isResponseText}}*/{{/isResponseText}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}}
318318
{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}}
319319
{
320320
{{#hasQueryParams}}
@@ -324,7 +324,7 @@ export class {{classname}} {
324324
responseType: "blob",
325325
{{/isResponseFile}}
326326
{{#isResponseText}}
327-
responseType: "text",
327+
responseType: 'text',
328328
{{/isResponseText}}
329329
withCredentials: this.configuration.withCredentials,
330330
headers: headers,

0 commit comments

Comments
 (0)