From 541c271bf1e82f83522787a26d89e1acfddf6b75 Mon Sep 17 00:00:00 2001 From: baiyina Date: Fri, 26 Jul 2024 14:52:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BD=BF=E7=94=A8Knife4j=204.4=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用Knife4j 4.4代替接口文档 --- .../cim/client/config/SwaggerConfig.java | 75 ++++++++----------- .../client/controller/IndexController.java | 7 +- .../cim/client/vo/req/GoogleProtocolVO.java | 5 +- .../cim/client/vo/req/GroupReqVO.java | 5 +- .../cim/client/vo/req/P2PReqVO.java | 7 +- .../cim/client/vo/req/SendMsgReqVO.java | 5 +- .../cim/client/vo/req/StringReqVO.java | 3 +- .../src/main/resources/application.properties | 3 - cim-common/pom.xml | 5 ++ .../cim/common/req/BaseRequest.java | 6 +- .../cim/route/config/SwaggerConfig.java | 73 ++++++++---------- .../cim/route/controller/RouteController.java | 13 ++-- .../src/main/resources/application.properties | 2 - .../cim/server/config/SwaggerConfig.java | 73 ++++++++---------- .../server/controller/IndexController.java | 3 +- .../src/main/resources/application.properties | 2 - pom.xml | 6 ++ 17 files changed, 138 insertions(+), 155 deletions(-) diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java b/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java index 880cb3ef..c86725b4 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java @@ -1,42 +1,33 @@ -//package com.crossoverjie.cim.client.config; -// -//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import springfox.documentation.builders.ApiInfoBuilder; -//import springfox.documentation.builders.PathSelectors; -//import springfox.documentation.builders.RequestHandlerSelectors; -//import springfox.documentation.service.ApiInfo; -//import springfox.documentation.spi.DocumentationType; -//import springfox.documentation.spring.web.plugins.Docket; -//import springfox.documentation.swagger2.annotations.EnableSwagger2; -// -// -//@Configuration -//@EnableSwagger2 -///** 是否打开swagger **/ -//@ConditionalOnExpression("'${swagger.enable}' == 'true'") -//public class SwaggerConfig { -// -// -// @Bean -// public Docket createRestApi() { -// return new Docket(DocumentationType.SWAGGER_2) -// .apiInfo(apiInfo()) -// .select() -// .apis(RequestHandlerSelectors.basePackage("com.crossoverjie.netty.action.client.controller")) -// .paths(PathSelectors.any()) -// .build(); -// } -// -// private ApiInfo apiInfo() { -// return new ApiInfoBuilder() -// .title("sbc order api") -// .description("sbc order api") -// .termsOfServiceUrl("http://crossoverJie.top") -// .contact("crossoverJie") -// .version("1.0.0") -// .build(); -// } -// -//} \ No newline at end of file +package com.crossoverjie.cim.client.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI createRestApi() { + return new OpenAPI() + .info(apiInfo()); + } + + private Info apiInfo() { + return new Info() + .title("sbc order api") + .description("sbc order api") + .termsOfService("http://crossoverJie.top") + .contact(contact()) + .version("1.0.0"); + } + + private Contact contact () { + Contact contact = new Contact(); + contact.setName("crossoverJie"); + return contact; + } +} \ No newline at end of file diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/controller/IndexController.java b/cim-client/src/main/java/com/crossoverjie/cim/client/controller/IndexController.java index 4ebd8cde..a1c8c2fb 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/controller/IndexController.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/controller/IndexController.java @@ -10,6 +10,7 @@ import com.crossoverjie.cim.common.enums.StatusEnum; import com.crossoverjie.cim.common.res.BaseResponse; import com.crossoverjie.cim.common.res.NULLBody; +import io.swagger.v3.oas.annotations.Operation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -43,7 +44,7 @@ public class IndexController { * @param stringReqVO * @return */ -// @ApiOperation("客户端发送消息,字符串") + @Operation(summary = "客户端发送消息,字符串") @RequestMapping(value = "sendStringMsg", method = RequestMethod.POST) @ResponseBody public BaseResponse sendStringMsg(@RequestBody StringReqVO stringReqVO){ @@ -67,7 +68,7 @@ public BaseResponse sendStringMsg(@RequestBody StringReqVO stringReqVO * @param googleProtocolVO * @return */ -// @ApiOperation("向服务端发消息 Google ProtoBuf") + @Operation(summary = "向服务端发消息 Google ProtoBuf") @RequestMapping(value = "sendProtoBufMsg", method = RequestMethod.POST) @ResponseBody public BaseResponse sendProtoBufMsg(@RequestBody GoogleProtocolVO googleProtocolVO){ @@ -93,7 +94,7 @@ public BaseResponse sendProtoBufMsg(@RequestBody GoogleProtocolVO goog * @param sendMsgReqVO * @return */ -// @ApiOperation("群发消息") + @Operation(summary = "群发消息") @RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST) @ResponseBody public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws Exception { diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GoogleProtocolVO.java b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GoogleProtocolVO.java index 5d1cd1d8..a25a0afb 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GoogleProtocolVO.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GoogleProtocolVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -13,11 +14,11 @@ */ public class GoogleProtocolVO extends BaseRequest { @NotNull(message = "requestId 不能为空") -// @ApiModelProperty(required = true, value = "requestId", example = "123") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "requestId", example = "123") private Integer requestId ; @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; public String getMsg() { diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GroupReqVO.java b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GroupReqVO.java index f45651be..c9d2145e 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GroupReqVO.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/GroupReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,12 +15,12 @@ public class GroupReqVO extends BaseRequest { @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "消息发送者的 userId", example = "1545574049323") private Long userId ; @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; public GroupReqVO(Long userId, String msg) { diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/P2PReqVO.java b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/P2PReqVO.java index 6cfba9e2..7b66dc41 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/P2PReqVO.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/P2PReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,19 +15,19 @@ public class P2PReqVO extends BaseRequest { @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "消息发送者的 userId", example = "1545574049323") private Long userId ; @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "消息接收者的 userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "消息接收者的 userId", example = "1545574049323") private Long receiveUserId ; @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "msg", example = "hello") private String msg ; public P2PReqVO() { diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/SendMsgReqVO.java b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/SendMsgReqVO.java index a331f4dc..8fe4c8e1 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/SendMsgReqVO.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/SendMsgReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,11 +15,11 @@ public class SendMsgReqVO extends BaseRequest { @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "msg", example = "hello") private String msg ; @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "userId", example = "11") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "userId", example = "11") private Long userId ; public String getMsg() { diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/StringReqVO.java b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/StringReqVO.java index b1569f06..36cc491a 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/StringReqVO.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/vo/req/StringReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,7 +15,7 @@ public class StringReqVO extends BaseRequest { @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED , description = "msg", example = "hello") private String msg ; public String getMsg() { diff --git a/cim-client/src/main/resources/application.properties b/cim-client/src/main/resources/application.properties index b470ae10..911bdcbd 100644 --- a/cim-client/src/main/resources/application.properties +++ b/cim-client/src/main/resources/application.properties @@ -3,9 +3,6 @@ spring.application.name=cim-client # web port server.port=8082 -# enable swagger -swagger.enable = true - logging.level.root=error # log path diff --git a/cim-common/pom.xml b/cim-common/pom.xml index 42214abc..4bd7bc82 100644 --- a/cim-common/pom.xml +++ b/cim-common/pom.xml @@ -24,6 +24,11 @@ protobuf-java + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + com.squareup.okhttp3 okhttp diff --git a/cim-common/src/main/java/com/crossoverjie/cim/common/req/BaseRequest.java b/cim-common/src/main/java/com/crossoverjie/cim/common/req/BaseRequest.java index d0693983..1d1a5aea 100644 --- a/cim-common/src/main/java/com/crossoverjie/cim/common/req/BaseRequest.java +++ b/cim-common/src/main/java/com/crossoverjie/cim/common/req/BaseRequest.java @@ -1,6 +1,8 @@ package com.crossoverjie.cim.common.req; +import io.swagger.v3.oas.annotations.media.Schema; + /** * Function: * @author crossoverJie @@ -10,10 +12,10 @@ public class BaseRequest { -// @ApiModelProperty(required=false, value="唯一请求号", example = "1234567890") + @Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "唯一请求号", example = "1234567890") private String reqNo; -// @ApiModelProperty(required=false, value="当前请求的时间戳", example = "0") + @Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "当前请求的时间戳", example = "0") private int timeStamp; diff --git a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/SwaggerConfig.java b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/SwaggerConfig.java index fc77da6e..1c1e8163 100644 --- a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/SwaggerConfig.java +++ b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/SwaggerConfig.java @@ -1,42 +1,31 @@ -//package com.crossoverjie.cim.route.config; -// -//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import springfox.documentation.builders.ApiInfoBuilder; -//import springfox.documentation.builders.PathSelectors; -//import springfox.documentation.builders.RequestHandlerSelectors; -//import springfox.documentation.service.ApiInfo; -//import springfox.documentation.spi.DocumentationType; -//import springfox.documentation.spring.web.plugins.Docket; -//import springfox.documentation.swagger2.annotations.EnableSwagger2; -// -// -//@Configuration -//@EnableSwagger2 -///** 是否打开swagger **/ -//@ConditionalOnExpression("'${swagger.enable}' == 'true'") -//public class SwaggerConfig { -// -// -// @Bean -// public Docket createRestApi() { -// return new Docket(DocumentationType.SWAGGER_2) -// .apiInfo(apiInfo()) -// .select() -// .apis(RequestHandlerSelectors.basePackage("com.crossoverjie.cim.route.controller")) -// .paths(PathSelectors.any()) -// .build(); -// } -// -// private ApiInfo apiInfo() { -// return new ApiInfoBuilder() -// .title("cim-forward-route") -// .description("cim-forward-route api") -// .termsOfServiceUrl("http://crossoverJie.top") -// .contact("crossoverJie") -// .version("1.0.0") -// .build(); -// } -// -//} \ No newline at end of file +package com.crossoverjie.cim.route.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI createRestApi() { + return new OpenAPI() + .info(apiInfo()); + } + + private Info apiInfo() { + return new Info() + .title("cim-forward-route") + .description("cim-forward-route api") + .termsOfService("http://crossoverJie.top") + .contact(contact()) + .version("1.0.0"); + } + + private Contact contact () { + Contact contact = new Contact(); + contact.setName("crossoverJie"); + return contact; + } +} \ No newline at end of file diff --git a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java index 321a808d..e49b9ce3 100644 --- a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java +++ b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java @@ -19,6 +19,7 @@ import com.crossoverjie.cim.route.service.AccountService; import com.crossoverjie.cim.route.service.CommonBizService; import com.crossoverjie.cim.route.service.UserInfoCacheService; +import io.swagger.v3.oas.annotations.Operation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -58,7 +59,7 @@ public class RouteController implements RouteApi { @Autowired private RouteHandle routeHandle ; -// @ApiOperation("群聊 API") + @Operation(summary = "群聊 API") @RequestMapping(value = "groupRoute", method = RequestMethod.POST) @ResponseBody() @Override @@ -97,7 +98,7 @@ public BaseResponse groupRoute(@RequestBody ChatReqVO groupReqVO) thro * @param p2pRequest * @return */ -// @ApiOperation("私聊 API") + @Operation(summary = "私聊 API") @RequestMapping(value = "p2pRoute", method = RequestMethod.POST) @ResponseBody() @Override @@ -123,7 +124,7 @@ public BaseResponse p2pRoute(@RequestBody P2PReqVO p2pRequest) throws } -// @ApiOperation("客户端下线") + @Operation(summary = "客户端下线") @RequestMapping(value = "offLine", method = RequestMethod.POST) @ResponseBody() @Override @@ -145,7 +146,7 @@ public BaseResponse offLine(@RequestBody ChatReqVO groupReqVO) throws * * @return */ -// @ApiOperation("登录并获取服务器") + @Operation(summary = "登录并获取服务器") @RequestMapping(value = "login", method = RequestMethod.POST) @ResponseBody() @Override @@ -181,7 +182,7 @@ public BaseResponse login(@RequestBody LoginReqVO loginReqVO) th * * @return */ -// @ApiOperation("注册账号") + @Operation(summary = "注册账号") @RequestMapping(value = "registerAccount", method = RequestMethod.POST) @ResponseBody() @Override @@ -203,7 +204,7 @@ public BaseResponse registerAccount(@RequestBody RegisterInfo * * @return */ -// @ApiOperation("获取所有在线用户") + @Operation(summary = "获取所有在线用户") @RequestMapping(value = "onlineUser", method = RequestMethod.POST) @ResponseBody() @Override diff --git a/cim-forward-route/src/main/resources/application.properties b/cim-forward-route/src/main/resources/application.properties index b4f1be70..212486bd 100644 --- a/cim-forward-route/src/main/resources/application.properties +++ b/cim-forward-route/src/main/resources/application.properties @@ -3,8 +3,6 @@ spring.application.name=cim-forward-route # web port server.port=8083 -swagger.enable = true - logging.level.root=info diff --git a/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java b/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java index f5d23306..c7365b3f 100644 --- a/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java +++ b/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java @@ -1,42 +1,31 @@ -//package com.crossoverjie.cim.server.config; -// -//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import springfox.documentation.builders.ApiInfoBuilder; -//import springfox.documentation.builders.PathSelectors; -//import springfox.documentation.builders.RequestHandlerSelectors; -//import springfox.documentation.service.ApiInfo; -//import springfox.documentation.spi.DocumentationType; -//import springfox.documentation.spring.web.plugins.Docket; -//import springfox.documentation.swagger2.annotations.EnableSwagger2; -// -// -//@Configuration -//@EnableSwagger2 -///** 是否打开swagger **/ -//@ConditionalOnExpression("'${swagger.enable}' == 'true'") -//public class SwaggerConfig { -// -// -// @Bean -// public Docket createRestApi() { -// return new Docket(DocumentationType.SWAGGER_2) -// .apiInfo(apiInfo()) -// .select() -// .apis(RequestHandlerSelectors.basePackage("com.crossoverjie.cim.server.controller")) -// .paths(PathSelectors.any()) -// .build(); -// } -// -// private ApiInfo apiInfo() { -// return new ApiInfoBuilder() -// .title("sbc order api") -// .description("sbc order api") -// .termsOfServiceUrl("http://crossoverJie.top") -// .contact("crossoverJie") -// .version("1.0.0") -// .build(); -// } -// -//} \ No newline at end of file +package com.crossoverjie.cim.server.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI createRestApi() { + return new OpenAPI() + .info(apiInfo()); + } + + private Info apiInfo() { + return new Info() + .title("sbc order api") + .description("sbc order api") + .termsOfService("http://crossoverJie.top") + .contact(contact()) + .version("1.0.0"); + } + + private Contact contact () { + Contact contact = new Contact(); + contact.setName("crossoverJie"); + return contact; + } +} \ No newline at end of file diff --git a/cim-server/src/main/java/com/crossoverjie/cim/server/controller/IndexController.java b/cim-server/src/main/java/com/crossoverjie/cim/server/controller/IndexController.java index d242e94a..925fe928 100644 --- a/cim-server/src/main/java/com/crossoverjie/cim/server/controller/IndexController.java +++ b/cim-server/src/main/java/com/crossoverjie/cim/server/controller/IndexController.java @@ -7,6 +7,7 @@ import com.crossoverjie.cim.server.api.vo.req.SendMsgReqVO; import com.crossoverjie.cim.server.api.vo.res.SendMsgResVO; import com.crossoverjie.cim.server.server.CIMServer; +import io.swagger.v3.oas.annotations.Operation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -35,7 +36,7 @@ public class IndexController implements ServerApi { * @return */ @Override -// @ApiOperation("Push msg to client") + @Operation(summary = "Push msg to client") @RequestMapping(value = "sendMsg",method = RequestMethod.POST) @ResponseBody public BaseResponse sendMsg(@RequestBody SendMsgReqVO sendMsgReqVO){ diff --git a/cim-server/src/main/resources/application.properties b/cim-server/src/main/resources/application.properties index f3166a41..12408e79 100644 --- a/cim-server/src/main/resources/application.properties +++ b/cim-server/src/main/resources/application.properties @@ -3,8 +3,6 @@ spring.application.name=cim-server # web port server.port=8081 -# enable swagger -swagger.enable = true # cim ????? cim.server.port=11211 diff --git a/pom.xml b/pom.xml index 985b7109..297860de 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,12 @@ + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.4.0 + + com.squareup.okhttp3 okhttp From 70a2d75e6138c61b8e76c8227e70b793ca3a81a7 Mon Sep 17 00:00:00 2001 From: baiyina Date: Fri, 26 Jul 2024 15:54:21 +0800 Subject: [PATCH 2/4] update rout-api vo swagger2->Knife4j update rout-api vo swagger2->Knife4j --- .../com/crossoverjie/cim/route/api/vo/req/ChatReqVO.java | 5 +++-- .../com/crossoverjie/cim/route/api/vo/req/P2PReqVO.java | 7 ++++--- .../cim/route/api/vo/req/RegisterInfoReqVO.java | 3 ++- .../crossoverjie/cim/route/api/vo/req/SendMsgReqVO.java | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/ChatReqVO.java b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/ChatReqVO.java index bb98be72..10c6a682 100644 --- a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/ChatReqVO.java +++ b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/ChatReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,12 +15,12 @@ public class ChatReqVO extends BaseRequest { @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "userId", example = "1545574049323") private Long userId ; @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; public ChatReqVO() { diff --git a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/P2PReqVO.java b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/P2PReqVO.java index 7881549f..d0d0c62c 100644 --- a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/P2PReqVO.java +++ b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/P2PReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,19 +15,19 @@ public class P2PReqVO extends BaseRequest { @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "消息发送者的 userId", example = "1545574049323") private Long userId ; @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "消息接收者的 userId", example = "1545574049323") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "消息接收者的 userId", example = "1545574049323") private Long receiveUserId ; @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; public P2PReqVO() { diff --git a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/RegisterInfoReqVO.java b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/RegisterInfoReqVO.java index c0d1e0ad..6417e3ff 100644 --- a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/RegisterInfoReqVO.java +++ b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/RegisterInfoReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,7 +15,7 @@ public class RegisterInfoReqVO extends BaseRequest { @NotNull(message = "用户名不能为空") -// @ApiModelProperty(required = true, value = "userName", example = "zhangsan") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "userName", example = "zhangsan") private String userName ; public String getUserName() { diff --git a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/SendMsgReqVO.java b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/SendMsgReqVO.java index cf1aee05..35e81abb 100644 --- a/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/SendMsgReqVO.java +++ b/cim-rout-api/src/main/java/com/crossoverjie/cim/route/api/vo/req/SendMsgReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -14,11 +15,11 @@ public class SendMsgReqVO extends BaseRequest { @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; @NotNull(message = "id 不能为空") -// @ApiModelProperty(required = true, value = "id", example = "11") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "id", example = "11") private long id ; public String getMsg() { From 0c74ecf53693b1746bf41234eedad255ab464841 Mon Sep 17 00:00:00 2001 From: baiyina Date: Fri, 26 Jul 2024 16:40:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20SendMsgReqVO.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update SendMsgReqVO, Knife4j update ends --- .../crossoverjie/cim/server/api/vo/req/SendMsgReqVO.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cim-server-api/src/main/java/com/crossoverjie/cim/server/api/vo/req/SendMsgReqVO.java b/cim-server-api/src/main/java/com/crossoverjie/cim/server/api/vo/req/SendMsgReqVO.java index 1b5b7ebf..247d49f4 100644 --- a/cim-server-api/src/main/java/com/crossoverjie/cim/server/api/vo/req/SendMsgReqVO.java +++ b/cim-server-api/src/main/java/com/crossoverjie/cim/server/api/vo/req/SendMsgReqVO.java @@ -2,6 +2,7 @@ import com.crossoverjie.cim.common.req.BaseRequest; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; /** @@ -13,12 +14,12 @@ */ public class SendMsgReqVO extends BaseRequest { -// @NotNull(message = "msg 不能为空") -// @ApiModelProperty(required = true, value = "msg", example = "hello") + @NotNull(message = "msg 不能为空") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "msg", example = "hello") private String msg ; -// @NotNull(message = "userId 不能为空") -// @ApiModelProperty(required = true, value = "userId", example = "11") + @NotNull(message = "userId 不能为空") + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "userId", example = "11") private Long userId ; public SendMsgReqVO() { From eb8eacc36d55e2f6e98f92422e2cf5d37bed47d7 Mon Sep 17 00:00:00 2001 From: baiyina Date: Tue, 30 Jul 2024 10:36:50 +0800 Subject: [PATCH 4/4] indentation, title config, swagger properties indentation, title config, swagger properties --- .../com/crossoverjie/cim/client/config/SwaggerConfig.java | 8 ++++---- cim-client/src/main/resources/application.properties | 4 +++- .../src/main/resources/application.properties | 2 ++ .../com/crossoverjie/cim/server/config/SwaggerConfig.java | 4 ++-- cim-server/src/main/resources/application.properties | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java b/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java index c86725b4..5e7cbf3c 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/config/SwaggerConfig.java @@ -7,10 +7,10 @@ import org.springframework.context.annotation.Configuration; - @Configuration public class SwaggerConfig { - @Bean + + @Bean public OpenAPI createRestApi() { return new OpenAPI() .info(apiInfo()); @@ -18,8 +18,8 @@ public OpenAPI createRestApi() { private Info apiInfo() { return new Info() - .title("sbc order api") - .description("sbc order api") + .title("cim client") + .description("cim client api") .termsOfService("http://crossoverJie.top") .contact(contact()) .version("1.0.0"); diff --git a/cim-client/src/main/resources/application.properties b/cim-client/src/main/resources/application.properties index 911bdcbd..971fe565 100644 --- a/cim-client/src/main/resources/application.properties +++ b/cim-client/src/main/resources/application.properties @@ -5,10 +5,12 @@ server.port=8082 logging.level.root=error +# enable swagger +springdoc.swagger-ui.enabled = true + # log path cim.msg.logger.path = /opt/logs/cim/ - # route url suggested that this is Nginx address cim.route.url = http://localhost:8083 diff --git a/cim-forward-route/src/main/resources/application.properties b/cim-forward-route/src/main/resources/application.properties index 212486bd..0fec3896 100644 --- a/cim-forward-route/src/main/resources/application.properties +++ b/cim-forward-route/src/main/resources/application.properties @@ -5,6 +5,8 @@ server.port=8083 logging.level.root=info +# enable swagger +springdoc.swagger-ui.enabled = true app.zk.addr=127.0.0.1:2181 diff --git a/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java b/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java index c7365b3f..dced0001 100644 --- a/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java +++ b/cim-server/src/main/java/com/crossoverjie/cim/server/config/SwaggerConfig.java @@ -16,8 +16,8 @@ public OpenAPI createRestApi() { private Info apiInfo() { return new Info() - .title("sbc order api") - .description("sbc order api") + .title("cim server") + .description("cim server api") .termsOfService("http://crossoverJie.top") .contact(contact()) .version("1.0.0"); diff --git a/cim-server/src/main/resources/application.properties b/cim-server/src/main/resources/application.properties index 12408e79..09dc2c20 100644 --- a/cim-server/src/main/resources/application.properties +++ b/cim-server/src/main/resources/application.properties @@ -3,14 +3,14 @@ spring.application.name=cim-server # web port server.port=8081 +# enable swagger +springdoc.swagger-ui.enabled = true # cim ????? cim.server.port=11211 logging.level.root=info - - # enable zk app.zk.switch=true