springboot 3.0 正确的使用swagger

2023-01-23  本文已影响0人  不知不怪

其实用的是springdoc-openapi
只要加入依赖

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
1674558071277.png

为了一个在线文档用了这么多依赖,不太划算,生产环境关了吧
配置 不是必须的也可以不写 只要加入依赖就可以了

package com.gzz.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI springOpenAPI() {
        return new OpenAPI().info(new Info() //
                .title("SpringDoc API Test") //
                .description("SpringDoc Simple Application Test") //
                .version("0.0.1"));
    }

}

就完事儿了,其它的就跟你用过的swagger一样儿了
http://localhost:8080/swagger-ui/index.html

1674557807847.png

从SpringFox迁移

SpringFox SpringDoc
@Api @Tag
@ApiIgnore @Parameter(hidden = true)or@Operation(hidden = true)or@Hidden
@ApiImplicitParam @Parameter
@ApiImplicitParams @Parameters
@ApiModel @Schema
@ApiModelProperty @Schema
@ApiOperation(value = "foo", notes = "bar") @Operation(summary = "foo", description = "bar")
@ApiParam @Parameter
@ApiResponse(code = 404, message = "foo") ApiResponse(responseCode = "404", description = "foo")
上一篇下一篇

猜你喜欢

热点阅读