0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【学習】API設計のリクエスト項目、Requiredの実装における警告波線解消したい

Posted at

はじめに

SpringFrameworkを用いたプロジェクトであるコードを書いていたら警告の波線が表示されました。
APIの設計でリクエストの項目の中にRequiredが必須ものもがあったのですが。コードを書く際には少し注意しないといけないようです。

今回はどんなコードだと警告となり、どうすれば警告表示がなくなるのかを簡単に記事にできればと思います。

対象者

  • Swaggerのバージョンが2.0以上(比較的新しいバージョンを使用する場合に警告がでるのかもしれません)
  • 必須項目を設定した時に警告の波線表示をどうにかしたい人

どういったコードで警告波線だったのか?

@Schema(description = "", required = true)

上記のなかのrequired = trueに警告波線の表示。
バージョンにもよりますが、私は「2.8.4」のSwaggerを使用していて、警告の波線が表示されました。
上記ページを参照にコードを修正。

どうすれば警告波線がきえたのか?

先程のrequired = trueこの部分を下記コードに置き換える事で警告波線が消えました!

requiredMode = Schema.RequiredMode.REQUIRED

 
↓ついでに

// 必須ではない」と明示したい場合
requiredMode = Schema.RequiredMode.NOT_REQUIRED

// ライブラリに判断させたい場合
requiredMode = Schema.RequiredMode.AUTOデフォルト

参考

おまけ:一括置換の方法

修正箇所が沢山あったので、便利な方法がないか探したら下記ショートカットキーがありました。
macOS: ⌘ + Shift + R
Windows/Linux: Ctrl + Shift + R(Replace in Path)
開いた画面から一括置換ができる!便利

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?