[Spring]: RequestBody required-handling
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java, openapi, spring
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Mustache
- スター
- 299
- フォーク
- 439
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
swagger-api/swagger-codegen-generators のほかの issue
-
[Bug]: Python/pythonFlaskConnexion generators validate map keys instead of values for additionalProperties.enum対応中かも @pvillard31 が 190 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
Python generated code: Delete API Requests can be blocked in API Gateways when sends empty bodyオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
[Bug]: Bean validation doesn't work for numbers larger than Integer.MAX_VALUE対応中かも @apupier が 278 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
swagger-api/swagger-codegen-generators#1370 · コメント 3 件 · リアクション 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
swagger-api/swagger-codegen-generators の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aristocratos/btop#1945 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
boykopovar/AnyPS5#11291 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
stac-utils/stac-fastapi-elasticsearch-opensearch#965 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
Automattic/blocks-engine#3438 ·
メンテナーはふだん 1 日以内に返信
-
bug help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Tencent/teamai-cli#1397 ·
メンテナーはふだん 1 日以内に返信