swagger-api / swagger-api/swagger-codegen
Unwanted "result" Value in @RequestMapping `produces` Attribute Generated by OpenAPI Generator
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using the OpenAPI Generator plugin for server stub generation based on a Swagger 2.0 specification. I’ve encountered an issue where the generated code contains an unwanted "result" value in the produces attribute of the @RequestMapping annotation in the Spring Boot server stub.
Issue:
In the generated code, I have the following @RequestMapping annotation:
@RequestMapping(
method = RequestMethod.POST,
value = "/users",
produces = { "application/json", "result" },
consumes = { "application/json" }
)
As you can see, the produces attribute includes "result" as a media type, which should not be there. The produces attribute is intended to specify valid media types (like "application/json", "application/xml", etc.), but "result" seems to have been mistakenly added.
Example Swagger Spec (relevant part):
responses:
200:
description: Successful response
schema:
type: object
properties:
result:
type: object
properties:
someData:
type: string
What I've Tried:
- Reviewed the Swagger Spec: I've checked my Swagger 2.0 spec, and there's no reason for
"result"to be in theproducesfield. The spec only defines response data, not media types like"result". - Checked the Generated Code: The
producesfield in the generated@RequestMappingannotation is incorrectly including"result". - Looked at the OpenAPI Generator Templates: I haven’t customized the templates yet, but I’m wondering if this might be necessary.
My Question:
- Why is OpenAPI Generator adding
"result"as a value in theproducesattribute of the@RequestMappingannotation? Could it be related to the way the response body is defined in the Swagger 2.0 spec? - How can I fix this issue so that only the correct media types (like
"application/json") appear in theproducesfield, and"result"is not added? - Should I customize the OpenAPI Generator templates to prevent this from happening, and if so, how would I do that?
Any guidance or solutions would be greatly appreciated!
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 Spring Boot server templates and the Swagger 2.0 response-schema handling that generates the @RequestMapping produces values. Reproduce the shown schema, then trace why the response property name "result" becomes a media type. Done means generated annotations retain valid media types such as "application/json" without "result".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100