OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-angular] [5.4.0] - Wrong default response type 'blob' instead of JSON (OpenAPI model schema)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
OpenAPI-Generator-maven-plugin
Description
Generating a typescript-angular client with OpenAPI-Generator-maven-plugin 5.4.0
has wrong default response type 'blob' instead of the OpenAPI model schema.
- let responseType_: 'text' | 'json' = 'json';
- if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
- responseType_ = 'text';
+ let responseType_: 'text' | 'json' | 'blob' = 'json';
+ if (localVarHttpHeaderAcceptSelected) {
+ if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
+ responseType_ = 'text';
+ } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
+ responseType_ = 'json';
+ } else {
+ responseType_ = 'blob';
+ }
}
Printing the response gives:
Blob
size: 161
type: "application/json"
[[Prototype]]: Blob
arrayBuffer: ƒ arrayBuffer()
size: (...)
slice: ƒ slice()
stream: ƒ stream()
text: ƒ text()
type: (...)
constructor: ƒ Blob()
Symbol(Symbol.toStringTag): "Blob"
get size: ƒ size()
get type: ƒ type()
[[Prototype]]: Object
instead of the actual object defined in the schemas.
openapi-generator version
5.4.0
OpenAPI declaration file content or url
responses:
"200":
description: OK
content:
*/*:
instead of
responses:
"200":
description: OK
content:
application/json:
Generation Details
This is my pom.xml plugin config:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<id>angular</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>false</skip>
<skipIfSpecIsUnchanged>false</skipIfSpecIsUnchanged>
<inputSpec>${project.basedir}/src/main/resources/api/API.yaml</inputSpec>
<output>${project.basedir}/src/main/resources/api-client/ng-client</output>
<generatorName>typescript-angular</generatorName>
<configOptions>
<npmName>@project/api-client</npmName>
<npmVersion>1.0.0</npmVersion>
<ngVersion>12.2.15</ngVersion>
<apiModulePrefix>Project</apiModulePrefix>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Related issues/PRs
Suggest a fix
The fix required the setting of this external application property, of SpringDoc, for generating the OpenApi yaml:
springdoc:
default-produces-media-type: application/json
to override the default, which is
springdoc:
default-produces-media-type: */*
Maybe the generated client should continue to default to JSON as the default httpHeaderAccepts even if the response content is */*.
Otherwise, this behaviour needs to be documented.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated typescript-angular client’s responseType_ handling and the OpenAPI response content shown in the report, using the Maven plugin configuration to reproduce it. Compare behavior for / and application/json; done means JSON model responses are handled as intended, or the required behavior is clearly documented, with a regression check added if the project’s test entry point is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100