Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 71512e7

Browse files
authored
Merge pull request #882 from linwumingshi/feature/websocket-param
Added support for message and response parameters
2 parents 78f737d + f59175a commit 71512e7

File tree

15 files changed

+408
-82
lines changed

15 files changed

+408
-82
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ based on interface source code analysis to generate interface documents, and zer
1515
write Javadoc comments when developing, `smart-doc` can help you generate `Markdown` or `HTML5` document. `smart-doc` does not
1616
need to inject annotations into the code like `Swagger`.
1717

18-
[quick start](https://smart-doc-group.github.io/)
18+
**[Quick Start](https://smart-doc-group.github.io/)**
1919

2020
## Documentation
2121
* [English](https://smart-doc-group.github.io/)

src/main/java/com/ly/doc/builder/websocket/WebSocketDocBuilderTemplate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public Template buildWebSocketApiDocTemplate(WebSocketDoc webSocketDoc, ApiConfi
142142
mapper.binding(TemplateVariable.AUTHOR.getVariable(), webSocketDoc.getAuthor());
143143
mapper.binding(TemplateVariable.SUB_PROTOCOLS.getVariable(), webSocketDoc.getSubProtocols());
144144
mapper.binding(TemplateVariable.WEBSOCKET_PATH_PARAMS.getVariable(), webSocketDoc.getPathParams());
145+
mapper.binding(TemplateVariable.WEBSOCKET_MESSAGE_PARAMS.getVariable(), webSocketDoc.getMessageParams());
146+
mapper.binding(TemplateVariable.WEBSOCKET_RESPONSE_PARAMS.getVariable(), webSocketDoc.getResponseParams());
145147
return mapper;
146148
}
147149

src/main/java/com/ly/doc/constants/DocAnnotationConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public interface DocAnnotationConstants {
197197
*/
198198
String ON_OPEN = "OnOpen";
199199

200+
/**
201+
* `@javax.websocket.OnMessage` or `@jakarta.websocket.OnMessage` annotation name
202+
* {@code javax.websocket.OnMessage} {@code jakarta.websocket.OnMessage}
203+
*/
204+
String ON_MESSAGE = "OnMessage";
205+
200206
/**
201207
* `@javax.websocket.server.PathParam` or `@jakarta.websocket.PathParam` annotation
202208
* name {@code javax.websocket.server.PathParam}

src/main/java/com/ly/doc/constants/TemplateVariable.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ public enum TemplateVariable {
192192
/**
193193
* webSocketPathParams
194194
*/
195-
WEBSOCKET_PATH_PARAMS("pathParams"),;
195+
WEBSOCKET_PATH_PARAMS("pathParams"),
196+
197+
/**
198+
* webSocketMessageParams
199+
*/
200+
WEBSOCKET_MESSAGE_PARAMS("messageParams"),
201+
202+
/**
203+
* webSocketResponseParams
204+
*/
205+
WEBSOCKET_RESPONSE_PARAMS("responseParams"),
206+
207+
;
196208

197209
/**
198210
* variable

src/main/java/com/ly/doc/handler/IWebSocketRequestHandler.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.thoughtworks.qdox.model.JavaClass;
2929
import com.thoughtworks.qdox.model.expression.AnnotationValue;
3030
import com.thoughtworks.qdox.model.expression.AnnotationValueList;
31+
import com.thoughtworks.qdox.model.expression.TypeRef;
3132

3233
import java.util.List;
3334
import java.util.Objects;
@@ -64,6 +65,29 @@ default ServerEndpoint handleServerEndpoint(JavaClass cls, JavaAnnotation javaAn
6465
List<String> subProtocols = valueList.stream().map(Object::toString).collect(Collectors.toList());
6566
builder.setSubProtocols(subProtocols);
6667
}
68+
69+
// get decoders of annotation
70+
AnnotationValue decodersOfAnnotation = javaAnnotation.getProperty("decoders");
71+
if (Objects.nonNull(decodersOfAnnotation) && decodersOfAnnotation instanceof AnnotationValueList) {
72+
List<AnnotationValue> valueList = ((AnnotationValueList) decodersOfAnnotation).getValueList();
73+
List<String> decoders = valueList.stream()
74+
.filter(i -> i instanceof TypeRef)
75+
.map(i -> ((TypeRef) i).getType().getFullyQualifiedName())
76+
.collect(Collectors.toList());
77+
builder.setDecoders(decoders);
78+
}
79+
80+
// get encoders of annotation
81+
AnnotationValue encodersOfAnnotation = javaAnnotation.getProperty("encoders");
82+
if (Objects.nonNull(encodersOfAnnotation) && encodersOfAnnotation instanceof AnnotationValueList) {
83+
List<AnnotationValue> valueList = ((AnnotationValueList) encodersOfAnnotation).getValueList();
84+
List<String> encoders = valueList.stream()
85+
.filter(i -> i instanceof TypeRef)
86+
.map(i -> ((TypeRef) i).getType().getFullyQualifiedName())
87+
.collect(Collectors.toList());
88+
builder.setEncoders(encoders);
89+
}
90+
6791
return builder;
6892
}
6993

src/main/java/com/ly/doc/helper/DocBuildHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private Set<FileDiff> getChangedFiles(List<DiffEntry> diff, Set<String> uncommit
262262
*/
263263
private String toQualifiedName(String relativePath) {
264264
// /dev/null is git default path when a file is added or deleted
265-
if ("/dev/null".equals(relativePath)) {
265+
if (DiffEntry.DEV_NULL.equals(relativePath)) {
266266
return relativePath;
267267
}
268268

src/main/java/com/ly/doc/model/WebSocketDoc.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
*/
2121
package com.ly.doc.model;
2222

23+
import java.util.Collections;
2324
import java.util.List;
2425

2526
/**
2627
* the webSocket doc
2728
*
28-
* @author Lin222
29+
* @author linwumingshi
30+
* @since 3.0.3
2931
*/
3032
public class WebSocketDoc extends ApiDoc {
3133

@@ -41,6 +43,16 @@ public class WebSocketDoc extends ApiDoc {
4143
*/
4244
private List<ApiParam> pathParams;
4345

46+
/**
47+
* message param
48+
*/
49+
private List<ApiParam> messageParams;
50+
51+
/**
52+
* response param
53+
*/
54+
private List<List<ApiParam>> responseParams;
55+
4456
/**
4557
* webSocket url
4658
*/
@@ -64,13 +76,37 @@ public void setSubProtocols(String subProtocols) {
6476
}
6577

6678
public List<ApiParam> getPathParams() {
79+
if (pathParams == null) {
80+
return Collections.emptyList();
81+
}
6782
return pathParams;
6883
}
6984

7085
public void setPathParams(List<ApiParam> pathParams) {
7186
this.pathParams = pathParams;
7287
}
7388

89+
public List<ApiParam> getMessageParams() {
90+
if (messageParams == null) {
91+
return Collections.emptyList();
92+
}
93+
return messageParams;
94+
}
95+
96+
public WebSocketDoc setMessageParams(List<ApiParam> messageParams) {
97+
this.messageParams = messageParams;
98+
return this;
99+
}
100+
101+
public List<List<ApiParam>> getResponseParams() {
102+
return responseParams;
103+
}
104+
105+
public WebSocketDoc setResponseParams(List<List<ApiParam>> responseParams) {
106+
this.responseParams = responseParams;
107+
return this;
108+
}
109+
74110
public String getUri() {
75111
return uri;
76112
}

src/main/java/com/ly/doc/model/request/ServerEndpoint.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ public class ServerEndpoint {
4040
*/
4141
private List<String> subProtocols;
4242

43+
/**
44+
* the decoders class list of annotation
45+
*/
46+
private List<String> decoders;
47+
48+
/**
49+
* the encoders class list of annotation
50+
*/
51+
private List<String> encoders;
52+
4353
public ServerEndpoint() {
44-
this.subProtocols = Collections.emptyList();
4554
}
4655

4756
/**
@@ -56,18 +65,45 @@ public String getUrl() {
5665
return url;
5766
}
5867

59-
public List<String> getSubProtocols() {
60-
return subProtocols;
61-
}
62-
6368
public ServerEndpoint setUrl(String url) {
6469
this.url = url;
6570
return this;
6671
}
6772

73+
public List<String> getSubProtocols() {
74+
if (subProtocols == null) {
75+
subProtocols = Collections.emptyList();
76+
}
77+
return subProtocols;
78+
}
79+
6880
public ServerEndpoint setSubProtocols(List<String> subProtocols) {
6981
this.subProtocols = subProtocols;
7082
return this;
7183
}
7284

85+
public List<String> getDecoders() {
86+
if (decoders == null) {
87+
decoders = Collections.emptyList();
88+
}
89+
return decoders;
90+
}
91+
92+
public ServerEndpoint setDecoders(List<String> decoders) {
93+
this.decoders = decoders;
94+
return this;
95+
}
96+
97+
public List<String> getEncoders() {
98+
if (encoders == null) {
99+
encoders = Collections.emptyList();
100+
}
101+
return encoders;
102+
}
103+
104+
public ServerEndpoint setEncoders(List<String> encoders) {
105+
this.encoders = encoders;
106+
return this;
107+
}
108+
73109
}

src/main/java/com/ly/doc/template/IWebSocketDocBuildTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* websocket doc build template
3434
*
3535
* @author linwumingshi
36+
* @since 3.0.3
3637
*/
3738
public interface IWebSocketDocBuildTemplate<T extends WebSocketDoc> extends IDocBuildBaseTemplate {
3839

@@ -47,7 +48,7 @@ default List<T> getWebSocketData(ProjectDocConfigBuilder projectBuilder) {
4748
DocMapping.init();
4849
DocBuildHelper docBuildHelper = DocBuildHelper.create(projectBuilder);
4950

50-
preRender(docBuildHelper);
51+
this.preRender(docBuildHelper);
5152

5253
Collection<JavaClass> candidateClasses = this.getCandidateClasses(projectBuilder, docBuildHelper);
5354

0 commit comments

Comments
 (0)