swagger-api / swagger-api/swagger-codegen
[Spring] Query params using content: generate invalid code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Using content instead of schema for query param generates code omitting the parameter & type of the query param in the Spring controller.
See schema versus content in https://swagger.io/docs/specification/describing-parameters/#query-parameters
The swagger definition below generates the following list() operation. The parameter annotations are there but no parameter name or type.
public ResponseEntity<String> list(@ApiParam(value = "") @Valid @RequestParam(value = "filter", required = false) ) {
String accept = request.getHeader("Accept");
return new ResponseEntity<String>(HttpStatus.NOT_IMPLEMENTED);
}
Swagger-codegen version
3.0.8
Swagger declaration file content or url
openapi: 3.0.1
info:
title: query param content
version: 1.0
paths:
/test:
get:
operationId: list
parameters:
# See schema versus content. https://swagger.io/docs/specification/describing-parameters/#query-parameters
- in: query
name: filter
# Wrap 'schema' into 'content.<media-type>'
content:
application/json: # <---- media type indicates how to serialize / deserialize the parameter content
schema:
type: object
properties:
type:
type: string
color:
type: string
responses:
200:
description: successful operation
content:
application/json:
schema:
type: string
Command line used for generation
swagger-codegen generate -i query-param-content.yaml -o output --lang spring
Steps to reproduce
Save swagger above in query-param-content.yaml and run the codegen line above.
Related issues/PRs
Suggest a fix/enhancement
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
Reproduce the issue with query-param-content.yaml and the documented swagger-codegen generate command using --lang spring. Start at the Spring generator entry point and its templates, then verify that the generated list() operation includes the query parameter's name and type instead of an incomplete declaration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100