2

Springdoc は、すべてのハンドラー メソッドの API ドキュメントを自動的に生成します。OpenAPI アノテーションがなくても。

API ドキュメントからエンドポイントを非表示にするにはどうすればよいですか?

4

2 に答える 2

8

注釈は、コントローラーの@io.swagger.v3.oas.annotations.Hiddenメソッドまたはクラス レベルで使用して、1 つまたはすべてのエンドポイントを非表示にすることができます。

(参照: https://springdoc.org/faq.html#how-can-i-hide-an-operation-or-a-controller-from-documentation )

例:

@Hidden // Hide all endpoints
@RestController
@RequestMapping(path = "/test")
public class TestController {

    private String test = "Test";

    @Operation(summary = "Get test string", description = "Returns a test string", tags = { "test" })
    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success" ) })
    @GetMapping(value = "", produces = MediaType.TEXT_PLAIN_VALUE)
    public @ResponseBody String getTest() {
        return test;
    }

    @Hidden // Hide this endpoint
    @PutMapping(value = "", consumes = MediaType.TEXT_PLAIN_VALUE)
    @ResponseStatus(HttpStatus.OK)
    public void setTest(@RequestBody String test) {
        this.test = test;
    }

}

編集:

特定のパッケージのコントローラーのみの API ドキュメントを生成することもできます。

application.properties以下をファイルに追加します。

springdoc.packagesToScan=package1, package2

(参照: https://springdoc.org/faq.html#how-can-i-explicitly-set-which-packages-to-scan )

于 2020-05-30T12:12:50.163 に答える