swagger(一)项目中的swagger配置

目录

一.引入依赖;

二.配置swagger

三.界面展示

四:使用swagger注解

五.例子

六.注意:

七:后期需要,再贴出其他相关配置

一.引入依赖;

 <!-- 引入swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

二.配置swagger


@Configuration
@EnableSwagger2
public class Swagger2Config {


    /**
     * 创建swagger对象:
     *
     * @return
     */
    @Bean
    public Docket mapRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("地图坐标转化APIs")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.example.microservice.http.controller.server.map"))
                .paths(PathSelectors.any())
                .build();
    }


    /**
     * 设置api信息
     * title:swagger题目
     * description:描述
     * cotact:创建者
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("微服务API")
                .description("springboot框架小服务")
                .contact(new Contact("yourname",null ,"xxx@qq.com"))
                .version("1.0")
                .build();
    }


}

groupName:当出现多个服务时候,可以用来进行分组

三.界面展示

四:使用swagger注解

 @API

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ABP配置Swagger,可以按照以下步骤进行操作: 1. 在Startup的ConfigureServices方法添加以下代码: ```csharp services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); }); ``` 这段代码会添加Swagger生成器,并指定API的标题和版本。 2. 如果你的项目有XML注释文件,可以将其包含在Swagger文档。在Startup的ConfigureServices方法添加以下代码: ```csharp var xmlFile = @"XXX.Application.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath, true); ``` 这段代码会将XML注释文件包含在Swagger文档,以便生成API文档时能够显示注释内容。 3. 如果你想对Swagger文档进行更多的配置,可以在Startup的ConfigureServices方法使用options对象进行配置。例如,你可以添加全局的请求过滤器、授权认证等。以下是一个示例: ```csharp services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); // 添加全局的请求过滤器 options.OperationFilter<FileUploadOperation>(); // 添加授权认证 options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme", Type = SecuritySchemeType.Http, Scheme = "bearer" }); options.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] {} } }); }); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值