0

在 Rest API 中使用版本 API。我想使用 Micronaut open-api 进行多重招摇定义

我有以下代码结构

在此处输入图像描述

版本 1

@Controller("/${api.version:v1}")
@Tag(name = "Version1", description = "Version 2 api")
@Version("1")
public class Version1Controller {
    @Operation(operationId = "findFreeSearchText",
            description = "Find project based on the free text search.",
            summary = "Find all products based on the free searched text",
            responses = {
                    @ApiResponse(responseCode = "200", description = "List of products",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = String.class))),
                    @ApiResponse(responseCode = "400", description = "invalid or missing parameters"),
                    @ApiResponse(responseCode = "404", description = "Not found"),
                    @ApiResponse(responseCode = "401", description = "if not authenticated as admin")
            })
    @Get("/")
    String freeTextSearch(@NotBlank String text) {
        return "Hello version 2";
    }
}

版本 2

@Controller("/${api.version:v2}")
@Tag(name = "Version2", description = "Version 2 api")
@Version("2")
public class Version2Controller {
    @Operation(operationId = "findFreeSearchText",
            description = "Find project based on the free text search.",
            summary = "Find all products based on the free searched text",
            responses = {
                    @ApiResponse(responseCode = "200", description = "List of products",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = String.class))),
                    @ApiResponse(responseCode = "400", description = "invalid or missing parameters"),
                    @ApiResponse(responseCode = "404", description = "Not found"),
                    @ApiResponse(responseCode = "401", description = "if not authenticated as admin")
            })
    @Get("/")
    String freeTextSearch(@NotBlank String text) {
        return "Hello version 1";
    }
}

这会生成招摇文档

在此处输入图像描述

右上角应该有一个下拉菜单,我可以在其中选择代码的版本

4

0 回答 0