├── doc-apis-test ├── src │ ├── test │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── docapis │ │ │ └── test │ │ │ └── TestApplication.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── docapis │ │ └── test │ │ ├── DocPlusApplication.java │ │ ├── model │ │ ├── Document.java │ │ ├── DocQuery.java │ │ └── ApiResult.java │ │ └── controller │ │ └── SampleController.java └── pom.xml ├── doc-apis-core ├── src │ └── main │ │ ├── resources │ │ ├── Java_Entity_Field.tpl │ │ ├── IOS_Model_Field.tpl │ │ ├── img │ │ │ └── logo.png │ │ ├── Java_Entity_Getter.tpl │ │ ├── fonts │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── glyphicons-halflings-regular.ttf │ │ ├── Java_Entity_Setter.tpl │ │ ├── Java_Entity.tpl │ │ ├── IOS_Model.tpl │ │ ├── Code_File.html.tpl │ │ ├── css │ │ │ └── prettify.min.css │ │ ├── message.properties │ │ ├── message_en.properties │ │ ├── message_zh_CN.properties │ │ ├── api-common-catalog.html.ftl │ │ ├── api-doc.md.ftl │ │ ├── api-request-node.html.ftl │ │ ├── api-index.html.ftl │ │ ├── EsPageInfo.java │ │ └── PageInfo.java │ │ └── java │ │ └── com │ │ └── docapis │ │ └── core │ │ ├── ProjectType.java │ │ ├── codegenerator │ │ ├── ICodeBuilder.java │ │ ├── provider │ │ │ ├── ProviderFactory.java │ │ │ ├── DocFieldProvider.java │ │ │ └── DocFieldHelper.java │ │ ├── IFieldProvider.java │ │ ├── ios │ │ │ ├── ModelTemplateProvider.java │ │ │ ├── builder │ │ │ │ ├── ModelBuilder.java │ │ │ │ └── ModelFieldBuilder.java │ │ │ └── ModelCodeGenerator.java │ │ ├── TemplateProvider.java │ │ ├── java │ │ │ ├── JavaTemplateProvider.java │ │ │ ├── builder │ │ │ │ ├── JavaFieldBuilder.java │ │ │ │ ├── JavaClassBuilder.java │ │ │ │ ├── JavaGetterBuilder.java │ │ │ │ └── JavaSetterBuilder.java │ │ │ └── JavaCodeGenerator.java │ │ ├── CodeFileBuilder.java │ │ ├── model │ │ │ └── FieldModel.java │ │ └── CodeGenerator.java │ │ ├── BuildToolTypeEnum.java │ │ ├── constant │ │ ├── ChangeFlag.java │ │ └── CoreConstants.java │ │ ├── parser │ │ ├── RequestMethod.java │ │ ├── HeaderNode.java │ │ ├── MockNode.java │ │ ├── ResponseNode.java │ │ ├── GenericControllerParser.java │ │ ├── ParamNode.java │ │ ├── JFinalControllerParser.java │ │ ├── PlayControllerParser.java │ │ ├── GenericNode.java │ │ ├── FieldNode.java │ │ ├── ControllerNode.java │ │ ├── PlayRoutesParser.java │ │ ├── RequestNode.java │ │ ├── ClassNode.java │ │ └── JFinalRoutesParser.java │ │ ├── IPluginSupport.java │ │ ├── IResponseWrapper.java │ │ ├── exception │ │ ├── ConfigException.java │ │ └── JavaFileNotFoundException.java │ │ ├── doc │ │ ├── IControllerDocBuilder.java │ │ ├── Link.java │ │ ├── HtmlDocGenerator.java │ │ ├── HtmlControllerDocBuilder.java │ │ └── AbsDocGenerator.java │ │ ├── plugin │ │ ├── rap │ │ │ ├── ActionTypeEnum.java │ │ │ ├── DeleteActionFrom.java │ │ │ ├── ModelResponse.java │ │ │ ├── ProjectForm.java │ │ │ ├── Page.java │ │ │ ├── Module.java │ │ │ ├── Action.java │ │ │ ├── Parameter.java │ │ │ ├── DataType.java │ │ │ ├── RapSupportPlugin.java │ │ │ └── Project.java │ │ └── markdown │ │ │ └── MarkdownDocPlugin.java │ │ ├── DocIgnore.java │ │ ├── RapMock.java │ │ ├── I18n.java │ │ ├── DocApi.java │ │ ├── http │ │ ├── DHttpRequest.java │ │ ├── DHttpResponse.java │ │ └── DHttpUtils.java │ │ ├── LogUtils.java │ │ ├── Resources.java │ │ ├── CacheUtils.java │ │ ├── Docs.java │ │ └── DocsConfig.java └── pom.xml ├── doc-apis-starter ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ ├── spring │ │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── docapis │ │ └── starter │ │ ├── config │ │ ├── CorsConfig.java │ │ └── AutoConfig.java │ │ └── property │ │ ├── CorsConfigProperties.java │ │ └── DocPlusConfigProperties.java └── pom.xml ├── .gitignore ├── pom.xml ├── README_ZH.md └── README.md /doc-apis-test/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc-apis-test/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/Java_Entity_Field.tpl: -------------------------------------------------------------------------------- 1 | private ${FIELD_TYPE} ${FIELD_NAME}; //${COMMENT} -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/IOS_Model_Field.tpl: -------------------------------------------------------------------------------- 1 | //${COMMENT} 2 | @property (nonatomic, ${ASSIGN}) ${FIELD_TYPE} ${FIELD_NAME}; -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizuda/doc-apis/HEAD/doc-apis-core/src/main/resources/img/logo.png -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/Java_Entity_Getter.tpl: -------------------------------------------------------------------------------- 1 | public ${FIELD_TYPE} get${CASE_FIELD_NAME}(){ 2 | return ${FIELD_NAME}; 3 | } 4 | -------------------------------------------------------------------------------- /doc-apis-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | com.docapis.starter.config.AutoConfig 2 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizuda/doc-apis/HEAD/doc-apis-core/src/main/resources/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/Java_Entity_Setter.tpl: -------------------------------------------------------------------------------- 1 | public void set${CASE_FIELD_NAME}(${FIELD_TYPE} ${FIELD_NAME}){ 2 | this.${FIELD_NAME} = ${FIELD_NAME}; 3 | } 4 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aizuda/doc-apis/HEAD/doc-apis-core/src/main/resources/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /doc-apis-core/src/main/resources/Java_Entity.tpl: -------------------------------------------------------------------------------- 1 |
2 | public class ${CLASS_NAME} implements Serializable{
3 |
4 | ${FIELDS}
5 | ${METHODS}
6 | }
7 |
8 |
9 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/IOS_Model.tpl:
--------------------------------------------------------------------------------
1 | 2 |12 | -------------------------------------------------------------------------------- /doc-apis-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Auto Configure 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | com.docapis.starter.config.AutoConfig,\ 4 | com.docapis.starter.config.CorsConfig 5 | 6 | 7 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/ProjectType.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core; 2 | 3 | /** 4 | * project type 5 | *3 | #import 11 |; 4 | 5 | @interface ${CLASS_NAME} : NSObject 6 | 7 | ${FIELDS} 8 | 9 | @end 10 |
6 | * licence Apache 2.0, from japidoc 7 | **/ 8 | public enum ProjectType { 9 | SPRING, PLAY, JFINAL, GENERIC; 10 | } 11 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/codegenerator/ICodeBuilder.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core.codegenerator; 2 | 3 | /** 4 | * code builder 5 | *
6 | * licence Apache 2.0, from japidoc 7 | **/ 8 | public interface ICodeBuilder { 9 | String build(); 10 | } 11 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/BuildToolTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core; 2 | 3 | /** 4 | * build tool type enum 5 | *
6 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated 7 | **/ 8 | public enum BuildToolTypeEnum { 9 | GRADLE, MAVEN, UNKNOWN 10 | } 11 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/constant/ChangeFlag.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core.constant; 2 | 3 | /** 4 | * changeFlag 5 | *
6 | * licence Apache 2.0, from japidoc 7 | **/ 8 | public interface ChangeFlag { 9 | Byte SAME = 0; 10 | Byte NEW = 1; 11 | Byte MODIFY = 2; 12 | } 13 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/parser/RequestMethod.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core.parser; 2 | 3 | /** 4 | * request method 5 | *
6 | * licence Apache 2.0, from japidoc 7 | **/ 8 | public enum RequestMethod { 9 | 10 | GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE 11 | 12 | } 13 | -------------------------------------------------------------------------------- /doc-apis-core/src/main/java/com/docapis/core/IPluginSupport.java: -------------------------------------------------------------------------------- 1 | package com.docapis.core; 2 | 3 | import com.docapis.core.parser.ControllerNode; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * plugin support 9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public interface IPluginSupport {
13 |
14 | void execute(List
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public interface IResponseWrapper {
13 | Map
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class ConfigException extends RuntimeException {
9 |
10 | public ConfigException() {
11 | }
12 |
13 | public ConfigException(String message) {
14 | super(message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/HeaderNode.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | /**
4 | * header node
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class HeaderNode {
9 |
10 | private String name;
11 | private String value;
12 |
13 | public HeaderNode(String name, String value) {
14 | this.name = name;
15 | this.value = value;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/doc/IControllerDocBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.doc;
2 |
3 | import com.docapis.core.parser.ControllerNode;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | * controller doc builder
9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public interface IControllerDocBuilder {
13 |
14 | String buildDoc(ControllerNode controllerNode) throws IOException;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### git ignore
2 | # Compiled class file
3 | *.class
4 |
5 | # Log file
6 | *.log
7 |
8 | # BlueJ files
9 | *.ctxt
10 |
11 | # Mobile Tools for Java (J2ME)
12 | .mtj.tmp/
13 |
14 | # Package Files #
15 | *.jar
16 | *.war
17 | *.nar
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 | *.iml
23 |
24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25 | hs_err_pid*
26 |
27 | .idea/
28 | target/
29 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/plugin/rap/ActionTypeEnum.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.plugin.rap;
2 |
3 | /**
4 | * action type
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | enum ActionTypeEnum {
9 |
10 | GET("1"),
11 | POST("2"),
12 | PUT("3"),
13 | DELETE("4");
14 |
15 | public final String type;
16 |
17 | ActionTypeEnum(String type) {
18 | this.type = type;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/provider/ProviderFactory.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.provider;
2 |
3 |
4 | import com.docapis.core.codegenerator.IFieldProvider;
5 |
6 | /**
7 | * provider factory
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class ProviderFactory {
12 |
13 | public static IFieldProvider createProvider() {
14 | return new DocFieldProvider();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/IFieldProvider.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator;
2 |
3 |
4 | import com.docapis.core.codegenerator.model.FieldModel;
5 | import com.docapis.core.parser.ClassNode;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * field provider
11 | *
12 | * licence Apache 2.0, from japidoc
13 | **/
14 | public interface IFieldProvider {
15 | List
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class JavaFileNotFoundException extends RuntimeException {
9 |
10 | public JavaFileNotFoundException() {
11 | }
12 |
13 | public JavaFileNotFoundException(String message) {
14 | super(message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/Code_File.html.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 | * Copyright © 2024 xpc1024 All Rights Reserved
10 | **/
11 | @SpringBootApplication
12 | public class TestApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(TestApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/DocIgnore.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * DocIgnore annotation
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | @Retention(RetentionPolicy.SOURCE)
14 | @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
15 | public @interface DocIgnore {
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-test/src/main/java/com/docapis/test/DocPlusApplication.java:
--------------------------------------------------------------------------------
1 | package com.docapis.test;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 启动类
8 | *
9 | * Copyright © 2024 xpc1024 All Rights Reserved
10 | **/
11 | @SpringBootApplication
12 | public class DocPlusApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(DocPlusApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/RapMock.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * RapMock annotation
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | @Retention(RetentionPolicy.SOURCE)
14 | @Target({ElementType.FIELD})
15 | public @interface RapMock {
16 |
17 | String limit() default "";
18 |
19 | String value() default "";
20 | }
21 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/ios/ModelTemplateProvider.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.ios;
2 |
3 |
4 | import com.docapis.core.codegenerator.TemplateProvider;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * 模型目标构造
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | public class ModelTemplateProvider {
14 |
15 | public String provideTemplateForName(String templateName) throws IOException {
16 | return TemplateProvider.provideTemplateForName(templateName);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/TemplateProvider.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator;
2 |
3 |
4 | import com.docapis.core.Resources;
5 | import com.docapis.core.Utils;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * template provider
11 | *
12 | * licence Apache 2.0, from japidoc
13 | **/
14 | public class TemplateProvider {
15 | public static String provideTemplateForName(String templateName) throws IOException {
16 | return Utils.streamToString(Resources.getCodeTemplateFile(templateName));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/JavaTemplateProvider.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java;
2 |
3 |
4 | import com.docapis.core.codegenerator.TemplateProvider;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * java template provider
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | public class JavaTemplateProvider {
14 |
15 | public String provideTemplateForName(String templateName) throws IOException {
16 | return TemplateProvider.provideTemplateForName(templateName);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/MockNode.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | /**
4 | * mock node
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class MockNode {
9 |
10 | private String limit;
11 | private String value;
12 |
13 | public String getLimit() {
14 | return limit;
15 | }
16 |
17 | public void setLimit(String limit) {
18 | this.limit = limit;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/plugin/rap/DeleteActionFrom.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.plugin.rap;
2 |
3 | /**
4 | * delete action from
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | class DeleteActionFrom {
9 |
10 | private String className;
11 | private Integer id;
12 |
13 | public String getClassName() {
14 | return className;
15 | }
16 |
17 | public void setClassName(String className) {
18 | this.className = className;
19 | }
20 |
21 | public Integer getId() {
22 | return id;
23 | }
24 |
25 | public void setId(Integer id) {
26 | this.id = id;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/I18n.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import java.util.Locale;
4 | import java.util.ResourceBundle;
5 |
6 | /**
7 | * i18n
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class I18n {
12 |
13 | private ResourceBundle resourceBundle;
14 |
15 | public I18n() {
16 | this.resourceBundle = ResourceBundle.getBundle("message", Locale.getDefault());
17 | }
18 |
19 | public I18n(Locale locale) {
20 | this.resourceBundle = ResourceBundle.getBundle("message", locale);
21 | }
22 |
23 | public String getMessage(String name) {
24 | return resourceBundle.getString(name);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/doc/Link.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.doc;
2 |
3 | /**
4 | * link
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | class Link {
9 | private String name;
10 | private String url;
11 |
12 | public Link(String name, String url) {
13 | this.name = name;
14 | this.url = url;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public String getUrl() {
26 | return url;
27 | }
28 |
29 | public void setUrl(String url) {
30 | this.url = url;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/css/prettify.min.css:
--------------------------------------------------------------------------------
1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/message.properties:
--------------------------------------------------------------------------------
1 | catalog=catalog
2 | requestUrl=request url
3 | requestParameters=request parameter
4 | requestBody=request body
5 | parameterName=parameter name
6 | parameterType=parameter type
7 | parameterNeed=must
8 | description=description
9 | responseResult=response
10 | searchPlaceholder=search api
11 | deprecated=deprecated
12 | yes=Y
13 | no=N
14 | doc.generate.tip=This documentation is generated by doc-apis
15 | author=author
16 | new=New
17 | modify=Modify
18 | currentVersion=current version
19 | lastVersion=last version
20 | classificationLevel=classification level
21 | adv=Sponsorship advertising space cooperation Mail: xpc@dromara.org
22 | advLink=https://en.doc-apis.com/pages/top888/
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/message_en.properties:
--------------------------------------------------------------------------------
1 | catalog=catalog
2 | requestUrl=request url
3 | requestParameters=request parameter
4 | requestBody=request body
5 | parameterName=parameter name
6 | parameterType=parameter type
7 | parameterNeed=must
8 | description=description
9 | responseResult=response
10 | searchPlaceholder=search api
11 | deprecated=deprecated
12 | yes=Y
13 | no=N
14 | doc.generate.tip=This documentation is generated by doc-apis
15 | author=author
16 | new=New
17 | modify=Modify
18 | currentVersion=current version
19 | lastVersion=last version
20 | classificationLevel=classification level
21 | adv=Sponsorship advertising space cooperation Mail: xpc@dromara.org
22 | advLink=https://en.doc-apis.com/pages/top888/
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/DocApi.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * DocApi annotation
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | @Retention(RetentionPolicy.SOURCE)
14 | @Target({ElementType.TYPE, ElementType.METHOD})
15 | public @interface DocApi {
16 |
17 | Class> value() default Null.class;
18 |
19 | Class> result() default Null.class;
20 |
21 | String stringResult() default "";
22 |
23 | String url() default "";
24 |
25 | String method() default "get";
26 |
27 | final class Null {
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/plugin/rap/ModelResponse.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.plugin.rap;
2 |
3 | /**
4 | * model response
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | class ModelResponse {
9 |
10 | private int code;
11 | private String msg;
12 | private Project model;
13 |
14 | public int getCode() {
15 | return code;
16 | }
17 |
18 | public void setCode(int code) {
19 | this.code = code;
20 | }
21 |
22 | public String getMsg() {
23 | return msg;
24 | }
25 |
26 | public void setMsg(String msg) {
27 | this.msg = msg;
28 | }
29 |
30 | public Project getModel() {
31 | return model;
32 | }
33 |
34 | public void setModel(Project model) {
35 | this.model = model;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/resources/message_zh_CN.properties:
--------------------------------------------------------------------------------
1 | catalog=\u76ee\u5f55
2 | requestUrl=\u8bf7\u6c42URL
3 | requestParameters=\u8bf7\u6c42\u53c2\u6570
4 | requestBody=\u8bf7\u6c42\u4f53
5 | parameterName=\u53c2\u6570\u540d
6 | parameterType=\u7c7b\u578b
7 | parameterNeed=\u5fc5\u987b
8 | description=\u63cf\u8ff0
9 | responseResult=\u8fd4\u56de\u7ed3\u679c
10 | searchPlaceholder=\u641c\u7d22\u63a5\u53e3
11 | deprecated=\u8fc7\u671f
12 | yes=\u662f
13 | no=\u5426
14 | doc.generate.tip=\u672c\u6587\u6863\u7531doc-apis\u751f\u6210
15 | author=\u4f5c\u8005
16 | new=\u65b0\u589e
17 | modify=\u4fee\u6539
18 | currentVersion=\u5f53\u524d\u7248\u672c
19 | lastVersion=\u4e0a\u4e00\u7248\u672c
20 | classificationLevel=\u5BC6\u7EA7
21 | adv=\u8d5e\u52a9\u5546\u5e7f\u544a\u4f4d \u5408\u4f5c Mail:xpc@dromara.org
22 | advLink=https://www.doc-apis.com/pages/top888/
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/CodeFileBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator;
2 |
3 | /**
4 | * code file builder
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class CodeFileBuilder implements ICodeBuilder {
9 |
10 | private String fileName;
11 | private String codeBody;
12 | private String codeTemplate;
13 |
14 | public CodeFileBuilder(String fileName, String codeBody, String codeTemplate) {
15 | super();
16 | this.fileName = fileName;
17 | this.codeBody = codeBody;
18 | this.codeTemplate = codeTemplate;
19 | }
20 |
21 | public String build() {
22 | codeTemplate = codeTemplate.replace("${FILE_NAME}", fileName);
23 | codeTemplate = codeTemplate.replace("${MODEL_LIST}", codeBody);
24 | return codeTemplate;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/doc-apis-test/src/main/java/com/docapis/test/model/Document.java:
--------------------------------------------------------------------------------
1 | package com.docapis.test.model;
2 |
3 | /**
4 | * 文档数据模型
5 | *
6 | * Copyright © 2024 xpc1024 All Rights Reserved
7 | **/
8 | public class Document {
9 | /**
10 | * 主键
11 | */
12 | private Long id;
13 | /**
14 | * 文档标题
15 | */
16 | private String title;
17 | /**
18 | * 文档内容
19 | */
20 | private String content;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Long id) {
27 | this.id = id;
28 | }
29 |
30 | public String getTitle() {
31 | return title;
32 | }
33 |
34 | public void setTitle(String title) {
35 | this.title = title;
36 | }
37 |
38 | public String getContent() {
39 | return content;
40 | }
41 |
42 | public void setContent(String content) {
43 | this.content = content;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/ios/builder/ModelBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.ios.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 |
6 | /**
7 | * 模型构造
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class ModelBuilder implements ICodeBuilder {
12 |
13 | private String modelTemplate;
14 | private String objectName;
15 | private String properties;
16 |
17 |
18 | public ModelBuilder(String modelTemplate, String objectName, String properties) {
19 | super();
20 | this.modelTemplate = modelTemplate;
21 | this.objectName = objectName;
22 | this.properties = properties;
23 | }
24 |
25 | @Override
26 | public String build() {
27 | modelTemplate = modelTemplate.replace("${CLASS_NAME}", objectName);
28 | modelTemplate = modelTemplate.replace("${FIELDS}", properties);
29 | return modelTemplate;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/doc-apis-test/src/main/java/com/docapis/test/model/DocQuery.java:
--------------------------------------------------------------------------------
1 | package com.docapis.test.model;
2 |
3 | import javax.validation.constraints.NotNull;
4 |
5 | /**
6 | * 文档查询参数
7 | *
8 | * Copyright © 2024 xpc1024 All Rights Reserved
9 | **/
10 |
11 | public class DocQuery {
12 | /**
13 | * 标题
14 | */
15 | private String title;
16 | /**
17 | * 页码
18 | */
19 | @NotNull
20 | private Integer pageNum;
21 | /**
22 | * 每页条数
23 | */
24 | @NotNull
25 | private Integer pageSize;
26 |
27 | public String getTitle() {
28 | return title;
29 | }
30 |
31 | public void setTitle(String title) {
32 | this.title = title;
33 | }
34 |
35 | public Integer getPageNum() {
36 | return pageNum;
37 | }
38 |
39 | public void setPageNum(Integer pageNum) {
40 | this.pageNum = pageNum;
41 | }
42 |
43 | public Integer getPageSize() {
44 | return pageSize;
45 | }
46 |
47 | public void setPageSize(Integer pageSize) {
48 | this.pageSize = pageSize;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/builder/JavaFieldBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 | import com.docapis.core.codegenerator.model.FieldModel;
6 |
7 | /**
8 | * java field code builder
9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public class JavaFieldBuilder implements ICodeBuilder {
13 |
14 | private String fieldTemplate;
15 | private FieldModel entryFieldModel;
16 |
17 | public JavaFieldBuilder(String fieldTemplate, FieldModel entryFieldModel) {
18 | this.fieldTemplate = fieldTemplate;
19 | this.entryFieldModel = entryFieldModel;
20 | }
21 |
22 | @Override
23 | public String build() {
24 | fieldTemplate = fieldTemplate.replace("${FIELD_TYPE}", entryFieldModel.getFieldType());
25 | fieldTemplate = fieldTemplate.replace("${FIELD_NAME}", entryFieldModel.getFieldName());
26 | fieldTemplate = fieldTemplate.replace("${COMMENT}", entryFieldModel.getComment());
27 | return fieldTemplate + "\n";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/builder/JavaClassBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 |
6 | /**
7 | * java class builder
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class JavaClassBuilder implements ICodeBuilder {
12 |
13 | private String className;
14 | private String mFieldCode;
15 | private String mMethodCode;
16 | private String entryClassTemplate;
17 |
18 | public JavaClassBuilder(String entryClassTemplate, String className, String mFieldCode, String mMethodCode) {
19 | this.className = className;
20 | this.mFieldCode = mFieldCode;
21 | this.mMethodCode = mMethodCode;
22 | this.entryClassTemplate = entryClassTemplate;
23 | }
24 |
25 | @Override
26 | public String build() {
27 | entryClassTemplate = entryClassTemplate.replace("${CLASS_NAME}", className);
28 | entryClassTemplate = entryClassTemplate.replace("${FIELDS}", mFieldCode);
29 | entryClassTemplate = entryClassTemplate.replace("${METHODS}", mMethodCode);
30 | return entryClassTemplate;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/ResponseNode.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.docapis.core.Utils;
5 |
6 | /**
7 | * response node
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class ResponseNode extends ClassNode {
12 |
13 | private RequestNode requestNode;
14 |
15 | private String stringResult;
16 |
17 | public RequestNode getRequestNode() {
18 | return requestNode;
19 | }
20 |
21 | public void setRequestNode(RequestNode requestNode) {
22 | this.requestNode = requestNode;
23 | }
24 |
25 | public String getStringResult() {
26 | return stringResult;
27 | }
28 |
29 | public void setStringResult(String stringResult) {
30 | this.stringResult = stringResult;
31 | }
32 |
33 | @Override
34 | public String toJsonApi() {
35 | if (stringResult != null) {
36 | try {
37 | return Utils.toPrettyJson((JSONObject.parse(stringResult)));
38 | } catch (Exception ex) {
39 | // do nothing
40 | return stringResult;
41 | }
42 | }
43 | return super.toJsonApi();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/builder/JavaGetterBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 | import com.docapis.core.codegenerator.model.FieldModel;
6 |
7 | /**
8 | * java getter builder
9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public class JavaGetterBuilder implements ICodeBuilder {
13 |
14 | private String getterTemplate;
15 | private FieldModel entryFieldModel;
16 |
17 | public JavaGetterBuilder(String getterTemplate, FieldModel entryFieldModel) {
18 | this.getterTemplate = getterTemplate;
19 | this.entryFieldModel = entryFieldModel;
20 | }
21 |
22 | @Override
23 | public String build() {
24 | getterTemplate = getterTemplate.replace("${CASE_FIELD_NAME}", entryFieldModel.getCaseFieldName());
25 | getterTemplate = getterTemplate.replace("${FIELD_NAME}", entryFieldModel.getFieldName());
26 | getterTemplate = getterTemplate.replace("${FIELD_TYPE}", entryFieldModel.getFieldType());
27 | getterTemplate = getterTemplate.replace("${REMOTE_FIELD_NAME}", entryFieldModel.getRemoteFieldName());
28 | return getterTemplate + "\n";
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/builder/JavaSetterBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 | import com.docapis.core.codegenerator.model.FieldModel;
6 |
7 | /**
8 | * java setter builder
9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public class JavaSetterBuilder implements ICodeBuilder {
13 |
14 | private String setterTemplate;
15 | private FieldModel entryFieldModel;
16 |
17 | public JavaSetterBuilder(String setterTemplate, FieldModel entryFieldModel) {
18 | this.setterTemplate = setterTemplate;
19 | this.entryFieldModel = entryFieldModel;
20 | }
21 |
22 | @Override
23 | public String build() {
24 | setterTemplate = setterTemplate.replace("${REMOTE_FIELD_NAME}", entryFieldModel.getRemoteFieldName());
25 | setterTemplate = setterTemplate.replace("${CASE_FIELD_NAME}", entryFieldModel.getCaseFieldName());
26 | setterTemplate = setterTemplate.replace("${FIELD_NAME}", entryFieldModel.getFieldName());
27 | setterTemplate = setterTemplate.replace("${FIELD_TYPE}", entryFieldModel.getFieldType());
28 | return setterTemplate + "\n";
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/GenericControllerParser.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | import com.docapis.core.DocApi;
4 | import com.docapis.core.Utils;
5 | import com.github.javaparser.ast.body.MethodDeclaration;
6 | import com.github.javaparser.ast.expr.NormalAnnotationExpr;
7 |
8 | /**
9 | * generic controller parser
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | public class GenericControllerParser extends AbsControllerParser {
14 |
15 | @Override
16 | protected void afterHandleMethod(RequestNode requestNode, MethodDeclaration md) {
17 | md.getAnnotationByName(DocApi.class.getSimpleName()).ifPresent(an -> {
18 | if (an instanceof NormalAnnotationExpr) {
19 | ((NormalAnnotationExpr) an).getPairs().forEach(p -> {
20 | String n = p.getNameAsString();
21 | if (n.equals("url")) {
22 | requestNode.setUrl(Utils.removeQuotations(p.getValue().toString()));
23 | } else if (n.equals("method")) {
24 | requestNode.addMethod(Utils.removeQuotations(p.getValue().toString()));
25 | }
26 | });
27 | }
28 | });
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/ios/builder/ModelFieldBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.ios.builder;
2 |
3 |
4 | import com.docapis.core.codegenerator.ICodeBuilder;
5 | import com.docapis.core.codegenerator.model.FieldModel;
6 |
7 | /**
8 | * 模型字段构造
9 | *
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public class ModelFieldBuilder implements ICodeBuilder {
13 |
14 | private String modelFieldTemplate;
15 | private FieldModel entryFieldModel;
16 |
17 | public ModelFieldBuilder(String modelFieldTemplate, FieldModel entryFieldModel) {
18 | super();
19 | this.modelFieldTemplate = modelFieldTemplate;
20 | this.entryFieldModel = entryFieldModel;
21 | }
22 |
23 | @Override
24 | public String build() {
25 | modelFieldTemplate = modelFieldTemplate.replace("${FIELD_TYPE}", entryFieldModel.getIFieldType());
26 | modelFieldTemplate = modelFieldTemplate.replace("${FIELD_NAME}", entryFieldModel.getFieldName());
27 | modelFieldTemplate = modelFieldTemplate.replace("${COMMENT}", entryFieldModel.getComment());
28 | modelFieldTemplate = modelFieldTemplate.replace("${ASSIGN}", entryFieldModel.getAssign());
29 | return modelFieldTemplate + "\n";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/doc-apis-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class DHttpRequest {
12 |
13 | private String url;
14 | private boolean autoRedirect = true; //自动重定向
15 | private Map
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class ParamNode {
9 |
10 | private String name;
11 | private String type;
12 | private Boolean required = Boolean.FALSE;
13 | private String description;
14 | private Boolean jsonBody = Boolean.FALSE;// when true ,the json body set to description
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | public String getType() {
25 | return type;
26 | }
27 |
28 | public void setType(String type) {
29 | this.type = type;
30 | }
31 |
32 |
33 | public String getDescription() {
34 | return description;
35 | }
36 |
37 | public void setDescription(String description) {
38 | this.description = description;
39 | }
40 |
41 | public Boolean getRequired() {
42 | return required;
43 | }
44 |
45 | public void setRequired(Boolean required) {
46 | this.required = required;
47 | }
48 |
49 | public Boolean getJsonBody() {
50 | return jsonBody;
51 | }
52 |
53 | public void setJsonBody(Boolean jsonBody) {
54 | this.jsonBody = jsonBody;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import java.io.IOException;
4 | import java.util.logging.FileHandler;
5 | import java.util.logging.Level;
6 | import java.util.logging.Logger;
7 | import java.util.logging.SimpleFormatter;
8 |
9 | /**
10 | * log utils
11 | *
12 | * licence Apache 2.0, from japidoc
13 | **/
14 | public class LogUtils {
15 |
16 | private static final Logger LOGGER = Logger.getGlobal();
17 |
18 | static {
19 | try {
20 | FileHandler fileHandler = new FileHandler(DocContext.getLogFile().getAbsolutePath());
21 | fileHandler.setFormatter(new SimpleFormatter());
22 | fileHandler.setLevel(Level.ALL);
23 | LOGGER.addHandler(fileHandler);
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 |
29 | public static void info(String message, Object... args) {
30 | LOGGER.info(String.format(message, args));
31 | }
32 |
33 | public static void warn(String message, Object... args) {
34 | LOGGER.warning(String.format(message, args));
35 | }
36 |
37 | public static void error(String message, Object... args) {
38 | LOGGER.severe(String.format(message, args));
39 | }
40 |
41 | public static void error(String message, Throwable e) {
42 | LOGGER.log(Level.SEVERE, message, e);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/JFinalControllerParser.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | import com.docapis.core.Utils;
4 | import com.github.javaparser.ast.body.MethodDeclaration;
5 | import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr;
6 |
7 | import java.util.Arrays;
8 |
9 | /**
10 | * jFinal controller parser
11 | *
12 | * licence Apache 2.0, from japidoc
13 | **/
14 | public class JFinalControllerParser extends AbsControllerParser {
15 |
16 | @Override
17 | protected void afterHandleMethod(RequestNode requestNode, MethodDeclaration md) {
18 | String methodName = md.getNameAsString();
19 | requestNode.setUrl(getUrl(methodName));
20 | md.getAnnotationByName("ActionKey").ifPresent(an -> {
21 | if (an instanceof SingleMemberAnnotationExpr) {
22 | String url = ((SingleMemberAnnotationExpr) an).getMemberValue().toString();
23 | requestNode.setMethod(Arrays.asList(RequestMethod.GET.name(), RequestMethod.POST.name()));
24 | requestNode.setUrl(Utils.removeQuotations(url));
25 | return;
26 | }
27 | });
28 | }
29 |
30 | private String getUrl(String methodName) {
31 | JFinalRoutesParser.RouteNode routeNode = JFinalRoutesParser.INSTANCE.getRouteNode(getControllerFile().getAbsolutePath());
32 | return routeNode == null ? "" : routeNode.basicUrl + "/" + methodName;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/http/DHttpResponse.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.http;
2 |
3 |
4 | import com.docapis.core.Utils;
5 |
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * http response
13 | *
14 | * licence Apache 2.0, from japidoc
15 | **/
16 | public class DHttpResponse {
17 |
18 | private int code;
19 | private InputStream stream;
20 | private Map
10 | * licence Apache 2.0, from japidoc
11 | **/
12 | public class PlayControllerParser extends AbsControllerParser {
13 |
14 | @Override
15 | protected void afterHandleMethod(RequestNode requestNode, MethodDeclaration md) {
16 | PlayRoutesParser.RouteNode routeNode = PlayRoutesParser.INSTANCE.getRouteNode(getControllerFile(), md.getNameAsString());
17 | if (routeNode == null) {
18 | return;
19 | }
20 |
21 | String method = routeNode.method.toUpperCase();
22 | if ("*".equals(method)) {
23 | requestNode.setMethod(Arrays.asList(RequestMethod.GET.name(), RequestMethod.POST.name()));
24 | } else {
25 | requestNode.addMethod(RequestMethod.valueOf(method).name());
26 | }
27 |
28 | requestNode.setUrl(routeNode.routeUrl);
29 |
30 | md.getParameters().forEach(p -> {
31 | String paraName = p.getName().asString();
32 | ParamNode paramNode = requestNode.getParamNodeByName(paraName);
33 | if (paramNode != null) {
34 | p.getAnnotationByName("Required").ifPresent(r -> {
35 | paramNode.setRequired(true);
36 | });
37 | }
38 | });
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/plugin/rap/ProjectForm.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.plugin.rap;
2 |
3 | /**
4 | * project form
5 | *
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | class ProjectForm {
9 |
10 | private Integer id;
11 | private String projectData;
12 | private String deletedObjectListData;
13 | private String versionPosition;
14 | private String description;
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public String getProjectData() {
25 | return projectData;
26 | }
27 |
28 | public void setProjectData(String projectData) {
29 | this.projectData = projectData;
30 | }
31 |
32 | public String getDeletedObjectListData() {
33 | return deletedObjectListData;
34 | }
35 |
36 | public void setDeletedObjectListData(String deletedObjectListData) {
37 | this.deletedObjectListData = deletedObjectListData;
38 | }
39 |
40 | public String getVersionPosition() {
41 | return versionPosition == null ? "4" : versionPosition;
42 | }
43 |
44 | public void setVersionPosition(String versionPosition) {
45 | this.versionPosition = versionPosition;
46 | }
47 |
48 | public String getDescription() {
49 | return description;
50 | }
51 |
52 | public void setDescription(String description) {
53 | this.description = description;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/doc-apis-starter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 | * licence Apache 2.0, from japidoc
17 | **/
18 | public class DocFieldProvider implements IFieldProvider {
19 |
20 | @Override
21 | public List
6 | * Copyright © 2024 xpc1024 All Rights Reserved
7 | **/
8 | public class ApiResult
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | class Page {
12 |
13 | private int id;
14 | private String name;
15 | private String introduction;
16 | private Module module;
17 | private Set
12 | * licence Apache 2.0, from japidoc
13 | **/
14 | public class GenericNode {
15 |
16 | private Type classType;
17 | private Class modelClass;
18 | private String placeholder;
19 | private File fromJavaFile;
20 | private List
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | class Module {
12 |
13 | public static final String NAME = "API List";
14 |
15 | private int id;
16 | private int projectId;
17 | private String name;
18 | private String introduction;
19 | private Project project;
20 | private Set
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class FieldModel {
12 |
13 | private String remoteFieldName;
14 | private String caseFieldName;
15 | private String fieldName;
16 | private String fieldType;
17 | private String comment;
18 |
19 | public String getFieldName() {
20 | return fieldName;
21 | }
22 |
23 | public void setFieldName(String fieldName) {
24 | this.fieldName = fieldName;
25 | }
26 |
27 | public String getFieldType() {
28 | return fieldType;
29 | }
30 |
31 | public String getIFieldType() {
32 | return DocFieldHelper.getIosFieldType(fieldType);
33 | }
34 |
35 | public void setFieldType(String fieldType) {
36 | this.fieldType = fieldType;
37 | }
38 |
39 | public String getRemoteFieldName() {
40 | return remoteFieldName;
41 | }
42 |
43 | public void setRemoteFieldName(String remoteFieldName) {
44 | this.remoteFieldName = remoteFieldName;
45 | }
46 |
47 | public String getCaseFieldName() {
48 | return caseFieldName;
49 | }
50 |
51 | public void setCaseFieldName(String caseFieldName) {
52 | this.caseFieldName = caseFieldName;
53 | }
54 |
55 | public String getComment() {
56 | return comment == null ? "" : comment;
57 | }
58 |
59 | public void setComment(String comment) {
60 | this.comment = comment;
61 | }
62 |
63 | public String getAssign() {
64 | if (fieldType != null && fieldType.equalsIgnoreCase("string")) {
65 | return "assign";
66 | } else {
67 | return "strong";
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | public class FieldNode {
9 |
10 | private String name;
11 | private String type;
12 | private String description;
13 | private MockNode mockNode;
14 | private ClassNode childNode;
15 | private ClassNode classNode;
16 | private Boolean loopNode = Boolean.FALSE;
17 | private Boolean notNull = Boolean.FALSE;
18 |
19 | public Boolean getLoopNode() {
20 | return loopNode;
21 | }
22 |
23 | public void setLoopNode(Boolean loopNode) {
24 | this.loopNode = loopNode;
25 | }
26 |
27 | public Boolean getNotNull() {
28 | return notNull;
29 | }
30 |
31 | public void setNotNull(Boolean notNull) {
32 | this.notNull = notNull;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public String getType() {
44 | return type;
45 | }
46 |
47 | public void setType(String type) {
48 | this.type = type;
49 | }
50 |
51 | public String getDescription() {
52 | return description;
53 | }
54 |
55 | public void setDescription(String description) {
56 | this.description = description;
57 | }
58 |
59 | public MockNode getMockNode() {
60 | return mockNode;
61 | }
62 |
63 | public void setMockNode(MockNode mockNode) {
64 | this.mockNode = mockNode;
65 | }
66 |
67 | public ClassNode getChildNode() {
68 | return childNode;
69 | }
70 |
71 | public void setChildNode(ClassNode childNode) {
72 | this.childNode = childNode;
73 | }
74 |
75 | public ClassNode getClassNode() {
76 | return classNode;
77 | }
78 |
79 | public void setClassNode(ClassNode classNode) {
80 | this.classNode = classNode;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/doc-apis-test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 | * Copyright © 2024 xpc1024 All Rights Reserved
18 | **/
19 | @Configuration
20 | @EnableWebMvc
21 | @ConditionalOnProperty(prefix = "doc-apis.corsConfig", name = {"allowCors"}, havingValue = "true", matchIfMissing = true)
22 | public class CorsConfig implements WebMvcConfigurer {
23 | @Autowired
24 | private DocPlusConfigProperties docPlusConfigProperties;
25 |
26 | @Override
27 | public void addCorsMappings(CorsRegistry registry) {
28 | CorsConfigProperties config = docPlusConfigProperties.getCorsConfig();
29 | String[] allowedOriginPatterns = config.getAllowedOriginPatterns().split(COMMA_SIGN);
30 | String[] allowedMethods = config.getAllowedMethods().split(COMMA_SIGN);
31 | String[] allowedHeaders = config.getAllowedHeaders().split(COMMA_SIGN);
32 | registry.addMapping(config.getPathPattern())
33 | // 设置允许跨域请求的域名
34 | .allowedOriginPatterns(allowedOriginPatterns)
35 | // 设置允许的方法
36 | .allowedMethods(allowedMethods)
37 | // 允许的请求头
38 | .allowedHeaders(allowedHeaders)
39 | // 跨域允许时间
40 | .maxAge(config.getMaxAge())
41 | // 是否允许证书 不在默认开启
42 | .allowCredentials(config.isAllowCredentials());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/doc-apis-test/src/main/java/com/docapis/test/controller/SampleController.java:
--------------------------------------------------------------------------------
1 | package com.docapis.test.controller;
2 |
3 | import com.docapis.test.model.ApiResult;
4 | import com.docapis.test.model.DocQuery;
5 | import com.docapis.test.model.Document;
6 | import com.github.pagehelper.PageInfo;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import javax.validation.Valid;
10 | import java.util.Collections;
11 |
12 | /**
13 | * 示例接口
14 | **/
15 | @RestController
16 | @RequestMapping("/sample")
17 | public class SampleController {
18 | /**
19 | * 分页获取文档列表
20 | *
21 | * @param docQuery 文档分页查询参数
22 | * @return 分页数据
23 | */
24 | @PostMapping("/page")
25 | public ApiResult
22 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated
23 | **/
24 | public class MarkdownDocPlugin implements IPluginSupport {
25 |
26 | @Override
27 | public void execute(List
6 | * Copyright © 2024 xpc1024 All Rights Reserved
7 | **/
8 | public class CorsConfigProperties {
9 | /**
10 | * 是否开启跨域
11 | */
12 | private boolean allowCors = true;
13 | /**
14 | * 跨域允许时间
15 | */
16 | private Long maxAge = 3600L;
17 | /**
18 | * 允许跨域请求的域名
19 | */
20 | private String pathPattern = "/**";
21 | /**
22 | * 允许跨域的来源模式
23 | */
24 | private String allowedOriginPatterns = "*";
25 | /**
26 | * 允许跨域的方法
27 | */
28 | private String allowedMethods = "*";
29 | /**
30 | * 跨域允许请求头
31 | */
32 | private String allowedHeaders = "*";
33 | /**
34 | * 是否允许证书
35 | */
36 | private boolean allowCredentials = true;
37 |
38 | public boolean isAllowCors() {
39 | return allowCors;
40 | }
41 |
42 | public void setAllowCors(boolean allowCors) {
43 | this.allowCors = allowCors;
44 | }
45 |
46 | public Long getMaxAge() {
47 | return maxAge;
48 | }
49 |
50 | public void setMaxAge(Long maxAge) {
51 | this.maxAge = maxAge;
52 | }
53 |
54 | public String getPathPattern() {
55 | return pathPattern;
56 | }
57 |
58 | public void setPathPattern(String pathPattern) {
59 | this.pathPattern = pathPattern;
60 | }
61 |
62 | public String getAllowedOriginPatterns() {
63 | return allowedOriginPatterns;
64 | }
65 |
66 | public void setAllowedOriginPatterns(String allowedOriginPatterns) {
67 | this.allowedOriginPatterns = allowedOriginPatterns;
68 | }
69 |
70 | public String getAllowedMethods() {
71 | return allowedMethods;
72 | }
73 |
74 | public void setAllowedMethods(String allowedMethods) {
75 | this.allowedMethods = allowedMethods;
76 | }
77 |
78 | public String getAllowedHeaders() {
79 | return allowedHeaders;
80 | }
81 |
82 | public void setAllowedHeaders(String allowedHeaders) {
83 | this.allowedHeaders = allowedHeaders;
84 | }
85 |
86 | public boolean isAllowCredentials() {
87 | return allowCredentials;
88 | }
89 |
90 | public void setAllowCredentials(boolean allowCredentials) {
91 | this.allowCredentials = allowCredentials;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/constant/CoreConstants.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.constant;
2 |
3 |
4 | import java.io.File;
5 |
6 | /**
7 | * 核心常量
8 | *
9 | * Copyright © 2024 xpc1024 All Rights Reserved
10 | **/
11 | public interface CoreConstants {
12 | /**
13 | * 版本号发版及包调整时须更新此字段,死贫道不能死道友,此举可使用户可免配
14 | */
15 | String VERSION = "1.0.0";
16 | /**
17 | * jar 完整路径
18 | */
19 | String JAR_PATH = "com" + File.separator + "doc-apis" + File.separator + "doc-apis-core" + File.separator + VERSION + File.separator + "doc-apis-core-" + VERSION + ".jar";
20 | /**
21 | * 分隔符
22 | */
23 | String SEPATOR = "/";
24 | /**
25 | * comma
26 | */
27 | String COMMA_SIGN = ",";
28 | /**
29 | * 当前项目目录
30 | */
31 | String USER_DIR = "user.dir";
32 | /**
33 | * js存放路径
34 | */
35 | String JS_PATH = "js";
36 | /**
37 | * 图片存放路径
38 | */
39 | String IMG_PATH = "img";
40 | /**
41 | * css存放路径
42 | */
43 | String CSS_PATH = "css";
44 | /**
45 | * 字体存放路径
46 | */
47 | String FONT_PATH = "fonts";
48 | /**
49 | * html存放路径
50 | */
51 | String HTML_PATH = "html";
52 |
53 |
54 | String LOGO_NAME = "logo.png";
55 | /**
56 | * pageInfo 类名
57 | */
58 | String PAGE_INFO_NAME = "PageInfo";
59 | /**
60 | * pageInfo 文件名
61 | */
62 | String PAGE_INFO_FILE = "PageInfo.java";
63 | /**
64 | * esPageInfo 类名
65 | */
66 | String ES_PAGE_INFO_NAME = "EsPageInfo";
67 | /**
68 | * esPageInfo 文件名
69 | */
70 | String ES_PAGE_INFO_FILE = "EsPageInfo.java";
71 | /**
72 | * java 文件后缀
73 | */
74 | String JAVA_FILE_SUFFIX = ".java";
75 | /**
76 | * 内部依赖的所有js列表
77 | */
78 | String JS_NAMES = "jquery.min.js,bootstrap.min.js,autocomplete.jquery.min.js,prettify.min.js";
79 | /**
80 | * 内部依赖的所有css列表
81 | */
82 | String CSS_NAMES = "style.css,bootstrap.min.css,font-awesome.min.css,prettify.min.css";
83 | /**
84 | * 内部依赖的所有字体列表
85 | */
86 | String FONT_NAMES = "fontawesome-webfont.ttf,glyphicons-halflings-regular.ttf";
87 | /**
88 | * 缓存文件
89 | */
90 | String CACHE_FILE = ".cache.json";
91 | /**
92 | * 默认水印
93 | */
94 | String DEFAULT_WATERMARK = "doc-apis";
95 | /**
96 | * 默认密级
97 | */
98 | String DEFAULT_CLASSIFICATION_LEVEL = "II";
99 | }
100 |
--------------------------------------------------------------------------------
/doc-apis-starter/src/main/java/com/docapis/starter/config/AutoConfig.java:
--------------------------------------------------------------------------------
1 | package com.docapis.starter.config;
2 |
3 |
4 | import com.docapis.core.Docs;
5 | import com.docapis.core.DocsConfig;
6 | import com.docapis.core.LogUtils;
7 | import com.docapis.core.plugin.markdown.MarkdownDocPlugin;
8 | import com.docapis.starter.property.DocPlusConfigProperties;
9 | import org.springframework.beans.factory.InitializingBean;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
12 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
13 | import org.springframework.context.annotation.Configuration;
14 |
15 | import java.util.concurrent.CompletableFuture;
16 |
17 | /**
18 | * 自动生成装配
19 | *
20 | * Copyright © 2024 xpc1024 All Rights Reserved
21 | **/
22 | @Configuration
23 | @EnableConfigurationProperties(value = {DocPlusConfigProperties.class})
24 | @ConditionalOnProperty(prefix = "doc-apis", name = {"enable"}, havingValue = "true", matchIfMissing = true)
25 | public class AutoConfig implements InitializingBean {
26 | @Autowired
27 | private DocPlusConfigProperties docPlusConfigProperties;
28 |
29 | @Override
30 | public void afterPropertiesSet() throws Exception {
31 | if (!docPlusConfigProperties.isEnable()) {
32 | // 未开启, 直接不生成
33 | LogUtils.info("doc-apis not enabled, won't generate docs");
34 | return;
35 | }
36 | CompletableFuture.runAsync(this::doGenerate)
37 | .exceptionally(throwable -> {
38 | throwable.printStackTrace();
39 | return null;
40 | });
41 | }
42 |
43 | private void doGenerate() {
44 | DocsConfig config = new DocsConfig();
45 | // 项目根目录
46 | config.setProjectPath(docPlusConfigProperties.getProjectPath());
47 | // 项目名称
48 | config.setProjectName(docPlusConfigProperties.getProjectName());
49 | // 声明该API的版本
50 | config.setApiVersion(docPlusConfigProperties.getDocVersion());
51 | // 生成API 文档所在目录
52 | config.setDocsPath(docPlusConfigProperties.getDocPath());
53 | // 配置自动生成
54 | config.setAutoGenerate(docPlusConfigProperties.isAutoGenerate());
55 | // 添加MarkDown文档
56 | if (docPlusConfigProperties.isGenerateMarkDown()) {
57 | config.addPlugin(new MarkdownDocPlugin());
58 | }
59 |
60 | // 设置默认语言
61 | config.setLocale(docPlusConfigProperties.getLocale());
62 |
63 | // 执行生成文档
64 | Docs.buildHtmlDocs(config);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/Resources.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 | import freemarker.template.Configuration;
4 | import freemarker.template.Template;
5 |
6 | import java.io.*;
7 |
8 | /**
9 | * resources
10 | *
11 | * licence Apache 2.0, from japidoc
12 | **/
13 | public class Resources {
14 |
15 | private static boolean isDebug = false;
16 | private static String debugResourcePath;
17 |
18 | static {
19 | try {
20 | if (!isDebug) {
21 | freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
22 | }
23 | } catch (ClassNotFoundException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 |
28 | public static InputStream getTemplateFile(String fileName) throws FileNotFoundException {
29 |
30 | if (isDebug) {
31 | return new FileInputStream(new File(debugResourcePath, fileName));
32 | }
33 |
34 | final String userResPath = getUserResourcePath();
35 |
36 | if (getUserResourcePath() != null) {
37 | File tplFile = new File(userResPath, fileName);
38 | if (tplFile.isFile() && tplFile.exists()) {
39 | return new FileInputStream(tplFile);
40 | }
41 | }
42 |
43 | return Resources.class.getResourceAsStream("/" + fileName);
44 | }
45 |
46 | public static InputStream getCodeTemplateFile(String fileName) throws FileNotFoundException {
47 | return getTemplateFile(fileName);
48 | }
49 |
50 | public static Template getFreemarkerTemplate(String fileName) throws IOException {
51 | Configuration conf = new Configuration(Configuration.VERSION_2_3_0);
52 | conf.setDefaultEncoding("utf-8");
53 | if (isDebug) {
54 | conf.setDirectoryForTemplateLoading(new File(debugResourcePath));
55 | } else {
56 | final String userResPath = getUserResourcePath();
57 | File tplFile = new File(userResPath, fileName);
58 | if (tplFile.isFile() && tplFile.exists()) {
59 | conf.setDirectoryForTemplateLoading(new File(userResPath));
60 | } else {
61 | conf.setClassForTemplateLoading(Resources.class, "/");
62 | }
63 | }
64 | return conf.getTemplate(fileName);
65 | }
66 |
67 | private static String getUserResourcePath() {
68 | return DocContext.getDocsConfig().resourcePath;
69 | }
70 |
71 |
72 | public static void setDebug() {
73 | isDebug = true;
74 | debugResourcePath = System.getProperty("user.dir") + "/build/resources/main";
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/CacheUtils.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core;
2 |
3 |
4 | import com.docapis.core.parser.ClassNode;
5 | import com.docapis.core.parser.ControllerNode;
6 | import com.docapis.core.parser.ResponseNode;
7 |
8 | import java.io.File;
9 | import java.io.FileInputStream;
10 | import java.io.IOException;
11 | import java.util.Arrays;
12 | import java.util.List;
13 |
14 | import static com.docapis.core.constant.CoreConstants.CACHE_FILE;
15 |
16 | /**
17 | * abstract doc generator
18 | *
19 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated
20 | **/
21 | public class CacheUtils {
22 |
23 | public static void saveControllerNodes(List
16 | * licence Apache 2.0, from japidoc
17 | **/
18 | public abstract class CodeGenerator {
19 |
20 | private ResponseNode responseNode;
21 | private File codePath;
22 | private String codeRelativePath;
23 |
24 | public CodeGenerator(ResponseNode responseNode) {
25 | this.responseNode = responseNode;
26 | this.codeRelativePath = getRelativeCodeDir();
27 | this.codePath = new File(DocContext.getDocPath(), codeRelativePath);
28 | if (!this.codePath.exists()) {
29 | this.codePath.mkdirs();
30 | }
31 | }
32 |
33 | public String generateCode() throws IOException {
34 | if (responseNode.getChildNodes() == null || responseNode.getChildNodes().isEmpty()) {
35 | return "";
36 | }
37 | StringBuilder codeBodyBuilder = new StringBuilder();
38 | generateCodeForBuilder(responseNode, codeBodyBuilder);
39 | final String sCodeTemplate = getCodeTemplate();
40 | CodeFileBuilder codeBuilder = new CodeFileBuilder(responseNode.getClassName(), codeBodyBuilder.toString(), sCodeTemplate);
41 | final String javaFileName = String.format("%s_%s_%s_%s.html",
42 | responseNode.getRequestNode().getControllerNode().getPackageName().replace(".", "_"),
43 | responseNode.getRequestNode().getControllerNode().getClassName(),
44 | responseNode.getRequestNode().getMethodName(), responseNode.getClassName());
45 | Utils.writeToDisk(new File(codePath, javaFileName), codeBuilder.build());
46 | return String.format("%s/%s", codeRelativePath, javaFileName);
47 | }
48 |
49 | private void generateCodeForBuilder(ClassNode rootNode, StringBuilder codeBodyBuilder) throws IOException {
50 | codeBodyBuilder.append(generateNodeCode(rootNode));
51 | codeBodyBuilder.append('\n');
52 | for (FieldNode recordNode : rootNode.getChildNodes()) {
53 | if (recordNode.getChildNode() != null) {
54 | generateCodeForBuilder(recordNode.getChildNode(), codeBodyBuilder);
55 | }
56 | }
57 | }
58 |
59 | public abstract String generateNodeCode(ClassNode classNode) throws IOException;
60 |
61 | public abstract String getRelativeCodeDir();
62 |
63 | public abstract String getCodeTemplate();
64 | }
65 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/provider/DocFieldHelper.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.provider;
2 |
3 |
4 | import com.docapis.core.Utils;
5 |
6 | /**
7 | * doc field helper
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class DocFieldHelper {
12 |
13 | public static String getPrefFieldName(String originFieldName) {
14 | String[] names = originFieldName.split("_");
15 | if (names.length == 1) {
16 | return Utils.decapitalize(names[0]);
17 | }
18 | StringBuilder fieldNameBuilder = new StringBuilder();
19 | fieldNameBuilder.append(Utils.decapitalize(names[0]));
20 | for (int i = 1; i < names.length; i++) {
21 | fieldNameBuilder.append(Utils.capitalize(names[i]));
22 | }
23 | return fieldNameBuilder.toString();
24 | }
25 |
26 | public static String getPrefFieldType(String fieldType) {
27 |
28 | if (fieldType == null) {
29 | return "unknow";
30 | }
31 |
32 | if (fieldType.equalsIgnoreCase("int") || fieldType.equalsIgnoreCase("integer")) {
33 | return "int";
34 | } else if (fieldType.equalsIgnoreCase("short")) {
35 | return "short";
36 | } else if (fieldType.equalsIgnoreCase("byte")) {
37 | return "byte";
38 | } else if (fieldType.equalsIgnoreCase("long")) {
39 | return "long";
40 | } else if (fieldType.equalsIgnoreCase("boolean") || fieldType.equalsIgnoreCase("bool")) {
41 | return "boolean";
42 | } else if (fieldType.equalsIgnoreCase("float")) {
43 | return "float";
44 | } else if (fieldType.equalsIgnoreCase("double")) {
45 | return "double";
46 | } else if (fieldType.equalsIgnoreCase("String") || fieldType.equalsIgnoreCase("Date")) {
47 | return "String";
48 | } else {
49 | return fieldType;
50 | }
51 | }
52 |
53 | public static String getIosFieldType(String type) {
54 | if (type.equals("byte")) {
55 | return "int";
56 | } else if (type.equals("int")) {
57 | return "NSInteger";
58 | } else if (type.equals("short")) {
59 | return "short";
60 | } else if (type.equals("long")) {
61 | return "long";
62 | } else if (type.equals("float")) {
63 | return "CGFloat";
64 | } else if (type.equals("double")) {
65 | return "double";
66 | } else if (type.equals("boolean")) {
67 | return "BOOL";
68 | } else if (type.equalsIgnoreCase("String")) {
69 | return "NSString";
70 | } else {
71 | return type;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/parser/ControllerNode.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.parser;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * controller node
8 | *
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | public class ControllerNode {
12 |
13 | private String author;
14 | private String description;
15 | private String baseUrl;
16 | private String className;
17 | private String packageName;
18 | private Boolean generateDocs = Boolean.FALSE;
19 | private List
24 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated
25 | **/
26 | public class HtmlDocGenerator extends AbsDocGenerator {
27 |
28 | public HtmlDocGenerator() {
29 | super(DocContext.controllerParser(), new HtmlControllerDocBuilder());
30 | }
31 |
32 | @Override
33 | void generateIndex(List
20 | * licence Apache 2.0, from japidoc
21 | **/
22 | public class ModelCodeGenerator extends CodeGenerator {
23 |
24 | private static final String FILE_FIELD_TEMPLATE = "IOS_Model_Field.tpl";
25 | private static final String FILE_MODEL_TEMPLATE = "IOS_Model.tpl";
26 | private static final String FILE_CODE_TEMPLATE = "Code_File.html.tpl";
27 | private static final String IOS_CODE_DIR = "iosCodes";
28 |
29 | private static String sFieldTemplate;
30 | private static String sModelTemplate;
31 | private static String sCodeTemplate;
32 |
33 | static {
34 | ModelTemplateProvider resourceTemplateProvider = new ModelTemplateProvider();
35 | try {
36 | sFieldTemplate = resourceTemplateProvider.provideTemplateForName(FILE_FIELD_TEMPLATE);
37 | sModelTemplate = resourceTemplateProvider.provideTemplateForName(FILE_MODEL_TEMPLATE);
38 | sCodeTemplate = TemplateProvider.provideTemplateForName(FILE_CODE_TEMPLATE);
39 | } catch (IOException e) {
40 | e.printStackTrace();
41 | }
42 | }
43 |
44 | public ModelCodeGenerator(ResponseNode responseNode) {
45 | super(responseNode);
46 | }
47 |
48 | @Override
49 | public String generateNodeCode(ClassNode respNode) throws IOException {
50 | String className = respNode.getClassName();
51 | IFieldProvider entryProvider = ProviderFactory.createProvider();
52 | List
14 | * licence Apache 2.0, from japidoc
15 | **/
16 | public class DHttpUtils {
17 |
18 | private DHttpUtils() {
19 |
20 | }
21 |
22 | public static DHttpResponse httpPost(DHttpRequest request) throws IOException {
23 |
24 | URL url = new URL(request.getUrl());
25 | HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
26 | httpConn.setRequestMethod("POST");
27 | httpConn.setInstanceFollowRedirects(request.isAutoRedirect());
28 |
29 | Map
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | class Action {
12 |
13 | private int id;
14 | private int disableCache;
15 | private String name;
16 | private String description;
17 | private String requestType = "1";
18 | private String requestUrl;
19 | private Set
16 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated
17 | **/
18 | public class Docs {
19 |
20 | private static final String CONFIG_FILE = "docs.config";
21 |
22 | public static void main(String[] args) {
23 | DocsConfig config = loadProps();
24 | buildHtmlDocs(config);
25 | }
26 |
27 | public static void buildHtmlDocs(DocsConfig config) {
28 | DocContext.init(config);
29 | HtmlDocGenerator docGenerator = new HtmlDocGenerator();
30 | DocContext.setControllerNodeList(docGenerator.getControllerNodeList());
31 | try {
32 | docGenerator.generateDocs();
33 | } catch (Throwable e) {
34 | e.printStackTrace();
35 | } finally {
36 | // 清理可能产生的PageInfo临时文件
37 | Utils.deleteFileWithRetry(System.getProperty(USER_DIR) + File.separator + PAGE_INFO_FILE);
38 | Utils.deleteFileWithRetry(System.getProperty(USER_DIR) + File.separator + ES_PAGE_INFO_FILE);
39 | }
40 | CacheUtils.saveControllerNodes(docGenerator.getControllerNodeList());
41 | DocsConfig docsConfig = DocContext.getDocsConfig();
42 | if (docsConfig.getRapProjectId() != null && docsConfig.getRapHost() != null) {
43 | IPluginSupport rapPlugin = new RapSupportPlugin();
44 | rapPlugin.execute(docGenerator.getControllerNodeList());
45 | }
46 | for (IPluginSupport plugin : config.getPlugins()) {
47 | plugin.execute(docGenerator.getControllerNodeList());
48 | }
49 |
50 | // 清理 cache.json
51 | Utils.deleteFileWithRetry(DocContext.getDocPath() + File.separator + CACHE_FILE);
52 | }
53 |
54 | public static void setResponseWrapper(IResponseWrapper responseWrapper) {
55 | DocContext.setResponseWrapper(responseWrapper);
56 | }
57 |
58 | private static DocsConfig loadProps() {
59 | try {
60 | Properties properties = new Properties();
61 | properties.load(new FileReader(CONFIG_FILE));
62 | DocsConfig config = new DocsConfig();
63 | config.projectPath = properties.getProperty("projectPath", null);
64 |
65 | if (config.projectPath == null) {
66 | throw new RuntimeException("projectPath property is needed in the config file.");
67 | }
68 |
69 | config.docsPath = properties.getProperty("docsPath", null);
70 | config.resourcePath = properties.getProperty("resourcePath", null);
71 | config.mvcFramework = properties.getProperty("mvcFramework", "");
72 | return config;
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 |
76 | try {
77 | File configFile = new File(CONFIG_FILE);
78 | configFile.createNewFile();
79 | } catch (Exception ex) {
80 | e.printStackTrace();
81 | }
82 |
83 | throw new RuntimeException("you need to set projectPath property in " + CONFIG_FILE);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/doc/HtmlControllerDocBuilder.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.doc;
2 |
3 | import com.docapis.core.DocContext;
4 | import com.docapis.core.LogUtils;
5 | import com.docapis.core.Resources;
6 | import com.docapis.core.Utils;
7 | import com.docapis.core.codegenerator.ios.ModelCodeGenerator;
8 | import com.docapis.core.codegenerator.java.JavaCodeGenerator;
9 | import com.docapis.core.parser.ControllerNode;
10 | import com.docapis.core.parser.RequestNode;
11 | import freemarker.template.Template;
12 | import freemarker.template.TemplateException;
13 |
14 | import java.io.File;
15 | import java.io.FileInputStream;
16 | import java.io.FileWriter;
17 | import java.io.IOException;
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | import static com.docapis.core.constant.CoreConstants.HTML_PATH;
22 |
23 | /**
24 | * html controller doc builder
25 | *
26 | * licence Apache 2.0,AGPL-3.0, from japidoc and doc-apis originated
27 | **/
28 | public class HtmlControllerDocBuilder implements IControllerDocBuilder {
29 |
30 | @Override
31 | public String buildDoc(ControllerNode controllerNode) throws IOException {
32 |
33 | for (RequestNode requestNode : controllerNode.getRequestNodes()) {
34 | if (requestNode.getResponseNode() != null && !requestNode.getResponseNode().getChildNodes().isEmpty()) {
35 | JavaCodeGenerator javaCodeGenerator = new JavaCodeGenerator(requestNode.getResponseNode());
36 | final String javaSrcUrl = javaCodeGenerator.generateCode();
37 | requestNode.setAndroidCodePath(javaSrcUrl);
38 | ModelCodeGenerator iosCodeGenerator = new ModelCodeGenerator(requestNode.getResponseNode());
39 | final String iosSrcUrl = iosCodeGenerator.generateCode();
40 | requestNode.setIosCodePath(iosSrcUrl);
41 | }
42 | }
43 |
44 | final Template ctrlTemplate = getControllerTpl();
45 | String path = DocContext.getDocPath() + File.separator + HTML_PATH;
46 | File htmlDir = new File(path);
47 | if (!htmlDir.exists()) {
48 | boolean mkdir = htmlDir.mkdir();
49 | if (!mkdir) {
50 | LogUtils.error("create html docs dir fail");
51 | }
52 | }
53 | final File docFile = new File(path, controllerNode.getDocFileName());
54 | FileWriter docFileWriter = new FileWriter(docFile);
55 | Map
9 | * licence Apache 2.0, from japidoc
10 | **/
11 | class Parameter {
12 |
13 | private int id;
14 | private String mockData;
15 | private String name;
16 | private String identifier;
17 | private String identifierChange;
18 | private String remarkChange;
19 | private String dataType;
20 | private String remark;
21 | private Set
18 | * licence Apache 2.0, from japidoc
19 | **/
20 | public class PlayRoutesParser {
21 |
22 | private String routeFile;
23 | private String javaSrcPath;
24 |
25 | private List
13 | * Copyright © 2024 xpc1024 All Rights Reserved
14 | **/
15 | @ConfigurationProperties(value = "doc-apis")
16 | @ConditionalOnProperty(prefix = "doc-apis", name = {"enable"}, havingValue = "true", matchIfMissing = true)
17 | public class DocPlusConfigProperties {
18 | /**
19 | * 是否开启文档自动生成 默认开启
20 | */
21 | private boolean enable = true;
22 | /**
23 | * 项目名称
24 | */
25 | private String projectName = "doc-apis";
26 | /**
27 | * 项目路径
28 | */
29 | private String projectPath = System.getProperty(CoreConstants.USER_DIR);
30 | /**
31 | * 文档版本
32 | */
33 | private String docVersion = "doc-version-" + CoreConstants.VERSION;
34 | /**
35 | * 文档生成路径
36 | */
37 | private String docPath = System.getProperty(CoreConstants.USER_DIR);
38 | /**
39 | * 是否自动生成 默认为true 若为false时,需要加@DocApi注解
40 | */
41 | private boolean autoGenerate = true;
42 | /**
43 | * 是否生成markdown文档,默认生成,若为否则仅生成html文档
44 | */
45 | private boolean generateMarkDown = true;
46 | /**
47 | * 水印
48 | */
49 | private String watermark;
50 | /**
51 | * 接口文档密级
52 | */
53 | private String classificationLevel;
54 |
55 | /**
56 | * 跨域相关配置
57 | */
58 | @NestedConfigurationProperty
59 | private CorsConfigProperties corsConfig = new CorsConfigProperties();
60 |
61 | /**
62 | * 生成文档语言,默认为当前系统语言
63 | */
64 | private Locale locale = Locale.getDefault();
65 |
66 | public boolean isEnable() {
67 | return enable;
68 | }
69 |
70 | public void setEnable(boolean enable) {
71 | this.enable = enable;
72 | }
73 |
74 | public String getProjectName() {
75 | return projectName;
76 | }
77 |
78 | public void setProjectName(String projectName) {
79 | this.projectName = projectName;
80 | }
81 |
82 | public String getProjectPath() {
83 | return projectPath;
84 | }
85 |
86 | public void setProjectPath(String projectPath) {
87 | this.projectPath = projectPath;
88 | }
89 |
90 | public String getDocVersion() {
91 | return docVersion;
92 | }
93 |
94 | public void setDocVersion(String docVersion) {
95 | this.docVersion = docVersion;
96 | }
97 |
98 | public String getDocPath() {
99 | return docPath;
100 | }
101 |
102 | public void setDocPath(String docPath) {
103 | this.docPath = docPath;
104 | }
105 |
106 | public boolean isAutoGenerate() {
107 | return autoGenerate;
108 | }
109 |
110 | public void setAutoGenerate(boolean autoGenerate) {
111 | this.autoGenerate = autoGenerate;
112 | }
113 |
114 | public boolean isGenerateMarkDown() {
115 | return generateMarkDown;
116 | }
117 |
118 | public void setGenerateMarkDown(boolean generateMarkDown) {
119 | this.generateMarkDown = generateMarkDown;
120 | }
121 |
122 | public CorsConfigProperties getCorsConfig() {
123 | return corsConfig;
124 | }
125 |
126 | public Locale getLocale() {
127 | return locale;
128 | }
129 |
130 | public void setLocale(Locale locale) {
131 | this.locale = locale;
132 | }
133 |
134 | public String getWatermark() {
135 | return watermark;
136 | }
137 |
138 | public void setWatermark(String watermark) {
139 | this.watermark = watermark;
140 | }
141 |
142 | public String getClassificationLevel() {
143 | return classificationLevel;
144 | }
145 |
146 | public void setClassificationLevel(String classificationLevel) {
147 | this.classificationLevel = classificationLevel;
148 | }
149 |
150 | public void setCorsConfig(CorsConfigProperties corsConfig) {
151 | this.corsConfig = corsConfig;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/doc-apis-core/src/main/java/com/docapis/core/codegenerator/java/JavaCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.docapis.core.codegenerator.java;
2 |
3 |
4 | import com.docapis.core.codegenerator.CodeGenerator;
5 | import com.docapis.core.codegenerator.IFieldProvider;
6 | import com.docapis.core.codegenerator.TemplateProvider;
7 | import com.docapis.core.codegenerator.java.builder.JavaClassBuilder;
8 | import com.docapis.core.codegenerator.java.builder.JavaFieldBuilder;
9 | import com.docapis.core.codegenerator.java.builder.JavaGetterBuilder;
10 | import com.docapis.core.codegenerator.java.builder.JavaSetterBuilder;
11 | import com.docapis.core.codegenerator.model.FieldModel;
12 | import com.docapis.core.codegenerator.provider.ProviderFactory;
13 | import com.docapis.core.parser.ClassNode;
14 | import com.docapis.core.parser.ResponseNode;
15 |
16 | import java.io.IOException;
17 | import java.util.List;
18 |
19 | /**
20 | * java code generator
21 | *
22 | * licence Apache 2.0, from japidoc
23 | **/
24 | public class JavaCodeGenerator extends CodeGenerator {
25 |
26 | private static final String FILE_FIELD_TEMPLATE = "Java_Entity_Field.tpl";
27 | private static final String FILE_GETTER_TEMPLATE = "Java_Entity_Getter.tpl";
28 | private static final String FILE_SETTER_TEMPLATE = "Java_Entity_Setter.tpl";
29 | private static final String FILE_CLASS_TEMPLATE = "Java_Entity.tpl";
30 | private static final String FILE_CODE_TEMPLATE = "Code_File.html.tpl";
31 | private static final String JAVA_CODE_DIR = "javaCodes";
32 |
33 | private static String sFieldTemplate, sGetterTemplate, sSetterTemplate, sClassTemplate, sCodeTemplate;
34 |
35 | static {
36 | JavaTemplateProvider resourceTemplateProvider = new JavaTemplateProvider();
37 | try {
38 | sFieldTemplate = resourceTemplateProvider.provideTemplateForName(FILE_FIELD_TEMPLATE);
39 | sGetterTemplate = resourceTemplateProvider.provideTemplateForName(FILE_GETTER_TEMPLATE);
40 | sSetterTemplate = resourceTemplateProvider.provideTemplateForName(FILE_SETTER_TEMPLATE);
41 | sClassTemplate = resourceTemplateProvider.provideTemplateForName(FILE_CLASS_TEMPLATE);
42 | sCodeTemplate = TemplateProvider.provideTemplateForName(FILE_CODE_TEMPLATE);
43 | } catch (IOException e) {
44 | e.printStackTrace();
45 | }
46 | }
47 |
48 | public JavaCodeGenerator(ResponseNode responseNode) {
49 | super(responseNode);
50 | }
51 |
52 | @Override
53 | public String generateNodeCode(ClassNode respNode) throws IOException {
54 | String className = respNode.getClassName();
55 |
56 | IFieldProvider entryProvider = ProviderFactory.createProvider();
57 | List
6 | * licence Apache 2.0, from japidoc
7 | **/
8 | class DataType {
9 |
10 | public static String STRING = "string";
11 | public static String NUMBER = "number";
12 | public static String BOOLEAN = "boolean";
13 | public static String OBJECT = "object";
14 | public static String ARRAY = "array";
15 | public static String ARRAY_NUMBER = "array
53 |