2222
2323import com .ly .doc .builder .ProjectDocConfigBuilder ;
2424import com .ly .doc .constants .*;
25- import com .ly .doc .handler .DefaultWebSocketRequestHandler ;
26- import com .ly .doc .handler .JaxrsHeaderHandler ;
27- import com .ly .doc .handler .JaxrsPathHandler ;
25+ import com .ly .doc .handler .*;
2826import com .ly .doc .helper .FormDataBuildHelper ;
2927import com .ly .doc .helper .JsonBuildHelper ;
3028import com .ly .doc .helper .ParamsBuildHelper ;
4139import com .thoughtworks .qdox .model .*;
4240
4341import java .util .*;
44- import java .util .concurrent .atomic .AtomicInteger ;
4542import java .util .logging .Logger ;
4643import java .util .stream .Collectors ;
4744import java .util .stream .Stream ;
5451 * @author Zxq
5552 * @since 2021/7/15
5653 */
57- public class JaxrsDocBuildTemplate implements IDocBuildTemplate <ApiDoc >, IWebSocketDocBuildTemplate <WebSocketDoc >, IRestDocTemplate , IWebSocketTemplate {
54+ public class JAXRSDocBuildTemplate implements IDocBuildTemplate <ApiDoc >, IWebSocketDocBuildTemplate <WebSocketDoc >, IRestDocTemplate , IWebSocketTemplate {
5855
59- private static final Logger log = Logger .getLogger (JaxrsDocBuildTemplate .class .getName ());
56+ private static final Logger log = Logger .getLogger (JAXRSDocBuildTemplate .class .getName ());
6057
61- /**
62- * api index
63- */
64- private final AtomicInteger atomicInteger = new AtomicInteger (1 );
6558 /**
6659 * headers
6760 */
@@ -71,45 +64,25 @@ public class JaxrsDocBuildTemplate implements IDocBuildTemplate<ApiDoc>, IWebSoc
7164 @ Override
7265 public List <ApiDoc > renderApi (ProjectDocConfigBuilder projectBuilder , Collection <JavaClass > candidateClasses ) {
7366 ApiConfig apiConfig = projectBuilder .getApiConfig ();
74- FrameworkAnnotations frameworkAnnotations = registeredAnnotations ();
7567 this .headers = apiConfig .getRequestHeaders ();
76- List <ApiDoc > apiDocList = new ArrayList <>();
77- int order = 0 ;
78- boolean setCustomOrder = false ;
79- // exclude class is ignore
80- for (JavaClass cls : candidateClasses ) {
81- if (StringUtil .isNotEmpty (apiConfig .getPackageFilters ())) {
82- // from smart config
83- if (!DocUtil .isMatch (apiConfig .getPackageFilters (), cls )) {
84- continue ;
85- }
86- }
87- // from tag
88- DocletTag ignoreTag = cls .getTagByName (DocTags .IGNORE );
89- if (!isEntryPoint (cls , frameworkAnnotations ) || Objects .nonNull (ignoreTag )) {
90- continue ;
91- }
92- String strOrder = JavaClassUtil .getClassTagsValue (cls , DocTags .ORDER , Boolean .TRUE );
93- order ++;
94- if (ValidateUtil .isNonNegativeInteger (strOrder )) {
95- setCustomOrder = true ;
96- order = Integer .parseInt (strOrder );
97- }
98- List <ApiMethodDoc > apiMethodDocs = buildControllerMethod (cls , apiConfig , projectBuilder , frameworkAnnotations );
99- this .handleApiDoc (cls , apiDocList , apiMethodDocs , order , apiConfig .isMd5EncryptedHtmlName ());
100- }
68+ List <ApiReqParam > configApiReqParams = Stream .of (apiConfig .getRequestHeaders (), apiConfig .getRequestParams ()).filter (Objects ::nonNull )
69+ .flatMap (Collection ::stream ).collect (Collectors .toList ());
70+ FrameworkAnnotations frameworkAnnotations = this .registeredAnnotations ();
71+ List <ApiDoc > apiDocList = this .processApiData (projectBuilder , frameworkAnnotations ,
72+ configApiReqParams , new SpringMVCRequestMappingHandler (), new SpringMVCRequestHeaderHandler (), candidateClasses );
10173 // sort
10274 if (apiConfig .isSortByTitle ()) {
10375 Collections .sort (apiDocList );
104- } else if (setCustomOrder ) {
105- // while set custom oder
106- return apiDocList .stream ()
107- .sorted (Comparator .comparing (ApiDoc ::getOrder ))
108- .peek (p -> p .setOrder (atomicInteger .getAndAdd (1 ))).collect (Collectors .toList ());
10976 }
11077 return apiDocList ;
11178 }
11279
80+ @ Override
81+ public List <ApiMethodDoc > buildEntryPointMethod (JavaClass cls , ApiConfig apiConfig , ProjectDocConfigBuilder projectBuilder ,
82+ FrameworkAnnotations frameworkAnnotations , List <ApiReqParam > configApiReqParams , IRequestMappingHandler baseMappingHandler , IHeaderHandler headerHandler ) {
83+ return buildControllerMethod (cls , apiConfig , projectBuilder , frameworkAnnotations );
84+ }
85+
11386 @ Override
11487 public List <WebSocketDoc > renderWebSocketApi (ProjectDocConfigBuilder projectBuilder , Collection <JavaClass > candidateClasses ) {
11588 FrameworkAnnotations frameworkAnnotations = registeredAnnotations ();
@@ -215,7 +188,7 @@ private List<ApiMethodDoc> buildControllerMethod(final JavaClass cls, ApiConfig
215188 }
216189 List <ApiReqParam > allApiReqParams ;
217190 allApiReqParams = apiReqParams ;
218- if (this .headers != null ) {
191+ if (Objects . nonNull ( this .headers ) ) {
219192 allApiReqParams = Stream .of (this .headers , apiReqParams )
220193 .flatMap (Collection ::stream ).distinct ().collect (Collectors .toList ());
221194 }
@@ -234,8 +207,7 @@ private List<ApiMethodDoc> buildControllerMethod(final JavaClass cls, ApiConfig
234207 apiMethodDoc .setRequestHeaders (allApiReqParams );
235208
236209 // build request json
237- ApiRequestExample requestExample = buildReqJson (docJavaMethod , apiMethodDoc , jaxPathMapping .getMethodType (),
238- projectBuilder );
210+ ApiRequestExample requestExample = buildReqJson (docJavaMethod , apiMethodDoc , projectBuilder );
239211 String requestJson = requestExample .getExampleBody ();
240212 // set request example detail
241213 apiMethodDoc .setRequestExample (requestExample );
@@ -406,7 +378,6 @@ private ApiMethodReqParam requestParams(final DocJavaMethod docJavaMethod, Proje
406378 } else {
407379 isRequestBody = true ;
408380 }
409-
410381 boolean required = Boolean .parseBoolean (strRequired );
411382 boolean queryParam = !isRequestBody && !isPathVariable ;
412383 if (JavaClassValidateUtil .isCollection (fullyQualifiedName ) || JavaClassValidateUtil .isArray (fullyQualifiedName )) {
@@ -556,8 +527,8 @@ else if (javaClass.isEnum()) {
556527 .setQueryParams (queryParams );
557528 }
558529
559- private ApiRequestExample buildReqJson (DocJavaMethod javaMethod , ApiMethodDoc apiMethodDoc , String methodType ,
560- ProjectDocConfigBuilder configBuilder ) {
530+ private ApiRequestExample buildReqJson (DocJavaMethod javaMethod , ApiMethodDoc apiMethodDoc , ProjectDocConfigBuilder configBuilder ) {
531+ String methodType = apiMethodDoc . getType ();
561532 JavaMethod method = javaMethod .getJavaMethod ();
562533 Map <String , String > pathParamsMap = new LinkedHashMap <>();
563534 List <DocJavaParameter > parameterList = getJavaParameterList (configBuilder , javaMethod , null );
0 commit comments