OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA/TYPESCRIPT] Invalid consumes headers generated
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When image/* is specified for requestBody content type, the generated spring server and typescript client (probably others as well) end up invalid.
On spring side:
@RequestMapping(
method = RequestMethod.POST,
value = "/v1",
consumes = { "image/_*" }
)
On typescript side:
// to determine the Content-Type header
const consumes: string[] = [
'image/_*'
];
openapi-generator version
5.2.1
OpenAPI declaration file content or url
{
"paths": {
"/v1": {
"post": {
"summary": "uploadImage",
"operationId": "uploadImage",
"requestBody": {
"content": {
"image/*": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
Generation Details
Generator names were "spring" and "typescript-angular".
Suggest a fix
Tweak DefaultCodegen.addConsumesInfo.
Issue is with this line:
mediaType.put("mediaType", escapeText(escapeQuotationMark(key)));
The method escapeText is explicitly breaking /* and */.
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 DefaultCodegen.addConsumesInfo and reproduce the issue using the provided OpenAPI declaration with the spring and typescript-angular generators. Check how the media type is escaped, then verify that generated consumes headers preserve image/* rather than producing image/_*.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, java, openapi, spring, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100