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..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 @@ -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("cim client") + .description("cim client 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..971fe565 100644 --- a/cim-client/src/main/resources/application.properties +++ b/cim-client/src/main/resources/application.properties @@ -3,15 +3,14 @@ spring.application.name=cim-client # web port server.port=8082 -# enable swagger -swagger.enable = true - 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-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..0fec3896 100644 --- a/cim-forward-route/src/main/resources/application.properties +++ b/cim-forward-route/src/main/resources/application.properties @@ -3,10 +3,10 @@ spring.application.name=cim-forward-route # web port server.port=8083 -swagger.enable = true - logging.level.root=info +# enable swagger +springdoc.swagger-ui.enabled = true app.zk.addr=127.0.0.1:2181 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() { 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() { 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..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 @@ -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("cim server") + .description("cim server 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..09dc2c20 100644 --- a/cim-server/src/main/resources/application.properties +++ b/cim-server/src/main/resources/application.properties @@ -4,15 +4,13 @@ spring.application.name=cim-server server.port=8081 # enable swagger -swagger.enable = true +springdoc.swagger-ui.enabled = true # cim ????? cim.server.port=11211 logging.level.root=info - - # enable zk app.zk.switch=true 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