2.添加配置org.springframework.plugin spring-plugin-core2.0.0.RELEASE org.springframework.plugin spring-plugin-metadata2.0.0.RELEASE io.springfox springfox-boot-starter3.0.0 org.springframework.plugin spring-plugin-coreorg.springframework.plugin spring-plugin-metadatacom.github.xiaoymin knife4j-spring-boot-starter3.0.2
application.yaml文件中添加如下
springfox: documentation: swagger-ui: enabled: true
添加一个配置类
package com.hhmt.delivery.config; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import io.swagger.v3.oas.annotations.Operation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import springfox.documentation.builders.*; import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.schema.ScalarType; import springfox.documentation.service.*; import springfox.documentation.spi.documentationType; import springfox.documentation.spring.web.plugins.Docket; import java.util.ArrayList; import java.util.List; @EnableKnife4j @Configuration @EnableOpenApi public class Swagger3Config { @Bean public Docket createRestApi() { //返回文档概要信息 return new Docket(documentationType.OAS_30) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class)) .paths(PathSelectors.any()) .build() .globalRequestParameters(getGlobalRequestParameters()) .globalResponses(HttpMethod.GET, getGlobalResponseMessage()) .globalResponses(HttpMethod.POST, getGlobalResponseMessage()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("辉煌明天第三方接入文档") .description("如有疑问,可联系") .contact(new Contact("华春", "https://hhmt-co.yoqu.net/version", "huachun_w@163.com")) .version("1.0") .build(); } private List3.添加注解getGlobalRequestParameters() { List parameters = new ArrayList<>(); parameters.add(new RequestParameterBuilder() .name("MediaDto") .description("请求数据") .required(true) .in(ParameterType.QUERY) .query(q -> q.model(m -> m.scalarModel((ScalarType.STRING)))) .required(false) .build()); return parameters; } private List getGlobalResponseMessage() { List responseList = new ArrayList<>(); responseList.add(new ResponseBuilder().code("404").description("未找到资源").build()); return responseList; } }
package com.hhmt.delivery.controller; import com.hhmt.delivery.ocpx.bean.MediaDto; import com.hhmt.delivery.ocpx.bean.ResultVo; import com.hhmt.delivery.ocpx.service.common.MediaCommonService; import com.hhmt.delivery.utils.CheckParamsUtils; import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Api(tags = "第三方媒体接入接口", value = "该参数没什么意义") @RestController(value = "第三方接入") @RequestMapping(value = "/cpa", name = "媒体公共调用控制器") public class OcpxCommonController { @Autowired private CheckParamsUtils checkParamsUtils; @Autowired private MediaCommonService mediaCommonService; @Operation(summary = "第三方上报入口") @PostMapping(value = "/media", name = "媒体上报") public ResultVo media(@Parameter(description = "媒体请求数据") @RequestBody MediaDto mediaDto) { checkParamsUtils.checkMediaInfo(mediaDto); return mediaCommonService.reportCustomer(mediaDto); } }4.访问测试
http://localhost:9527/swagger-ui/index.html
待完善...
原文参考:https://blog.csdn.net/qq_22075913/article/details/117038037
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)