1

Spring Data REST API を OpenAPI で文書化することに失敗しています。swagger-ui のホームページ (および明らかに /v3/api-docs ) には何も表示されません。

これが私の依存関係からの抜粋です:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-data-rest</artifactId>
        <version>1.6.4</version>
    </dependency>

そして、私のJPAリポジトリがあります:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonsRepository extends JpaRepository<Person, Long> {
Person findByLastname(@Param("name") @RequestParam("name") String lastname);
}

そして、これは私のSpring Bootのセットアップです:

spring.datasource.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false
spring.jpa.defer-datasource-initialization=true
spring.jpa.open-in-view=false
management.endpoints.web.exposure.include=*
springdoc.swagger-ui.operationsSorter=method
#springdoc.paths-to-match=/people/**

もちろん、私の CRUD API は /people PATH で問題ありません。/profile/people PATH でさえ正しいようです。

私は何かが欠けている必要があります...助けてくれてありがとう。

4

1 に答える 1

0

この URL を試す必要があることを願っています。

http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config#

マイ構成

また、OpenAPI Bean を作成しました

 @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components())
                .info(new Info().title("Test")
                        .description("Test Description")
                        .version("1.0.0"));
    }

RestController API エンドポイント メソッドの上に、次の注釈を追加しました。

 @Operation(summary = "Send Messages to Ibm Mq", description = "Send Message to the related ibm mq")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Success Response",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json")),
            @ApiResponse(responseCode = "500", description = "Internal System Error",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json")),
            @ApiResponse(responseCode = "400", description = "Invalid Parameter Request",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json"))
    })

すべてのインポートは io.swagger.v3.oas.annotations パッケージからのものでした

于 2022-01-21T03:30:06.617 に答える