[Spring]: RequestBody required-handling
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 62/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- java, openapi, spring
- Área
- backend-api-design
Línea de trabajo
The bug is that the spring generator ignores requestBody.required: false and always emits @RequestBody with its default required=true. Start in the Spring server templates and find where the @RequestBody annotation is written for request bodies. Make it pass required from the spec, then check that a POST to /search with no body and no query parameter is accepted. Done when the generated controller compiles and both curl cases from the issue succeed.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
My goal is to have an endpoint to enable a quick search and an extended search. Using the quick search the endpoint only needs a query-param. Using the extended search a full search-body is required.
I was defining my openapi as follows:
/search:
post:
requestBody:
required: false
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchCriterion"
parameters:
- in: query
name: value
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchResult"
I was expecting to be able to send curl requests like:
- curl -X POST
'http://localhost/search'
-H 'Content-Type: application/json'
-d '[{"type":"NAME","value":"Dummy"}]' - curl -i -X POST
'http://localhost/search?value=something'
-H 'Content-Type: application/json'
But only the first request returned any data. The second request only resulted in a 404.
After shortly analysing the problem I found that the required-property is not handed to the @RequestBody Spring annotation. As the annotation uses true as default for the required attribute, I need to hand the body for every request.
This behaviour should be altered to correctly pass the required-property to the code.
Version
We are using [email protected] (which uses [email protected]) but the current main is also not passing the required-property.
Language / Generator Affected
- spring (i haven't checked any other generators as this should be specific for this generator)
OpenAPI/Swagger Spec
/search:
post:
requestBody:
required: false
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchCriterion"
parameters:
- in: query
name: value
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchResult"
Environment
OS: Windows 11
Java Version: temurin-21.0.6+7.0.LTS
Build Tool: Maven
swagger-codegen-generators Version: 1.0.54
Checklist
- [/] I have searched the existing issues to avoid duplicates.
- [/] I have included a minimal reproducible spec or configuration.
- [/] I have clearly described the steps to reproduce the issue.
- [/] I have specified which generator or template is affected.
- Lenguaje dominante
- Mustache
- Estrellas
- 299
- Forks
- 439
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swagger-api/swagger-codegen-generators
-
[Bug]: Python/pythonFlaskConnexion generators validate map keys instead of values for additionalProperties.enumPosiblemente ocupada @pvillard31 la tomó hace 191 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
-
Python generated code: Delete API Requests can be blocked in API Gateways when sends empty bodyAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
[Bug]: Bean validation doesn't work for numbers larger than Integer.MAX_VALUEPosiblemente ocupada @apupier la tomó hace 279 días. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
swagger-api/swagger-codegen-generators#1370 · 3 comentarios · 1 reacción ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
Todos los issues de swagger-api/swagger-codegen-generators
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
FootprintAI/Containarium#3182 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
VictoriaMetrics/victorialogs-datasource#747 ·
Los mantenedores suelen responder en 1 día
-
good first issue hardware help wanted no-box serve
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día