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

Commit a42652e

Browse files
authored
Merge pull request #1115 from linwumingshi/fix/issues-1114
fix: 🐛 support path attribute in `@FeignClient` and refactor annotation constants
2 parents b00f4a4 + bfef5b7 commit a42652e

5 files changed

Lines changed: 169 additions & 86 deletions

File tree

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 smart-doc
2+
* Copyright (C) 2018-2025 smart-doc
33
*
44
* Licensed to the Apache Software Foundation (ASF) under one
55
* or more contributor license agreements. See the NOTICE file
@@ -215,4 +215,56 @@ public interface DocAnnotationConstants {
215215
*/
216216
String PATH_PARAM = "PathParam";
217217

218+
/**
219+
* The name of the 'consumes' attribute in Spring MVC request mapping annotations,
220+
* used to specify the media types that the annotated handler method can consume.
221+
* <p>
222+
* Corresponds to
223+
* {@code org.springframework.web.bind.annotation.RequestMapping#consumes()}
224+
* </p>
225+
*/
226+
String CONSUMES = "consumes";
227+
228+
/**
229+
* The name of the 'produces' attribute in Spring MVC request mapping annotations,
230+
* used to specify the media types that the annotated handler method can produce.
231+
* <p>
232+
* Corresponds to
233+
* {@code org.springframework.web.bind.annotation.RequestMapping#produces()}
234+
* </p>
235+
*/
236+
String PRODUCES = "produces";
237+
238+
/**
239+
* The name of the 'method' attribute in Spring MVC request mapping annotations, used
240+
* to specify the HTTP request methods that the annotated handler method supports.
241+
* <p>
242+
* Corresponds to
243+
* {@code org.springframework.web.bind.annotation.RequestMapping#method()}
244+
* </p>
245+
*/
246+
String METHOD = "method";
247+
248+
/**
249+
* The name of the 'params' attribute in Spring MVC request mapping annotations, used
250+
* to specify HTTP request parameters that must be present for the mapping to be
251+
* matched.
252+
* <p>
253+
* Corresponds to
254+
* {@code org.springframework.web.bind.annotation.RequestMapping#params()}
255+
* </p>
256+
*/
257+
String PARAMS = "params";
258+
259+
/**
260+
* Common property names used to define request mapping paths. Typically used in
261+
* annotations like {@code @RequestMapping}, {@code @GetMapping}, etc. Corresponds to
262+
* 'value' and 'path' attributes which are synonyms in Spring MVC.
263+
*
264+
* <p>
265+
* Used to configure URL mapping paths for handler methods.
266+
* </p>
267+
*/
268+
String[] PATH_MAPPING_PROPS = { VALUE_PROP, PATH_PROP };
269+
218270
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 smart-doc
2+
* Copyright (C) 2018-2025 smart-doc
33
*
44
* Licensed to the Apache Software Foundation (ASF) under one
55
* or more contributor license agreements. See the NOTICE file
@@ -40,8 +40,14 @@ public interface SpringMvcAnnotations {
4040

4141
String DELETE_MAPPING = "DeleteMapping";
4242

43+
@Deprecated
4344
String REQUEST_HERDER = "RequestHeader";
4445

46+
/**
47+
* RequestHeader
48+
*/
49+
String REQUEST_HEADER = "RequestHeader";
50+
4551
String REQUEST_PARAM = "RequestParam";
4652

4753
String REQUEST_PART = "RequestPart";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean isMapping(String annotationName) {
4949
@Override
5050
public HeaderAnnotation getHeaderAnnotation() {
5151
return HeaderAnnotation.builder()
52-
.setAnnotationName(SpringMvcAnnotations.REQUEST_HERDER)
52+
.setAnnotationName(SpringMvcAnnotations.REQUEST_HEADER)
5353
.setValueProp(DocAnnotationConstants.VALUE_PROP)
5454
.setDefaultValueProp(DocAnnotationConstants.DEFAULT_VALUE_PROP)
5555
.setRequiredProp(DocAnnotationConstants.REQUIRED_PROP);

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

Lines changed: 99 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 smart-doc
2+
* Copyright (C) 2018-2025 smart-doc
33
*
44
* Licensed to the Apache Software Foundation (ASF) under one
55
* or more contributor license agreements. See the NOTICE file
@@ -108,15 +108,17 @@ public boolean ignoreReturnObject(String typeName, List<String> ignoreParams) {
108108
@Override
109109
public FrameworkAnnotations registeredAnnotations() {
110110
FrameworkAnnotations annotations = FrameworkAnnotations.builder();
111+
112+
// Header annotation
111113
HeaderAnnotation headerAnnotation = HeaderAnnotation.builder()
112-
.setAnnotationName(SpringMvcAnnotations.REQUEST_HERDER)
114+
.setAnnotationName(SpringMvcAnnotations.REQUEST_HEADER)
113115
.setValueProp(DocAnnotationConstants.VALUE_PROP)
114116
.setDefaultValueProp(DocAnnotationConstants.DEFAULT_VALUE_PROP)
115117
.setRequiredProp(DocAnnotationConstants.REQUIRED_PROP);
116118
// add header annotation
117119
annotations.setHeaderAnnotation(headerAnnotation);
118120

119-
// add entry annotation
121+
// Entry annotations (Controller, RestController)
120122
Map<String, EntryAnnotation> entryAnnotations = new HashMap<>(16);
121123
EntryAnnotation controllerAnnotation = EntryAnnotation.builder()
122124
.setAnnotationName(SpringMvcAnnotations.CONTROLLER)
@@ -128,108 +130,43 @@ public FrameworkAnnotations registeredAnnotations() {
128130
entryAnnotations.put(restController.getAnnotationName(), restController);
129131
annotations.setEntryAnnotations(entryAnnotations);
130132

131-
// add request body annotation
133+
// RequestBody annotation
132134
RequestBodyAnnotation bodyAnnotation = RequestBodyAnnotation.builder()
133135
.setAnnotationName(SpringMvcAnnotations.REQUEST_BODY)
134136
.setAnnotationFullyName(SpringMvcAnnotations.REQUEST_BODY_FULLY);
135137
annotations.setRequestBodyAnnotation(bodyAnnotation);
136138

137-
// request param annotation
138-
RequestParamAnnotation requestAnnotation = RequestParamAnnotation.builder()
139+
// RequestParam annotation
140+
RequestParamAnnotation requestParamAnnotation = RequestParamAnnotation.builder()
139141
.setAnnotationName(SpringMvcAnnotations.REQUEST_PARAM)
140142
.setDefaultValueProp(DocAnnotationConstants.DEFAULT_VALUE_PROP)
141143
.setRequiredProp(DocAnnotationConstants.REQUIRED_PROP);
142-
annotations.setRequestParamAnnotation(requestAnnotation);
144+
annotations.setRequestParamAnnotation(requestParamAnnotation);
143145

144-
// request part annotation
146+
// RequestPart annotation
145147
RequestPartAnnotation requestPartAnnotation = RequestPartAnnotation.builder()
146148
.setAnnotationName(SpringMvcAnnotations.REQUEST_PART)
147149
.setDefaultValueProp(DocAnnotationConstants.DEFAULT_VALUE_PROP)
148150
.setRequiredProp(DocAnnotationConstants.REQUIRED_PROP);
149151
annotations.setRequestPartAnnotation(requestPartAnnotation);
150152

151-
// add path variable annotation
153+
// PathVariable annotation
152154
PathVariableAnnotation pathVariableAnnotation = PathVariableAnnotation.builder()
153155
.setAnnotationName(SpringMvcAnnotations.PATH_VARIABLE)
154156
.setDefaultValueProp(DocAnnotationConstants.DEFAULT_VALUE_PROP)
155157
.setRequiredProp(DocAnnotationConstants.REQUIRED_PROP);
156158
annotations.setPathVariableAnnotation(pathVariableAnnotation);
157159

158-
// add websocket server endpoint annotation
160+
// ServerEndpoint annotation (WebSocket)
159161
ServerEndpointAnnotation serverEndpointAnnotation = ServerEndpointAnnotation.builder()
160162
.setAnnotationName(SpringMvcAnnotations.SERVER_ENDPOINT);
161163
annotations.setServerEndpointAnnotation(serverEndpointAnnotation);
162164

163165
// add mapping annotations
164-
Map<String, MappingAnnotation> mappingAnnotations = new HashMap<>(16);
165-
166-
MappingAnnotation requestMappingAnnotation = MappingAnnotation.builder()
167-
.setAnnotationName(SpringMvcAnnotations.REQUEST_MAPPING)
168-
.setConsumesProp("consumes")
169-
.setProducesProp("produces")
170-
.setMethodProp("method")
171-
.setParamsProp("params")
172-
.setScope("class", "method")
173-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
174-
mappingAnnotations.put(requestMappingAnnotation.getAnnotationName(), requestMappingAnnotation);
175-
176-
MappingAnnotation postMappingAnnotation = MappingAnnotation.builder()
177-
.setAnnotationName(SpringMvcAnnotations.POST_MAPPING)
178-
.setConsumesProp("consumes")
179-
.setProducesProp("produces")
180-
.setMethodProp("method")
181-
.setParamsProp("params")
182-
.setMethodType(Methods.POST.getValue())
183-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
184-
mappingAnnotations.put(postMappingAnnotation.getAnnotationName(), postMappingAnnotation);
185-
186-
MappingAnnotation getMappingAnnotation = MappingAnnotation.builder()
187-
.setAnnotationName(SpringMvcAnnotations.GET_MAPPING)
188-
.setConsumesProp("consumes")
189-
.setProducesProp("produces")
190-
.setMethodProp("method")
191-
.setParamsProp("params")
192-
.setMethodType(Methods.GET.getValue())
193-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
194-
mappingAnnotations.put(getMappingAnnotation.getAnnotationName(), getMappingAnnotation);
195-
196-
MappingAnnotation putMappingAnnotation = MappingAnnotation.builder()
197-
.setAnnotationName(SpringMvcAnnotations.PUT_MAPPING)
198-
.setConsumesProp("consumes")
199-
.setProducesProp("produces")
200-
.setParamsProp("params")
201-
.setMethodProp("method")
202-
.setMethodType(Methods.PUT.getValue())
203-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
204-
mappingAnnotations.put(putMappingAnnotation.getAnnotationName(), putMappingAnnotation);
205-
206-
MappingAnnotation patchMappingAnnotation = MappingAnnotation.builder()
207-
.setAnnotationName(SpringMvcAnnotations.PATCH_MAPPING)
208-
.setConsumesProp("consumes")
209-
.setProducesProp("produces")
210-
.setMethodProp("method")
211-
.setParamsProp("params")
212-
.setMethodType(Methods.PATCH.getValue())
213-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
214-
mappingAnnotations.put(patchMappingAnnotation.getAnnotationName(), patchMappingAnnotation);
215-
216-
MappingAnnotation deleteMappingAnnotation = MappingAnnotation.builder()
217-
.setAnnotationName(SpringMvcAnnotations.DELETE_MAPPING)
218-
.setConsumesProp("consumes")
219-
.setProducesProp("produces")
220-
.setMethodProp("method")
221-
.setParamsProp("params")
222-
.setMethodType(Methods.DELETE.getValue())
223-
.setPathProps(DocAnnotationConstants.VALUE_PROP, DocAnnotationConstants.PATH_PROP);
224-
mappingAnnotations.put(deleteMappingAnnotation.getAnnotationName(), deleteMappingAnnotation);
225-
226-
MappingAnnotation feignClientAnnotation = MappingAnnotation.builder()
227-
.setAnnotationName(DocGlobalConstants.FEIGN_CLIENT)
228-
.setAnnotationFullyName(DocGlobalConstants.FEIGN_CLIENT_FULLY);
229-
mappingAnnotations.put(feignClientAnnotation.getAnnotationName(), feignClientAnnotation);
166+
Map<String, MappingAnnotation> mappingAnnotations = buildSpringMappingAnnotations();
230167
annotations.setMappingAnnotations(mappingAnnotations);
231168

232-
// Add Exception advice
169+
// Exception advice annotations
233170
Map<String, ExceptionAdviceAnnotation> exceptionAdviceAnnotations = new HashMap<>(16);
234171

235172
ExceptionAdviceAnnotation controllerAdviceAnnotation = ExceptionAdviceAnnotation.builder()
@@ -432,4 +369,89 @@ public List<ApiExceptionStatus> defaultHttpErrorStatuses() {
432369
return exceptionStatusList;
433370
}
434371

372+
/**
373+
* Builds and returns all Spring MVC request mapping annotations
374+
* including @RequestMapping, @GetMapping, @PostMapping, etc., with consistent
375+
* attribute configurations.
376+
* @return a map of annotation name to {@link MappingAnnotation}
377+
*/
378+
private Map<String, MappingAnnotation> buildSpringMappingAnnotations() {
379+
Map<String, MappingAnnotation> mappingAnnotations = new HashMap<>(16);
380+
381+
// Common properties
382+
String consumes = DocAnnotationConstants.CONSUMES;
383+
String produces = DocAnnotationConstants.PRODUCES;
384+
String method = DocAnnotationConstants.METHOD;
385+
String params = DocAnnotationConstants.PARAMS;
386+
String[] pathProps = DocAnnotationConstants.PATH_MAPPING_PROPS;
387+
388+
// @RequestMapping
389+
MappingAnnotation requestMapping = MappingAnnotation.builder()
390+
.setAnnotationName(SpringMvcAnnotations.REQUEST_MAPPING)
391+
.setConsumesProp(consumes)
392+
.setProducesProp(produces)
393+
.setMethodProp(method)
394+
.setParamsProp(params)
395+
.setScope("class", "method")
396+
.setPathProps(pathProps);
397+
mappingAnnotations.put(requestMapping.getAnnotationName(), requestMapping);
398+
399+
// @PostMapping
400+
MappingAnnotation postMapping = this.createMapping(SpringMvcAnnotations.POST_MAPPING, Methods.POST.getValue(),
401+
pathProps, consumes, produces, method, params);
402+
mappingAnnotations.put(postMapping.getAnnotationName(), postMapping);
403+
404+
// @GetMapping
405+
MappingAnnotation getMapping = this.createMapping(SpringMvcAnnotations.GET_MAPPING, Methods.GET.getValue(),
406+
pathProps, consumes, produces, method, params);
407+
mappingAnnotations.put(getMapping.getAnnotationName(), getMapping);
408+
409+
// @PutMapping
410+
MappingAnnotation putMapping = this.createMapping(SpringMvcAnnotations.PUT_MAPPING, Methods.PUT.getValue(),
411+
pathProps, consumes, produces, method, params);
412+
mappingAnnotations.put(putMapping.getAnnotationName(), putMapping);
413+
414+
// @PatchMapping
415+
MappingAnnotation patchMapping = this.createMapping(SpringMvcAnnotations.PATCH_MAPPING,
416+
Methods.PATCH.getValue(), pathProps, consumes, produces, method, params);
417+
mappingAnnotations.put(patchMapping.getAnnotationName(), patchMapping);
418+
419+
// @DeleteMapping
420+
MappingAnnotation deleteMapping = this.createMapping(SpringMvcAnnotations.DELETE_MAPPING,
421+
Methods.DELETE.getValue(), pathProps, consumes, produces, method, params);
422+
mappingAnnotations.put(deleteMapping.getAnnotationName(), deleteMapping);
423+
424+
// @FeignClient
425+
MappingAnnotation feignClient = MappingAnnotation.builder()
426+
.setAnnotationName(DocGlobalConstants.FEIGN_CLIENT)
427+
.setAnnotationFullyName(DocGlobalConstants.FEIGN_CLIENT_FULLY)
428+
.setPathProps(DocAnnotationConstants.PATH_PROP);
429+
mappingAnnotations.put(feignClient.getAnnotationName(), feignClient);
430+
431+
return mappingAnnotations;
432+
}
433+
434+
/**
435+
* Helper method to create common HTTP method-based mappings
436+
* (e.g., @GetMapping, @PostMapping).
437+
* @param annotationName the annotation name
438+
* @param methodType the method type
439+
* @param pathProps the path properties
440+
* @param consumes the consumes property
441+
* @param produces the produces property
442+
* @param method the HTTP method
443+
* @param params the params property
444+
*/
445+
private MappingAnnotation createMapping(String annotationName, String methodType, String[] pathProps,
446+
String consumes, String produces, String method, String params) {
447+
return MappingAnnotation.builder()
448+
.setAnnotationName(annotationName)
449+
.setConsumesProp(consumes)
450+
.setProducesProp(produces)
451+
.setMethodProp(method)
452+
.setParamsProp(params)
453+
.setMethodType(methodType)
454+
.setPathProps(pathProps);
455+
}
456+
435457
}

src/main/java/com/ly/doc/utils/JavaClassValidateUtil.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/*
2-
* smart-doc
3-
*
4-
* Copyright (C) 2018-2024 smart-doc
2+
* Copyright (C) 2018-2025 smart-doc
53
*
64
* Licensed to the Apache Software Foundation (ASF) under one
75
* or more contributor license agreements. See the NOTICE file
@@ -20,9 +18,14 @@
2018
* specific language governing permissions and limitations
2119
* under the License.
2220
*/
21+
2322
package com.ly.doc.utils;
2423

25-
import com.ly.doc.constants.*;
24+
import com.ly.doc.constants.DocAnnotationConstants;
25+
import com.ly.doc.constants.JSRAnnotationConstants;
26+
import com.ly.doc.constants.JavaTypeConstants;
27+
import com.ly.doc.constants.SolonAnnotations;
28+
import com.ly.doc.constants.SpringMvcAnnotations;
2629
import com.power.common.util.CollectionUtil;
2730
import com.power.common.util.StringUtil;
2831
import com.power.common.util.ValidateUtil;
@@ -227,7 +230,7 @@ public static boolean isJSR303Required(String annotationSimpleName) {
227230
* @return boolean
228231
*/
229232
public static boolean isIgnoreTag(String tagName) {
230-
return tagName.equals("ignore");
233+
return "ignore".equals(tagName);
231234
}
232235

233236
/**
@@ -355,7 +358,7 @@ public static boolean ignoreSpringMvcParamWithAnnotation(String annotation) {
355358
switch (annotation) {
356359
case SpringMvcAnnotations.SESSION_ATTRIBUTE:
357360
case SpringMvcAnnotations.REQUEST_ATTRIBUTE:
358-
case SpringMvcAnnotations.REQUEST_HERDER:
361+
case SpringMvcAnnotations.REQUEST_HEADER:
359362
return true;
360363
default:
361364
return false;

0 commit comments

Comments
 (0)