Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Knife4j 4.4代替接口文档 #136

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
// }
//
//}
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
crossoverJie marked this conversation as resolved.
Show resolved Hide resolved
public OpenAPI createRestApi() {
return new OpenAPI()
.info(apiInfo());
}

private Info apiInfo() {
return new Info()
.title("sbc order api")
.description("sbc order api")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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");
}

private Contact contact () {
Contact contact = new Contact();
contact.setName("crossoverJie");
return contact;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class IndexController {
* @param stringReqVO
* @return
*/
// @ApiOperation("客户端发送消息,字符串")
@Operation(summary = "客户端发送消息,字符串")
@RequestMapping(value = "sendStringMsg", method = RequestMethod.POST)
@ResponseBody
public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO){
Expand All @@ -67,7 +68,7 @@ public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO
* @param googleProtocolVO
* @return
*/
// @ApiOperation("向服务端发消息 Google ProtoBuf")
@Operation(summary = "向服务端发消息 Google ProtoBuf")
@RequestMapping(value = "sendProtoBufMsg", method = RequestMethod.POST)
@ResponseBody
public BaseResponse<NULLBody> sendProtoBufMsg(@RequestBody GoogleProtocolVO googleProtocolVO){
Expand All @@ -93,7 +94,7 @@ public BaseResponse<NULLBody> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crossoverjie.cim.common.req.BaseRequest;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crossoverjie.cim.common.req.BaseRequest;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crossoverjie.cim.common.req.BaseRequest;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crossoverjie.cim.common.req.BaseRequest;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.crossoverjie.cim.common.req.BaseRequest;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions cim-client/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ spring.application.name=cim-client
# web port
server.port=8082

# enable swagger
swagger.enable = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's suggested to provide this feature in the subsequent PR.


logging.level.root=error

# log path
Expand Down
5 changes: 5 additions & 0 deletions cim-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.crossoverjie.cim.common.req;


import io.swagger.v3.oas.annotations.media.Schema;

/**
* Function:
* @author crossoverJie
Expand All @@ -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;


Expand Down
Original file line number Diff line number Diff line change
@@ -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();
// }
//
//}
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;
}
}
Loading