├── .gitignore
├── LICENSE
├── README.md
├── demo.png
├── pom.xml
├── qrcode.png
├── screenshot.png
├── unionj-generator-backend
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cloud
│ │ │ └── unionj
│ │ │ └── generator
│ │ │ └── backend
│ │ │ ├── docparser
│ │ │ ├── BackendDocParser.java
│ │ │ └── entity
│ │ │ │ ├── Backend.java
│ │ │ │ ├── Proto.java
│ │ │ │ ├── ProtoProperty.java
│ │ │ │ ├── ProtoRouter.java
│ │ │ │ ├── Vo.java
│ │ │ │ ├── VoEnum.java
│ │ │ │ ├── VoEnumType.java
│ │ │ │ └── VoProperty.java
│ │ │ └── springboot
│ │ │ ├── BasePomGenerator.java
│ │ │ ├── Constants.java
│ │ │ ├── ControllerJavaGenerator.java
│ │ │ ├── ControllerPomGenerator.java
│ │ │ ├── FeignJavaGenerator.java
│ │ │ ├── FeignPomGenerator.java
│ │ │ ├── OutputConfig.java
│ │ │ ├── OutputType.java
│ │ │ ├── ProtoJavaGenerator.java
│ │ │ ├── ProtoPomGenerator.java
│ │ │ ├── ServiceImplJavaGenerator.java
│ │ │ ├── ServiceJavaGenerator.java
│ │ │ ├── ServicePomGenerator.java
│ │ │ ├── SpringbootFolderGenerator.java
│ │ │ ├── VoJavaGenerator.java
│ │ │ └── VoPomGenerator.java
│ └── resources
│ │ └── templates
│ │ └── backend
│ │ └── springboot
│ │ ├── controller.java.ftl
│ │ ├── controllerpom.xml.ftl
│ │ ├── feign.java.ftl
│ │ ├── feignpom.xml.ftl
│ │ ├── proto.java.ftl
│ │ ├── protopom.xml.ftl
│ │ ├── service.java.ftl
│ │ ├── serviceimpl.java.ftl
│ │ ├── servicepom.xml.ftl
│ │ ├── vo.java.ftl
│ │ └── vopom.xml.ftl
│ └── test
│ ├── java
│ └── cloud
│ │ └── unionj
│ │ └── generator
│ │ └── backend
│ │ ├── Components.java
│ │ ├── PathTest.java
│ │ ├── PodamTest.java
│ │ ├── docparser
│ │ └── BackendDocParserTest.java
│ │ └── springboot
│ │ ├── ControllerPomGeneratorTest.java
│ │ ├── ProtoPomGeneratorTest.java
│ │ ├── SpringbootFolderGeneratorTest.java
│ │ ├── VoPomGeneratorTest.java
│ │ ├── export
│ │ ├── ExportComponents.java
│ │ └── ExportProto.java
│ │ └── user
│ │ ├── UserComponents.java
│ │ └── UserProto.java
│ └── resources
│ └── petstore3.json
├── unionj-generator-core
├── pom.xml
└── src
│ └── main
│ └── java
│ └── cloud
│ └── unionj
│ └── generator
│ ├── DefaultGenerator.java
│ ├── Generator.java
│ ├── GeneratorUtils.java
│ └── Utils.java
├── unionj-generator-maven-plugin
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── cloud
│ │ └── unionj
│ │ └── Codegen.java
│ └── test
│ └── java
│ └── cloud
│ └── unionj
│ └── CodegenTest.java
├── unionj-generator-mybatis
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cloud
│ │ │ └── unionj
│ │ │ └── generator
│ │ │ └── mybatis
│ │ │ ├── Constants.java
│ │ │ ├── MapperInfo.java
│ │ │ ├── MapperLoader.java
│ │ │ ├── MapperTestJavaGenerator.java
│ │ │ ├── MethodInfo.java
│ │ │ └── ParameterInfo.java
│ └── resources
│ │ └── templates
│ │ └── mybatis
│ │ └── mappertest.java.ftl
│ └── test
│ └── java
│ └── cloud
│ └── unionj
│ └── generator
│ └── mybatis
│ ├── Main.java
│ ├── MainTest.java
│ ├── dao
│ └── ProductMapper.java
│ └── entity
│ └── Product.java
├── unionj-generator-openapi
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── cloud
│ │ └── unionj
│ │ └── generator
│ │ └── openapi3
│ │ ├── ExceptionHelper.java
│ │ ├── NullAwareBeanUtilsBean.java
│ │ ├── PathConfig.java
│ │ ├── PathHelper.java
│ │ ├── dsl
│ │ ├── Discriminator.java
│ │ ├── Generic.java
│ │ ├── IGeneric.java
│ │ ├── IImporter.java
│ │ ├── Openapi3.java
│ │ ├── PathHelper.java
│ │ ├── Reference.java
│ │ ├── Schema.java
│ │ ├── SchemaHelper.java
│ │ ├── info
│ │ │ ├── Contact.java
│ │ │ ├── Info.java
│ │ │ └── License.java
│ │ ├── paths
│ │ │ ├── Content.java
│ │ │ ├── Delete.java
│ │ │ ├── Get.java
│ │ │ ├── MediaType.java
│ │ │ ├── Operation.java
│ │ │ ├── Parameter.java
│ │ │ ├── Path.java
│ │ │ ├── Post.java
│ │ │ ├── Put.java
│ │ │ ├── RequestBody.java
│ │ │ ├── Response.java
│ │ │ └── Responses.java
│ │ ├── servers
│ │ │ └── Server.java
│ │ └── tags
│ │ │ └── Tag.java
│ │ ├── expression
│ │ ├── DiscriminatorBuilder.java
│ │ ├── GenericBuilder.java
│ │ ├── ISchemaFinder.java
│ │ ├── Openapi3Builder.java
│ │ ├── ReferenceBuilder.java
│ │ ├── SchemaBuilder.java
│ │ ├── info
│ │ │ ├── ContactBuilder.java
│ │ │ ├── InfoBuilder.java
│ │ │ └── LicenseBuilder.java
│ │ ├── paths
│ │ │ ├── ContentBuilder.java
│ │ │ ├── MediaTypeBuilder.java
│ │ │ ├── OperationBuilder.java
│ │ │ ├── ParameterBuilder.java
│ │ │ ├── PathBuilder.java
│ │ │ ├── RequestBodyBuilder.java
│ │ │ ├── ResponseBuilder.java
│ │ │ └── ResponsesBuilder.java
│ │ ├── servers
│ │ │ └── ServerBuilder.java
│ │ └── tags
│ │ │ └── TagBuilder.java
│ │ ├── model
│ │ ├── AdditionalPropertiesDeserializer.java
│ │ ├── Callback.java
│ │ ├── Components.java
│ │ ├── Discriminator.java
│ │ ├── Example.java
│ │ ├── ExternalDocs.java
│ │ ├── Generic.java
│ │ ├── Openapi3.java
│ │ ├── Schema.java
│ │ ├── Security.java
│ │ ├── SecurityScheme.java
│ │ ├── info
│ │ │ ├── Contact.java
│ │ │ ├── Info.java
│ │ │ └── License.java
│ │ ├── paths
│ │ │ ├── Content.java
│ │ │ ├── Encoding.java
│ │ │ ├── Header.java
│ │ │ ├── Link.java
│ │ │ ├── MediaType.java
│ │ │ ├── Operation.java
│ │ │ ├── Parameter.java
│ │ │ ├── Path.java
│ │ │ ├── RequestBody.java
│ │ │ ├── Response.java
│ │ │ └── Responses.java
│ │ ├── servers
│ │ │ └── Server.java
│ │ └── tags
│ │ │ └── Tag.java
│ │ └── parser
│ │ └── Openapi3Parser.java
│ └── test
│ ├── java
│ └── cloud
│ │ └── unionj
│ │ └── generator
│ │ └── openapi3
│ │ ├── dsl
│ │ ├── InfoTest.java
│ │ └── paths
│ │ │ ├── Components.java
│ │ │ └── PathTest.java
│ │ └── model
│ │ └── Openapi3Test.java
│ └── resources
│ └── petstore3.json
├── unionj-generator-ui
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cloud
│ │ │ └── unionj
│ │ │ └── generator
│ │ │ └── ui
│ │ │ ├── config
│ │ │ ├── DocAuthProperties.java
│ │ │ ├── JacksonConfig.java
│ │ │ └── UIConfig.java
│ │ │ ├── controller
│ │ │ └── UIController.java
│ │ │ └── filter
│ │ │ └── DocAuthFilter.java
│ └── resources
│ │ ├── META-INF
│ │ ├── resources
│ │ │ ├── css
│ │ │ │ ├── app.bbf0d3db.css
│ │ │ │ └── chunk-libs.dc65e09b.css
│ │ │ ├── fonts
│ │ │ │ ├── element-icons.535877f5.woff
│ │ │ │ └── element-icons.732389de.ttf
│ │ │ └── js
│ │ │ │ ├── app.c50fcb9e.js
│ │ │ │ ├── chunk-elementUI.56620297.js
│ │ │ │ ├── chunk-libs.b2d7bde5.js
│ │ │ │ └── runtime.9dc2cf20.js
│ │ └── spring.factories
│ │ └── templates
│ │ └── index.html
│ └── test
│ └── resources
│ └── petstore3.json
└── web-ui.png
/.gitignore:
--------------------------------------------------------------------------------
1 | cache-dir
2 | **/Permanent_Data
3 | **/logs
4 | **/log
5 | **/debug*
6 | # 忽略匹配下列规则的Git 提交 V2.1.0
7 | ### gradle ###
8 | .gradle
9 | /build/
10 | !gradle/wrapper/gradle-wrapper.jar
11 |
12 | ### STS ###
13 | .settings/
14 | .apt_generated
15 | .classpath
16 | .factorypath
17 | .project
18 | .settings
19 | .springBeans
20 | bin/
21 |
22 | ### IntelliJ IDEA ###
23 | .idea
24 | *.iws
25 | *.iml
26 | *.ipr
27 | *.lock
28 | rebel.xml
29 |
30 | ### NetBeans ###
31 | nbproject/private/
32 | build/
33 | nbbuild/
34 | nbdist/
35 | .nb-gradle/
36 |
37 | ### maven ###
38 | target/
39 | *.war
40 | *.ear
41 | *.tar
42 | *.tar.gz
43 |
44 | ### logs ####
45 | /logs/
46 | *.log
47 | **/logs
48 |
49 | ### temp ignore ###
50 | *.cache
51 | *.diff
52 | *.patch
53 | *.tmp
54 | *.java~
55 | *.properties~
56 | *.xml~
57 |
58 | ### system ignore ###
59 | .DS_Store
60 | Thumbs.db
61 | .metadata
62 | upload
63 | gen_code
64 |
65 | ### node ###
66 | node_modules
67 |
68 | ### sonar ###
69 | .scannerwork
70 |
71 | /unionj-generator-backend/backend/
72 | /unionj-generator-apidoc/apidoc
73 | /unionj-generator-frontend/output
74 | /unionj-generator-mock/mocks
75 | /unionj-generator-service/services
76 | /unionj-generator-frontend/vue/
77 | /unionj-generator-frontend/__MACOSX/
78 | /unionj-generator-backend/myproject-controller/
79 | /unionj-generator-backend/myproject-proto/
80 | /unionj-generator-backend/myproject-vo/
81 | unionj-generator-backend/myproject-service/
82 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 union
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unionj-cloud/unionj-generator/0ff0bb3895e285b55362892291d5561eaa8d76df/demo.png
--------------------------------------------------------------------------------
/qrcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unionj-cloud/unionj-generator/0ff0bb3895e285b55362892291d5561eaa8d76df/qrcode.png
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unionj-cloud/unionj-generator/0ff0bb3895e285b55362892291d5561eaa8d76df/screenshot.png
--------------------------------------------------------------------------------
/unionj-generator-backend/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 |
8 | io.github.unionj-cloud
9 | unionj-generator
10 | 1.6.8-SNAPSHOT
11 |
12 | unionj-generator-backend
13 | unionj-generator-backend
14 |
15 |
16 |
17 | io.github.unionj-cloud
18 | unionj-generator-core
19 | ${project.version}
20 |
21 |
22 | io.github.unionj-cloud
23 | unionj-generator-openapi
24 | ${project.version}
25 |
26 |
27 | uk.co.jemos.podam
28 | podam
29 | 8.0.0.RELEASE
30 |
31 |
32 | org.slf4j
33 | slf4j-api
34 | 1.7.25
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/BackendDocParser.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser;
2 |
3 | import cloud.unionj.generator.backend.docparser.entity.Backend;
4 | import cloud.unionj.generator.openapi3.model.Openapi3;
5 | import cloud.unionj.generator.openapi3.parser.Openapi3Parser;
6 | import lombok.Data;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.net.URL;
12 |
13 | /**
14 | * @author created by wubin
15 | * @version v0.1
16 | * cloud.unionj.generator.mock.docparser
17 | * date 2020/11/18
18 | */
19 | @Data
20 | public class BackendDocParser {
21 |
22 | public static Backend parse(File doc) throws IOException {
23 | Openapi3 openAPI = new Openapi3Parser().parse(doc);
24 | return Backend.convert(openAPI);
25 | }
26 |
27 | public static Backend parse(URL doc) throws IOException {
28 | Openapi3 openAPI = new Openapi3Parser().parse(doc);
29 | return Backend.convert(openAPI);
30 | }
31 |
32 | public static Backend parse(InputStream doc) throws IOException {
33 | Openapi3 openAPI = new Openapi3Parser().parse(doc);
34 | return Backend.convert(openAPI);
35 | }
36 |
37 | public static Backend parse(Openapi3 openAPI) throws IOException {
38 | return Backend.convert(openAPI);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/Proto.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import cloud.unionj.generator.Utils;
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.backend.docparser.entity
12 | * date 2020/12/21
13 | */
14 | @Data
15 | public class Proto {
16 |
17 | private List imports;
18 |
19 | public void setName(String name) {
20 | this.name = Utils.cleanClassName(name);
21 | }
22 |
23 | private String name;
24 | private List routers;
25 |
26 | // TODO
27 | private String base;
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/ProtoProperty.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import cloud.unionj.generator.Utils;
4 | import cloud.unionj.generator.openapi3.dsl.SchemaHelper;
5 | import cloud.unionj.generator.openapi3.model.Schema;
6 | import lombok.Data;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.mock.docparser.entity
13 | * date 2020/11/18
14 | */
15 | @Data
16 | public class ProtoProperty {
17 |
18 | public static final Builder UPLOAD_FILE_BUILDER = new Builder("MultipartFile").name("file");
19 | public static final Builder UPLOAD_FILES_BUILDER = new Builder("MultipartFile[]").name("files");
20 | public static final ProtoProperty STREAM = new Builder("ResponseEntity").build();
21 |
22 | private String name;
23 | private String description;
24 | private String requestParam;
25 | private String schemaType;
26 | private String in;
27 | private String type;
28 | private boolean required;
29 | private String defaultValue;
30 |
31 | private ProtoProperty() {
32 | }
33 |
34 | public static class Builder {
35 | private String name;
36 | private String description;
37 | private String in;
38 | private String type;
39 | private boolean required = true;
40 | private String defaultValue;
41 | private String schemaType;
42 | private String requestParam;
43 |
44 | public Builder(String type) {
45 | this.type = type;
46 | }
47 |
48 | public Builder(Schema type) {
49 | this.type = Utils.cleanClassName(type.javaType()
50 | .replaceAll(SchemaHelper.LEFT_ARROW, "<")
51 | .replaceAll(SchemaHelper.RIGHT_ARROW, ">"));
52 | this.schemaType = type.getType();
53 | }
54 |
55 | public Builder name(String name) {
56 | this.name = name;
57 | this.requestParam = name;
58 | return this;
59 | }
60 |
61 | public Builder in(String in) {
62 | this.in = in;
63 | return this;
64 | }
65 |
66 | public Builder required(boolean required) {
67 | this.required = required;
68 | return this;
69 | }
70 |
71 | public Builder description(String description) {
72 | this.description = description;
73 | return this;
74 | }
75 |
76 | public Builder defaultValue(String defaultValue) {
77 | if (StringUtils.isNotBlank(defaultValue)) {
78 | this.defaultValue = defaultValue;
79 | }
80 | return this;
81 | }
82 |
83 | public ProtoProperty build() {
84 | ProtoProperty property = new ProtoProperty();
85 | property.name = this.name;
86 | property.type = this.type;
87 | property.in = this.in;
88 | property.required = this.required;
89 | property.defaultValue = this.defaultValue;
90 | property.schemaType = this.schemaType;
91 | property.requestParam = this.requestParam;
92 | property.description = this.description;
93 | return property;
94 | }
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/Vo.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import cloud.unionj.generator.Utils;
4 | import lombok.Data;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.backend.docparser.entity
13 | * date 2020/12/21
14 | */
15 | @Data
16 | public class Vo {
17 |
18 | public void setName(String name) {
19 | this.name = Utils.cleanClassName(name);
20 | }
21 |
22 | private String name;
23 | private String description;
24 | private List properties;
25 | private List enumTypes;
26 | private List imports;
27 | private String dummy;
28 | private boolean output = true;
29 |
30 | public boolean isDummy() {
31 | return StringUtils.isNotBlank(this.dummy);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/VoEnum.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.backend.docparser.entity
9 | * date 2020/12/21
10 | */
11 | @Data
12 | public class VoEnum {
13 |
14 | private String name;
15 | private String value;
16 |
17 | public VoEnum(String name, String value) {
18 | this.name = name;
19 | this.value = value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/VoEnumType.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.backend.docparser.entity
11 | * date 2020/12/21
12 | */
13 | @Data
14 | public class VoEnumType {
15 |
16 | private List enums;
17 | private String name;
18 |
19 | public VoEnumType(List enums, String name) {
20 | this.enums = enums;
21 | this.name = name;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/docparser/entity/VoProperty.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser.entity;
2 |
3 | import cloud.unionj.generator.Utils;
4 | import cloud.unionj.generator.openapi3.dsl.SchemaHelper;
5 | import cloud.unionj.generator.openapi3.model.Schema;
6 | import lombok.Data;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.backend.docparser.entity
13 | * date 2020/12/21
14 | */
15 | @Data
16 | public class VoProperty {
17 | private String name;
18 | private String description;
19 | private String jsonProperty;
20 | private String type;
21 |
22 | public VoProperty(String name, String jsonProperty, String type) {
23 | this.name = Utils.cleanPropName(name);
24 | this.jsonProperty = jsonProperty;
25 | this.type = type;
26 | }
27 |
28 | public VoProperty(String name, String jsonProperty, String type, String description) {
29 | this.name = Utils.cleanPropName(name);
30 | this.jsonProperty = jsonProperty;
31 | this.type = type;
32 | this.description = StringUtils.replaceAll(StringUtils.trim(description), "\n", "");
33 | }
34 |
35 | public VoProperty(String name, String jsonProperty, Schema type) {
36 | this.name = Utils.cleanPropName(name);
37 | this.jsonProperty = jsonProperty;
38 | this.type = type.javaType()
39 | .replaceAll(SchemaHelper.LEFT_ARROW, "<")
40 | .replaceAll(SchemaHelper.RIGHT_ARROW, ">");
41 | }
42 |
43 | public VoProperty(String name, String jsonProperty, Schema type, String description) {
44 | this.name = Utils.cleanPropName(name);
45 | this.jsonProperty = jsonProperty;
46 | this.type = type.javaType()
47 | .replaceAll(SchemaHelper.LEFT_ARROW, "<")
48 | .replaceAll(SchemaHelper.RIGHT_ARROW, ">");
49 | this.description = StringUtils.replaceAll(StringUtils.trim(description), "\n", "");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/BasePomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 |
6 | import java.io.File;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import static cloud.unionj.generator.backend.springboot.Constants.MAVEN_POM;
11 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
12 |
13 | /**
14 | * @author created by tqccc
15 | * @version v0.0.1
16 | * description: cloud.unionj.generator.backend.springboot
17 | * date:2021/1/17
18 | */
19 | public abstract class BasePomGenerator extends DefaultGenerator {
20 |
21 | protected String outputDir;
22 |
23 | protected String groupId;
24 |
25 | protected String artifactId;
26 |
27 | protected String version;
28 |
29 | protected Boolean hasParent;
30 |
31 | protected String parentGroupId;
32 |
33 | protected String parentArtifactId;
34 |
35 | protected String parentVersion;
36 |
37 |
38 | public T outputDir(String outputDir) {
39 | this.outputDir = outputDir;
40 | return (T) this;
41 | }
42 |
43 | public T outputDirAsArtifactId() {
44 | this.outputDir = this.artifactId;
45 | return (T) this;
46 | }
47 |
48 | public T groupId(String groupId) {
49 | this.groupId = groupId;
50 | return (T) this;
51 | }
52 |
53 | public T groupIdAsParent() {
54 | this.groupId = this.parentGroupId;
55 | return (T) this;
56 | }
57 |
58 | public T artifactId(String artifactId) {
59 | this.artifactId = artifactId;
60 | return (T) this;
61 | }
62 |
63 | public T version(String version) {
64 | this.version = version;
65 | return (T) this;
66 | }
67 |
68 | public T versionAsParent() {
69 | this.version = parentVersion;
70 | return (T) this;
71 | }
72 |
73 | public T hasParent(Boolean hasParent) {
74 | this.hasParent = hasParent;
75 | return (T) this;
76 | }
77 |
78 | public T parentGroupId(String parentGroupId) {
79 | this.parentGroupId = parentGroupId;
80 | return (T) this;
81 | }
82 |
83 | public T parentArtifactId(String parentArtifactId) {
84 | this.parentArtifactId = parentArtifactId;
85 | return (T) this;
86 | }
87 |
88 | public T parentVersion(String parentVersion) {
89 | this.parentVersion = parentVersion;
90 | return (T) this;
91 | }
92 |
93 | protected BasePomGenerator() {
94 | super(false);
95 | this.outputDir = OUTPUT_DIR;
96 | this.hasParent = false;
97 | this.parentGroupId = "cloud.unionj.demo";
98 | this.parentArtifactId = "unionj-demo";
99 | this.parentVersion = "1.0.0-SNAPSHOT";
100 |
101 | this.groupId = this.parentGroupId;
102 | this.artifactId = this.parentArtifactId + "-unknown";
103 | this.version = this.parentVersion;
104 | }
105 |
106 | @Override
107 | public Map getInput() {
108 | Map input = new HashMap<>(8);
109 |
110 | input.put("hasParent", hasParent);
111 | input.put("parentGroupId", parentGroupId);
112 | input.put("parentArtifactId", parentArtifactId);
113 | input.put("parentVersion", parentVersion);
114 |
115 | input.put("groupId", groupId);
116 | input.put("artifactId", artifactId);
117 | input.put("version", version);
118 |
119 | return input;
120 | }
121 |
122 | @Override
123 | public String getOutputFile() {
124 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + MAVEN_POM;
125 | }
126 |
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/Constants.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * cloud.unionj.generator.backend.springboot
7 | * date 2020/12/22
8 | */
9 | public class Constants {
10 |
11 | public static final String OUTPUT_DIR = "backend/springboot";
12 | public static final String PACKAGE_NAME = "cloud.unionj.demo";
13 |
14 | public static final String MAVEN_POM = "pom.xml";
15 |
16 | public static final String DEFAULT_PROTO_PACKAGE = "proto";
17 | public static final String DEFAULT_VO_PACKAGE = "vo";
18 | public static final String DEFAULT_CONTROLLER_PACKAGE = "controller";
19 | public static final String DEFAULT_SERVICE_PACKAGE = "service";
20 | public static final String DEFAULT_FEIGN_PACKAGE = "feign";
21 | public static final String DOT = ".";
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ControllerJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Proto;
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import java.io.File;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
13 |
14 | /**
15 | * @author created by wubin
16 | * @version v0.1
17 | * cloud.unionj.generator
18 | * date 2020/11/22
19 | */
20 | public class ControllerJavaGenerator extends DefaultGenerator {
21 |
22 | private Proto proto;
23 | private String outputDir;
24 | private String packageName;
25 | private String voPackageName;
26 | private String protoPackageName;
27 | private String servicePackageName;
28 | private String controllerName;
29 | private String serviceName;
30 |
31 | public ControllerJavaGenerator(Proto proto, String packageName, String outputDir, String voPackageName,
32 | String protoPackageName, String servicePackageName, boolean noDefaultComment) {
33 | super(noDefaultComment);
34 | this.proto = proto;
35 | this.packageName = packageName;
36 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
37 | this.voPackageName = voPackageName;
38 | this.protoPackageName = protoPackageName;
39 | this.servicePackageName = servicePackageName;
40 | String baseName = StringUtils.removeEnd(StringUtils.capitalize(this.proto.getName()), "Proto");
41 | this.controllerName = baseName + "Controller";
42 | this.serviceName = baseName + "Service";
43 | }
44 |
45 | public ControllerJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
46 | String createDate, String parentVersion, String year, String copyright, Proto proto, String outputDir,
47 | String packageName, String voPackageName, String protoPackageName, String servicePackageName) {
48 | super(noDefaultComment, parentArtifactId, companyName,
49 | StringUtils.removeEnd(StringUtils.capitalize(proto.getName()), "Proto"), author, createDate, parentVersion,
50 | year, copyright);
51 | this.proto = proto;
52 | this.packageName = packageName;
53 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
54 | this.voPackageName = voPackageName;
55 | this.protoPackageName = protoPackageName;
56 | this.servicePackageName = servicePackageName;
57 | this.controllerName = baseName + "Controller";
58 | this.serviceName = baseName + "Service";
59 | }
60 |
61 | @Override
62 | public Map getInput() {
63 | Map input = new HashMap<>();
64 | input.put("packageName", this.packageName);
65 | input.put("voPackageName", this.voPackageName);
66 | input.put("protoPackageName", this.protoPackageName);
67 | input.put("servicePackageName", this.servicePackageName);
68 | input.put("imports", this.proto.getImports());
69 | input.put("name", this.controllerName);
70 | input.put("protoName", StringUtils.capitalize(this.proto.getName()));
71 | input.put("serviceName", this.serviceName);
72 | input.put("routers", this.proto.getRouters());
73 | input.put("noDefaultComment", this.noDefaultComment);
74 | input.put("parentArtifactId", this.parentArtifactId);
75 | input.put("companyName", this.companyName);
76 | input.put("baseName", this.baseName);
77 | input.put("author", this.author);
78 | input.put("createDate", this.createDate);
79 | input.put("parentVersion", this.parentVersion);
80 | input.put("year", this.year);
81 | input.put("copyright", this.copyright);
82 | return input;
83 | }
84 |
85 | @Override
86 | public String getTemplate() {
87 | return OUTPUT_DIR + "/controller.java.ftl";
88 | }
89 |
90 | @Override
91 | public String getOutputFile() {
92 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + this.controllerName + ".java";
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ControllerPomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 |
6 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
7 |
8 | public class ControllerPomGenerator extends BasePomGenerator {
9 |
10 | protected String protoGroupId;
11 |
12 | protected String protoArtifactId;
13 |
14 | protected String protoVersion;
15 |
16 | protected String serviceGroupId;
17 |
18 | protected String serviceArtifactId;
19 |
20 | protected String serviceVersion;
21 |
22 | public ControllerPomGenerator() {
23 | super();
24 |
25 | this.outputDir = OUTPUT_DIR + File.separator + "controller";
26 | this.artifactId = this.parentArtifactId + "-controller";
27 |
28 | this.hasParent = true;
29 |
30 | this.protoGroupId = this.parentGroupId;
31 | this.protoArtifactId = this.parentArtifactId + "-proto";
32 | this.protoVersion = this.parentVersion;
33 |
34 | this.serviceGroupId = this.parentGroupId;
35 | this.serviceArtifactId = this.parentArtifactId + "-service";
36 | this.serviceVersion = this.parentVersion;
37 | }
38 |
39 | public ControllerPomGenerator(String controllerDir) {
40 | super();
41 |
42 | this.outputDir = controllerDir;
43 | this.artifactId = this.parentArtifactId + "-controller";
44 |
45 | this.hasParent = true;
46 |
47 | this.protoGroupId = this.parentGroupId;
48 | this.protoArtifactId = this.parentArtifactId + "-proto";
49 | this.protoVersion = this.parentVersion;
50 |
51 | this.serviceGroupId = this.parentGroupId;
52 | this.serviceArtifactId = this.parentArtifactId + "-service";
53 | this.serviceVersion = this.parentVersion;
54 | }
55 |
56 | public ControllerPomGenerator protoGroupId(String protoGroupId) {
57 | this.protoGroupId = protoGroupId;
58 | return this;
59 | }
60 |
61 | public ControllerPomGenerator protoGroupIdAsParent() {
62 | this.protoGroupId = this.parentGroupId;
63 | return this;
64 | }
65 |
66 | public ControllerPomGenerator protoArtifactId(String protoArtifactId) {
67 | this.protoArtifactId = protoArtifactId;
68 | return this;
69 | }
70 |
71 | public ControllerPomGenerator protoVersion(String protoVersion) {
72 | this.protoVersion = protoVersion;
73 | return this;
74 | }
75 |
76 | public ControllerPomGenerator protoVersionAsParent() {
77 | this.protoVersion = this.parentVersion;
78 | return this;
79 | }
80 |
81 |
82 | public ControllerPomGenerator serviceGroupId(String serviceGroupId) {
83 | this.serviceGroupId = serviceGroupId;
84 | return this;
85 | }
86 |
87 | public ControllerPomGenerator serviceGroupIdAsParent() {
88 | this.serviceGroupId = this.parentGroupId;
89 | return this;
90 | }
91 |
92 | public ControllerPomGenerator serviceArtifactId(String serviceArtifactId) {
93 | this.serviceArtifactId = serviceArtifactId;
94 | return this;
95 | }
96 |
97 | public ControllerPomGenerator serviceVersion(String serviceVersion) {
98 | this.serviceVersion = serviceVersion;
99 | return this;
100 | }
101 |
102 | public ControllerPomGenerator serviceVersionAsParent() {
103 | this.serviceVersion = this.parentVersion;
104 | return this;
105 | }
106 |
107 | @Override
108 | public Map getInput() {
109 | Map input = super.getInput();
110 |
111 | input.put("protoGroupId", protoGroupId);
112 | input.put("protoArtifactId", protoArtifactId);
113 | input.put("protoVersion", protoVersion);
114 |
115 | input.put("serviceGroupId", serviceGroupId);
116 | input.put("serviceArtifactId", serviceArtifactId);
117 | input.put("serviceVersion", serviceVersion);
118 |
119 | return input;
120 | }
121 |
122 | @Override
123 | public String getTemplate() {
124 | return OUTPUT_DIR + "/controllerpom.xml.ftl";
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/FeignJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Proto;
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import java.io.File;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
13 |
14 | /**
15 | * @author created by wubin
16 | * @version v0.1
17 | * cloud.unionj.generator
18 | * date 2020/11/22
19 | */
20 | public class FeignJavaGenerator extends DefaultGenerator {
21 |
22 | private Proto proto;
23 | private String outputDir;
24 | private String packageName;
25 | private String voPackageName;
26 | private String serviceId;
27 | private String serviceBaseUrlKey;
28 | private String name;
29 |
30 | public FeignJavaGenerator(Proto proto, String packageName, String outputDir, String voPackageName, String serviceId,
31 | String serviceBaseUrlKey, boolean noDefaultComment) {
32 | super(noDefaultComment);
33 | this.proto = proto;
34 | this.packageName = packageName;
35 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
36 | this.voPackageName = voPackageName;
37 | this.serviceId = serviceId;
38 | this.serviceBaseUrlKey = serviceBaseUrlKey;
39 | this.name = StringUtils.removeEnd(StringUtils.capitalize(this.proto.getName()), "Proto") + "Client";
40 | }
41 |
42 | public FeignJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
43 | String createDate, String parentVersion, String year, String copyright, Proto proto, String outputDir,
44 | String packageName, String voPackageName, String serviceId, String serviceBaseUrlKey) {
45 | super(noDefaultComment, parentArtifactId, companyName,
46 | StringUtils.removeEnd(StringUtils.capitalize(proto.getName()), "Proto"), author, createDate, parentVersion,
47 | year, copyright);
48 | this.proto = proto;
49 | this.packageName = packageName;
50 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
51 | this.voPackageName = voPackageName;
52 | this.serviceId = serviceId;
53 | this.serviceBaseUrlKey = serviceBaseUrlKey;
54 | this.name = baseName + "Client";
55 | }
56 |
57 | @Override
58 | public Map getInput() {
59 | Map input = new HashMap<>();
60 | input.put("packageName", this.packageName);
61 | input.put("base", this.proto.getBase());
62 | input.put("name", this.name);
63 | input.put("routers", this.proto.getRouters());
64 | input.put("imports", this.proto.getImports());
65 | input.put("voPackageName", this.voPackageName);
66 | input.put("serviceId", this.serviceId);
67 | input.put("serviceBaseUrlKey", this.serviceBaseUrlKey);
68 | input.put("noDefaultComment", this.noDefaultComment);
69 | input.put("parentArtifactId", this.parentArtifactId);
70 | input.put("companyName", this.companyName);
71 | input.put("baseName", this.baseName);
72 | input.put("author", this.author);
73 | input.put("createDate", this.createDate);
74 | input.put("parentVersion", this.parentVersion);
75 | input.put("year", this.year);
76 | input.put("copyright", this.copyright);
77 | return input;
78 | }
79 |
80 | @Override
81 | public String getTemplate() {
82 | return OUTPUT_DIR + "/feign.java.ftl";
83 | }
84 |
85 | @Override
86 | public String getOutputFile() {
87 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + this.name + ".java";
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/FeignPomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 |
6 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
7 |
8 | /**
9 | * @author created by tqccc
10 | * @version v0.0.1
11 | * description: cloud.unionj.generator.backend.springboot
12 | * date:2021/1/17
13 | */
14 | public class FeignPomGenerator extends BasePomGenerator {
15 |
16 | protected String voGroupId;
17 |
18 | protected String voArtifactId;
19 |
20 | protected String voVersion;
21 |
22 | public FeignPomGenerator() {
23 | super();
24 |
25 | this.outputDir = OUTPUT_DIR + File.separator + "feign";
26 | this.artifactId = this.parentArtifactId + "-feign";
27 |
28 | this.hasParent = true;
29 |
30 | this.voGroupId = this.parentGroupId;
31 | this.voArtifactId = this.parentArtifactId + "-vo";
32 | this.voVersion = this.parentVersion;
33 | }
34 |
35 | public FeignPomGenerator(String feignDir) {
36 | super();
37 |
38 | this.outputDir = feignDir;
39 | this.artifactId = this.parentArtifactId + "-feign";
40 |
41 | this.hasParent = true;
42 |
43 | this.voGroupId = this.parentGroupId;
44 | this.voArtifactId = this.parentArtifactId + "-vo";
45 | this.voVersion = this.parentVersion;
46 | }
47 |
48 | public FeignPomGenerator voGroupId(String voGroupId) {
49 | this.voGroupId = voGroupId;
50 | return this;
51 | }
52 |
53 | public FeignPomGenerator voGroupIdAsParent() {
54 | this.voGroupId = this.parentGroupId;
55 | return this;
56 | }
57 |
58 | public FeignPomGenerator voArtifactId(String voArtifactId) {
59 | this.voArtifactId = voArtifactId;
60 | return this;
61 | }
62 |
63 | public FeignPomGenerator voVersion(String voVersion) {
64 | this.voVersion = voVersion;
65 | return this;
66 | }
67 |
68 | public FeignPomGenerator voVersionAsParent() {
69 | this.voVersion = this.parentVersion;
70 | return this;
71 | }
72 |
73 | @Override
74 | public Map getInput() {
75 | Map input = super.getInput();
76 |
77 | input.put("voGroupId", voGroupId);
78 | input.put("voArtifactId", voArtifactId);
79 | input.put("voVersion", voVersion);
80 |
81 | return input;
82 | }
83 |
84 | @Override
85 | public String getTemplate() {
86 | return OUTPUT_DIR + "/feignpom.xml.ftl";
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/OutputConfig.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 |
5 | /**
6 | * @author created by tqccc
7 | * @version v0.0.1
8 | * description: cloud.unionj.generator.backend.springboot
9 | * date:2021/1/17
10 | */
11 | public class OutputConfig {
12 | private String packageName;
13 | private String outputDir;
14 |
15 | public OutputConfig(String packageName, String outputDir) {
16 | this.packageName = packageName;
17 | this.outputDir = outputDir;
18 |
19 | validate();
20 | }
21 |
22 | public String getPackageName() {
23 | return packageName;
24 | }
25 |
26 | public String getOutputDir() {
27 | return outputDir;
28 | }
29 |
30 | public void setPackageName(String packageName) {
31 | this.packageName = packageName;
32 | }
33 |
34 | public void setOutputDir(String outputDir) {
35 | this.outputDir = outputDir;
36 | }
37 |
38 | public void validate() throws UnsupportedOperationException {
39 | if (StringUtils.isBlank(packageName)) {
40 | throw new UnsupportedOperationException("packageName required");
41 | }
42 |
43 | if (StringUtils.isBlank(outputDir)) {
44 | throw new UnsupportedOperationException("outputDir required");
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/OutputType.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | /**
4 | * @author created by tqccc
5 | * @version v0.0.1
6 | * description: cloud.unionj.generator.backend.springboot
7 | * date:2021/1/17
8 | */
9 | public enum OutputType {
10 | /**
11 | * check
12 | */
13 | CHECK,
14 |
15 | /**
16 | * overwrite
17 | */
18 | OVERWRITE
19 | }
20 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ProtoJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Proto;
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import java.io.File;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
13 |
14 | /**
15 | * @author created by wubin
16 | * @version v0.1
17 | * cloud.unionj.generator
18 | * date 2020/11/22
19 | */
20 | public class ProtoJavaGenerator extends DefaultGenerator {
21 |
22 | private Proto proto;
23 | private String outputDir;
24 | private String packageName;
25 | private String voPackageName;
26 |
27 | public ProtoJavaGenerator(Proto proto, String packageName, String outputDir, String voPackageName,
28 | boolean noDefaultComment) {
29 | super(noDefaultComment);
30 | this.proto = proto;
31 | this.packageName = packageName;
32 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
33 | this.voPackageName = voPackageName;
34 | }
35 |
36 | public ProtoJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
37 | String createDate, String parentVersion, String year, String copyright, Proto proto, String outputDir,
38 | String packageName, String voPackageName) {
39 | super(noDefaultComment, parentArtifactId, companyName,
40 | StringUtils.removeEnd(StringUtils.capitalize(proto.getName()), "Proto"), author, createDate, parentVersion,
41 | year, copyright);
42 | this.proto = proto;
43 | this.packageName = packageName;
44 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
45 | this.voPackageName = voPackageName;
46 | }
47 |
48 | @Override
49 | public Map getInput() {
50 | Map input = new HashMap<>();
51 | input.put("packageName", this.packageName);
52 | input.put("base", this.proto.getBase());
53 | input.put("name", StringUtils.capitalize(this.proto.getName()));
54 | input.put("routers", this.proto.getRouters());
55 | input.put("imports", this.proto.getImports());
56 | input.put("voPackageName", this.voPackageName);
57 | input.put("noDefaultComment", this.noDefaultComment);
58 | input.put("parentArtifactId", this.parentArtifactId);
59 | input.put("companyName", this.companyName);
60 | input.put("baseName", this.baseName);
61 | input.put("author", this.author);
62 | input.put("createDate", this.createDate);
63 | input.put("parentVersion", this.parentVersion);
64 | input.put("year", this.year);
65 | input.put("copyright", this.copyright);
66 | return input;
67 | }
68 |
69 | @Override
70 | public String getTemplate() {
71 | return OUTPUT_DIR + "/proto.java.ftl";
72 | }
73 |
74 | @Override
75 | public String getOutputFile() {
76 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + StringUtils.capitalize(
77 | this.proto.getName()) + ".java";
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ProtoPomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 |
6 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
7 |
8 | /**
9 | * @author created by tqccc
10 | * @version v0.0.1
11 | * description: cloud.unionj.generator.backend.springboot
12 | * date:2021/1/17
13 | */
14 | public class ProtoPomGenerator extends BasePomGenerator {
15 |
16 | protected String voGroupId;
17 |
18 | protected String voArtifactId;
19 |
20 | protected String voVersion;
21 |
22 | public ProtoPomGenerator() {
23 | super();
24 |
25 | this.outputDir = OUTPUT_DIR + File.separator + "proto";
26 | this.artifactId = this.parentArtifactId + "-proto";
27 |
28 | this.hasParent = true;
29 |
30 | this.voGroupId = this.parentGroupId;
31 | this.voArtifactId = this.parentArtifactId + "-vo";
32 | this.voVersion = this.parentVersion;
33 | }
34 |
35 | public ProtoPomGenerator(String protoDir) {
36 | super();
37 |
38 | this.outputDir = protoDir;
39 | this.artifactId = this.parentArtifactId + "-proto";
40 |
41 | this.hasParent = true;
42 |
43 | this.voGroupId = this.parentGroupId;
44 | this.voArtifactId = this.parentArtifactId + "-vo";
45 | this.voVersion = this.parentVersion;
46 | }
47 |
48 | public ProtoPomGenerator voGroupId(String voGroupId) {
49 | this.voGroupId = voGroupId;
50 | return this;
51 | }
52 |
53 | public ProtoPomGenerator voGroupIdAsParent() {
54 | this.voGroupId = this.parentGroupId;
55 | return this;
56 | }
57 |
58 | public ProtoPomGenerator voArtifactId(String voArtifactId) {
59 | this.voArtifactId = voArtifactId;
60 | return this;
61 | }
62 |
63 | public ProtoPomGenerator voVersion(String voVersion) {
64 | this.voVersion = voVersion;
65 | return this;
66 | }
67 |
68 | public ProtoPomGenerator voVersionAsParent() {
69 | this.voVersion = this.parentVersion;
70 | return this;
71 | }
72 |
73 | @Override
74 | public Map getInput() {
75 | Map input = super.getInput();
76 |
77 | input.put("voGroupId", voGroupId);
78 | input.put("voArtifactId", voArtifactId);
79 | input.put("voVersion", voVersion);
80 |
81 | return input;
82 | }
83 |
84 | @Override
85 | public String getTemplate() {
86 | return OUTPUT_DIR + "/protopom.xml.ftl";
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ServiceImplJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Proto;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | import java.io.File;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
14 |
15 | /**
16 | * @author created by wubin
17 | * @version v0.1
18 | * cloud.unionj.generator
19 | * date 2020/11/22
20 | */
21 | @Slf4j
22 | public class ServiceImplJavaGenerator extends DefaultGenerator {
23 |
24 | private Proto proto;
25 | private String outputDir;
26 | private String packageName;
27 | private String voPackageName;
28 | private String serviceName;
29 |
30 | public ServiceImplJavaGenerator(Proto proto, String packageName, String outputDir, String voPackageName,
31 | boolean noDefaultComment) {
32 | super(noDefaultComment);
33 | this.proto = proto;
34 | this.packageName = packageName;
35 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
36 | this.voPackageName = voPackageName;
37 | String baseName = StringUtils.removeEnd(StringUtils.capitalize(this.proto.getName()), "Proto");
38 | this.serviceName = baseName + "Service";
39 | }
40 |
41 | public ServiceImplJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
42 | String createDate, String parentVersion, String year, String copyright, Proto proto, String outputDir,
43 | String packageName, String voPackageName) {
44 | super(noDefaultComment, parentArtifactId, companyName,
45 | StringUtils.removeEnd(StringUtils.capitalize(proto.getName()), "Proto"), author, createDate, parentVersion,
46 | year, copyright);
47 | this.proto = proto;
48 | this.packageName = packageName;
49 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
50 | this.voPackageName = voPackageName;
51 | this.serviceName = baseName + "Service";
52 | }
53 |
54 | @Override
55 | public Map getInput() {
56 | Map input = new HashMap<>();
57 | input.put("packageName", this.packageName);
58 | input.put("name", this.serviceName);
59 | input.put("routers", this.proto.getRouters());
60 | input.put("imports", this.proto.getImports());
61 | input.put("voPackageName", this.voPackageName);
62 | input.put("noDefaultComment", this.noDefaultComment);
63 | input.put("parentArtifactId", this.parentArtifactId);
64 | input.put("companyName", this.companyName);
65 | input.put("baseName", this.baseName);
66 | input.put("author", this.author);
67 | input.put("createDate", this.createDate);
68 | input.put("parentVersion", this.parentVersion);
69 | input.put("year", this.year);
70 | input.put("copyright", this.copyright);
71 | return input;
72 | }
73 |
74 | @Override
75 | public String getTemplate() {
76 | return OUTPUT_DIR + "/serviceimpl.java.ftl";
77 | }
78 |
79 | @Override
80 | public String getOutputFile() {
81 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + this.serviceName + "Impl.java";
82 | }
83 |
84 | @Override
85 | public String generate() {
86 | File file = new File(getOutputFile());
87 | if (file.exists()) {
88 | log.info(file + " already exists, skip generating");
89 | return getOutputFile();
90 | }
91 | return super.generateFormat();
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ServiceJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Proto;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | import java.io.File;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
14 |
15 | /**
16 | * @author created by wubin
17 | * @version v0.1
18 | * cloud.unionj.generator
19 | * date 2020/11/22
20 | */
21 | @Slf4j
22 | public class ServiceJavaGenerator extends DefaultGenerator {
23 |
24 | private Proto proto;
25 | private String outputDir;
26 | private String packageName;
27 | private String protoPackageName;
28 | private String serviceName;
29 |
30 | public ServiceJavaGenerator(Proto proto, String packageName, String outputDir, String protoPackageName,
31 | boolean noDefaultComment) {
32 | super(noDefaultComment);
33 | this.proto = proto;
34 | this.packageName = packageName;
35 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
36 | this.protoPackageName = protoPackageName;
37 | String baseName = StringUtils.removeEnd(StringUtils.capitalize(this.proto.getName()), "Proto");
38 | this.serviceName = baseName + "Service";
39 | }
40 |
41 | public ServiceJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
42 | String createDate, String parentVersion, String year, String copyright, Proto proto, String outputDir,
43 | String packageName, String protoPackageName) {
44 | super(noDefaultComment, parentArtifactId, companyName,
45 | StringUtils.removeEnd(StringUtils.capitalize(proto.getName()), "Proto"), author, createDate, parentVersion,
46 | year, copyright);
47 | this.proto = proto;
48 | this.packageName = packageName;
49 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
50 | this.protoPackageName = protoPackageName;
51 | this.serviceName = baseName + "Service";
52 | }
53 |
54 | @Override
55 | public Map getInput() {
56 | Map input = new HashMap<>();
57 | input.put("packageName", this.packageName);
58 | input.put("name", this.serviceName);
59 | input.put("protoName", StringUtils.capitalize(this.proto.getName()));
60 | input.put("protoPackageName", this.protoPackageName);
61 | input.put("noDefaultComment", this.noDefaultComment);
62 | input.put("parentArtifactId", this.parentArtifactId);
63 | input.put("companyName", this.companyName);
64 | input.put("baseName", this.baseName);
65 | input.put("author", this.author);
66 | input.put("createDate", this.createDate);
67 | input.put("parentVersion", this.parentVersion);
68 | input.put("year", this.year);
69 | input.put("copyright", this.copyright);
70 | return input;
71 | }
72 |
73 | @Override
74 | public String getTemplate() {
75 | return OUTPUT_DIR + "/service.java.ftl";
76 | }
77 |
78 | @Override
79 | public String getOutputFile() {
80 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + this.serviceName + ".java";
81 | }
82 |
83 | @Override
84 | public String generate() {
85 | File file = new File(getOutputFile());
86 | if (file.exists()) {
87 | log.info(file + " already exists, skip generating");
88 | return getOutputFile();
89 | }
90 | return super.generateFormat();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/ServicePomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 |
6 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
7 |
8 | /**
9 | * @author created by tqccc
10 | * @version v0.0.1
11 | * description: cloud.unionj.generator.backend.springboot
12 | * date:2021/1/17
13 | */
14 | public class ServicePomGenerator extends BasePomGenerator {
15 |
16 | protected String voGroupId;
17 |
18 | protected String voArtifactId;
19 |
20 | protected String voVersion;
21 |
22 | protected String protoGroupId;
23 |
24 | protected String protoArtifactId;
25 |
26 | protected String protoVersion;
27 |
28 | public ServicePomGenerator() {
29 | super();
30 |
31 | this.outputDir = OUTPUT_DIR + File.separator + "service";
32 | this.artifactId = this.parentArtifactId + "-service";
33 |
34 | this.hasParent = true;
35 |
36 | this.voGroupId = this.parentGroupId;
37 | this.voArtifactId = this.parentArtifactId + "-vo";
38 | this.voVersion = this.parentVersion;
39 |
40 | this.protoGroupId = this.parentGroupId;
41 | this.protoArtifactId = this.parentArtifactId + "-proto";
42 | this.protoVersion = this.parentVersion;
43 | }
44 |
45 | public ServicePomGenerator(String serviceDir) {
46 | super();
47 |
48 | this.outputDir = serviceDir;
49 | this.artifactId = this.parentArtifactId + "-service";
50 |
51 | this.hasParent = true;
52 |
53 | this.voGroupId = this.parentGroupId;
54 | this.voArtifactId = this.parentArtifactId + "-vo";
55 | this.voVersion = this.parentVersion;
56 |
57 | this.protoGroupId = this.parentGroupId;
58 | this.protoArtifactId = this.parentArtifactId + "-proto";
59 | this.protoVersion = this.parentVersion;
60 | }
61 |
62 | public ServicePomGenerator voGroupId(String voGroupId) {
63 | this.voGroupId = voGroupId;
64 | return this;
65 | }
66 |
67 | public ServicePomGenerator voGroupIdAsParent() {
68 | this.voGroupId = this.parentGroupId;
69 | return this;
70 | }
71 |
72 | public ServicePomGenerator voArtifactId(String voArtifactId) {
73 | this.voArtifactId = voArtifactId;
74 | return this;
75 | }
76 |
77 | public ServicePomGenerator voVersion(String voVersion) {
78 | this.voVersion = voVersion;
79 | return this;
80 | }
81 |
82 | public ServicePomGenerator voVersionAsParent() {
83 | this.voVersion = this.parentVersion;
84 | return this;
85 | }
86 |
87 | public ServicePomGenerator protoGroupId(String protoGroupId) {
88 | this.protoGroupId = protoGroupId;
89 | return this;
90 | }
91 |
92 | public ServicePomGenerator protoGroupIdAsParent() {
93 | this.protoGroupId = this.parentGroupId;
94 | return this;
95 | }
96 |
97 | public ServicePomGenerator protoArtifactId(String protoArtifactId) {
98 | this.protoArtifactId = protoArtifactId;
99 | return this;
100 | }
101 |
102 | public ServicePomGenerator protoVersion(String protoVersion) {
103 | this.protoVersion = protoVersion;
104 | return this;
105 | }
106 |
107 | public ServicePomGenerator protoVersionAsParent() {
108 | this.protoVersion = this.parentVersion;
109 | return this;
110 | }
111 |
112 | @Override
113 | public Map getInput() {
114 | Map input = super.getInput();
115 |
116 | input.put("voGroupId", voGroupId);
117 | input.put("voArtifactId", voArtifactId);
118 | input.put("voVersion", voVersion);
119 |
120 | input.put("protoGroupId", protoGroupId);
121 | input.put("protoArtifactId", protoArtifactId);
122 | input.put("protoVersion", protoVersion);
123 |
124 | return input;
125 | }
126 |
127 | @Override
128 | public String getTemplate() {
129 | return OUTPUT_DIR + "/servicepom.xml.ftl";
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/VoJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import cloud.unionj.generator.backend.docparser.entity.Vo;
6 | import org.apache.commons.lang3.StringUtils;
7 |
8 | import java.io.File;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
13 |
14 | /**
15 | * @author created by wubin
16 | * @version v0.1
17 | * cloud.unionj.generator
18 | * date 2020/11/22
19 | */
20 | public class VoJavaGenerator extends DefaultGenerator {
21 |
22 | private Vo vo;
23 | private String outputDir;
24 | private String packageName;
25 |
26 | public VoJavaGenerator(Vo vo, String packageName, String outputDir, boolean noDefaultComment) {
27 | super(noDefaultComment);
28 | this.vo = vo;
29 | this.packageName = packageName;
30 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
31 | }
32 |
33 | public VoJavaGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String author,
34 | String createDate, String parentVersion, String year, String copyright, Vo vo, String outputDir,
35 | String packageName) {
36 | super(noDefaultComment, parentArtifactId, companyName, "", author, createDate, parentVersion, year, copyright);
37 | this.vo = vo;
38 | this.packageName = packageName;
39 | this.outputDir = outputDir + "/src/main/java/" + packageName.replace(".", "/");
40 | }
41 |
42 | @Override
43 | public Map getInput() {
44 | Map input = new HashMap<>();
45 | input.put("packageName", this.packageName);
46 | input.put("name", StringUtils.capitalize(this.vo.getName()));
47 | input.put("description", this.vo.getDescription());
48 | input.put("properties", this.vo.getProperties());
49 | input.put("enumTypes", this.vo.getEnumTypes());
50 | input.put("imports", this.vo.getImports());
51 | input.put("noDefaultComment", this.noDefaultComment);
52 | input.put("parentArtifactId", this.parentArtifactId);
53 | input.put("companyName", this.companyName);
54 | input.put("author", this.author);
55 | input.put("createDate", this.createDate);
56 | input.put("parentVersion", this.parentVersion);
57 | input.put("year", this.year);
58 | input.put("copyright", this.copyright);
59 | return input;
60 | }
61 |
62 | @Override
63 | public String getTemplate() {
64 | return OUTPUT_DIR + "/vo.java.ftl";
65 | }
66 |
67 | @Override
68 | public String getOutputFile() {
69 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + StringUtils.capitalize(this.vo.getName())
70 | .replaceAll("<.*>", "") + ".java";
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/java/cloud/unionj/generator/backend/springboot/VoPomGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import java.io.File;
4 |
5 | import static cloud.unionj.generator.backend.springboot.Constants.OUTPUT_DIR;
6 |
7 | /**
8 | * @author created by tqccc
9 | * @version v0.0.1
10 | * description: cloud.unionj.generator.backend.springboot
11 | * date:2021/1/12
12 | */
13 | public class VoPomGenerator extends BasePomGenerator {
14 |
15 | public VoPomGenerator() {
16 | super();
17 |
18 | this.outputDir = OUTPUT_DIR + File.separator + "vo";
19 | this.artifactId = this.parentArtifactId + "-vo";
20 |
21 | this.hasParent = true;
22 | }
23 |
24 | public VoPomGenerator(String voDir) {
25 | super();
26 |
27 | this.outputDir = voDir;
28 | this.artifactId = this.parentArtifactId + "-vo";
29 |
30 | this.hasParent = true;
31 | }
32 |
33 | @Override
34 | public String getTemplate() {
35 | return OUTPUT_DIR + "/vopom.xml.ftl";
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/controller.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import lombok.RequiredArgsConstructor;
10 | import org.springframework.web.bind.annotation.RestController;
11 | import org.springframework.http.ResponseEntity;
12 | import org.springframework.web.multipart.MultipartFile;
13 | import java.util.*;
14 | import ${voPackageName}.*;
15 | import ${protoPackageName}.${protoName};
16 | import ${servicePackageName}.${serviceName};
17 | <#if imports??>
18 | <#list imports as import>
19 | import ${import};
20 | #list>
21 | #if>
22 |
23 | /**
24 | * @ProductName: ${companyName} ${parentArtifactId}
25 | * @Description: ${baseName}模块控制层实现类
26 | * @Author: ${author}
27 | * @CreateDate: ${createDate}
28 | * @Version: ${parentVersion}
29 | * @Copyright © ${year} ${copyright}
30 | */
31 | @RestController
32 | @RequiredArgsConstructor
33 | public class ${name} implements ${protoName} {
34 |
35 | private final ${serviceName} ${serviceName?uncap_first};
36 |
37 | <#list routers as router>
38 | <#compress>@Override
39 | public ${router.respData.type} ${router.name}(
40 | <#assign x>
41 | <#if router.pathParams??>
42 | <#list router.pathParams as pathParam>
43 | ${pathParam.type} ${pathParam.name},
44 | #list>
45 | #if>
46 | <#if router.queryParams??>
47 | <#list router.queryParams as queryParam>
48 | ${queryParam.type} ${queryParam.name},
49 | #list>
50 | #if>
51 | <#if router.reqBody??>
52 | ${router.reqBody.type} ${router.reqBody.name},
53 | #if>
54 | <#if router.file??>
55 | ${router.file.type} ${router.file.name},
56 | #if>
57 | #assign>
58 | ${x?keep_before_last(",")?trim}
59 | ) {
60 | return ${serviceName?uncap_first}.${router.name}(
61 | <#assign x>
62 | <#if router.pathParams??>
63 | <#list router.pathParams as pathParam>
64 | ${pathParam.name},
65 | #list>
66 | #if>
67 | <#if router.queryParams??>
68 | <#list router.queryParams as queryParam>
69 | ${queryParam.name},
70 | #list>
71 | #if>
72 | <#if router.reqBody??>
73 | ${router.reqBody.name},
74 | #if>
75 | <#if router.file??>
76 | ${router.file.name},
77 | #if>
78 | #assign>
79 | ${x?keep_before_last(",")?trim}
80 | );
81 | }#compress>
82 | <#sep>
83 |
84 | #sep>
85 | #list>
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/controllerpom.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | <#if hasParent>
7 |
8 | ${parentGroupId}
9 | ${parentArtifactId}
10 | ${parentVersion}
11 |
12 | #if>
13 |
14 | ${groupId}
15 | ${artifactId}
16 | ${version}
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | ${protoGroupId}
33 | ${protoArtifactId}
34 | ${protoVersion}
35 |
36 |
37 | ${serviceGroupId}
38 | ${serviceArtifactId}
39 | ${serviceVersion}
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/feign.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.*;
11 | import org.springframework.web.multipart.MultipartFile;
12 | import org.springframework.cloud.openfeign.FeignClient;
13 | import java.util.*;
14 | import ${voPackageName}.*;
15 | <#if imports??>
16 | <#list imports as import>
17 | import ${import};
18 | #list>
19 | #if>
20 |
21 | /**
22 | * @ProductName: ${companyName} ${parentArtifactId}
23 | * @Description: ${serviceId}服务${baseName}模块REST接口Openfeign客户端
24 | * @Author: ${author}
25 | * @CreateDate: ${createDate}
26 | * @Version: ${parentVersion}
27 | * @Copyright © ${year} ${copyright}
28 | */
29 | @FeignClient(contextId = "${name?uncap_first}", value = "${serviceId}"<#if serviceBaseUrlKey??>, url = "${r"${"}${serviceBaseUrlKey}${r":}"}"#if>)
30 | public interface ${name} {
31 |
32 | <#list routers as router>
33 | <#compress>@${router.httpMethod?capitalize}Mapping("${router.endpoint}")
34 | ${router.respData.type} ${router.name}(
35 | <#assign x>
36 | <#if router.pathParams??>
37 | <#list router.pathParams as pathParam>
38 | <#if pathParam.required>@PathVariable("${pathParam.name}")<#else>@PathVariable(value="${pathParam.name}", required=false)#if> ${pathParam.type} ${pathParam.name},
39 | #list>
40 | #if>
41 | <#if router.queryParams??>
42 | <#list router.queryParams as queryParam>
43 | <#if queryParam.required>@RequestParam("${queryParam.requestParam}")<#elseif queryParam.defaultValue??>@RequestParam(value="${queryParam.requestParam}", required=false, defaultValue="${queryParam.defaultValue}")<#else>@RequestParam(value="${queryParam.requestParam}", required=false)#if> ${queryParam.type} ${queryParam.name},
44 | #list>
45 | #if>
46 | <#if router.reqBody??>
47 | <#if router.reqBody.required>@RequestBody<#else>@RequestBody(required=false)#if> ${router.reqBody.type} ${router.reqBody.name},
48 | #if>
49 | <#if router.file??>
50 | <#if router.file.required>@RequestPart("${router.file.name}")<#else>@RequestPart(value="${router.file.name}", required=false)#if> ${router.file.type} ${router.file.name},
51 | #if>
52 | #assign>
53 | ${x?keep_before_last(",")?trim}
54 | );#compress>
55 | <#sep>
56 |
57 | #sep>
58 | #list>
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/feignpom.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | <#if hasParent>
7 |
8 | ${parentGroupId}
9 | ${parentArtifactId}
10 | ${parentVersion}
11 |
12 | #if>
13 |
14 | ${groupId}
15 | ${artifactId}
16 | ${version}
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.cloud
33 | spring-cloud-starter-openfeign
34 |
35 |
36 | ${voGroupId}
37 | ${voArtifactId}
38 | ${voVersion}
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/proto.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.*;
11 | import org.springframework.web.multipart.MultipartFile;
12 | import java.util.*;
13 | import io.swagger.v3.oas.annotations.Operation;
14 | import io.swagger.v3.oas.annotations.Parameter;
15 | import io.swagger.v3.oas.annotations.tags.Tag;
16 | import ${voPackageName}.*;
17 | <#if imports??>
18 | <#list imports as import>
19 | import ${import};
20 | #list>
21 | #if>
22 |
23 | /**
24 | * @ProductName: ${companyName} ${parentArtifactId}
25 | * @Description: ${baseName}模块控制层接口类
26 | * @Author: ${author}
27 | * @CreateDate: ${createDate}
28 | * @Version: ${parentVersion}
29 | * @Copyright © ${year} ${copyright}
30 | */
31 | @Tag(name = "${baseName}模块接口")
32 | <#if base??>
33 | @RequestMapping("${base}")
34 | #if>
35 | public interface ${name} {
36 |
37 | <#list routers as router>
38 | <#compress>
39 | @Operation(summary = "${router.summary!""}", description = "${router.description!""}")
40 | @${router.httpMethod?capitalize}Mapping("${router.endpoint}")
41 | ${router.respData.type} ${router.name}(
42 | <#assign x>
43 | <#if router.pathParams??>
44 | <#list router.pathParams as pathParam>
45 | @Parameter(description = "${pathParam.description!""}") <#if pathParam.required>@PathVariable("${pathParam.name}")<#else>@PathVariable(value="${pathParam.name}", required=false)#if> ${pathParam.type} ${pathParam.name},
46 | #list>
47 | #if>
48 | <#if router.queryParams??>
49 | <#list router.queryParams as queryParam>
50 | @Parameter(description = "${queryParam.description!""}") <#if queryParam.required>@RequestParam("${queryParam.requestParam}")<#elseif queryParam.defaultValue??>@RequestParam(value="${queryParam.requestParam}", required=false, defaultValue="${queryParam.defaultValue}")<#else>@RequestParam(value="${queryParam.requestParam}", required=false)#if> ${queryParam.type} ${queryParam.name},
51 | #list>
52 | #if>
53 | <#if router.reqBody??>
54 | <#if router.reqBody.required>@RequestBody<#else>@RequestBody(required=false)#if> ${router.reqBody.type} ${router.reqBody.name},
55 | #if>
56 | <#if router.file??>
57 | @Parameter(description = "${router.file.description!""}") <#if router.file.required>@RequestPart("${router.file.name}")<#else>@RequestPart(value="${router.file.name}", required=false)#if> ${router.file.type} ${router.file.name},
58 | #if>
59 | #assign>
60 | ${x?keep_before_last(",")?trim}
61 | );#compress>
62 | <#sep>
63 |
64 | #sep>
65 | #list>
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/protopom.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | <#if hasParent>
7 |
8 | ${parentGroupId}
9 | ${parentArtifactId}
10 | ${parentVersion}
11 |
12 | #if>
13 |
14 | ${groupId}
15 | ${artifactId}
16 | ${version}
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | ${voGroupId}
33 | ${voArtifactId}
34 | ${voVersion}
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/service.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import ${protoPackageName}.${protoName};
10 |
11 | /**
12 | * @ProductName: ${companyName} ${parentArtifactId}
13 | * @Description: ${baseName}模块服务层接口类
14 | * @Author: ${author}
15 | * @CreateDate: ${createDate}
16 | * @Version: ${parentVersion}
17 | * @Copyright © ${year} ${copyright}
18 | */
19 | public interface ${name} extends ${protoName} {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/serviceimpl.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import org.springframework.stereotype.Service;
10 | import lombok.SneakyThrows;
11 | import org.springframework.web.multipart.MultipartFile;
12 | import java.util.*;
13 | import ${voPackageName}.*;
14 | <#if imports??>
15 | <#list imports as import>
16 | import ${import};
17 | #list>
18 | #if>
19 |
20 | /**
21 | * @ProductName: ${companyName} ${parentArtifactId}
22 | * @Description: ${baseName}模块服务层实现类
23 | * @Author: ${author}
24 | * @CreateDate: ${createDate}
25 | * @Version: ${parentVersion}
26 | * @Copyright © ${year} ${copyright}
27 | */
28 | @Service
29 | public class ${name}Impl implements ${name} {
30 |
31 | <#list routers as router>
32 | <#compress>@SneakyThrows
33 | @Override
34 | public ${router.respData.type} ${router.name}(
35 | <#assign x>
36 | <#if router.pathParams??>
37 | <#list router.pathParams as pathParam>
38 | ${pathParam.type} ${pathParam.name},
39 | #list>
40 | #if>
41 | <#if router.queryParams??>
42 | <#list router.queryParams as queryParam>
43 | ${queryParam.type} ${queryParam.name},
44 | #list>
45 | #if>
46 | <#if router.reqBody??>
47 | ${router.reqBody.type} ${router.reqBody.name},
48 | #if>
49 | <#if router.file??>
50 | ${router.file.type} ${router.file.name},
51 | #if>
52 | #assign>
53 | ${x?keep_before_last(",")?trim}
54 | ){
55 | throw new Exception("Implement me");
56 | }#compress>
57 | <#sep>
58 |
59 | #sep>
60 | #list>
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/servicepom.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | <#if hasParent>
7 |
8 | ${parentGroupId}
9 | ${parentArtifactId}
10 | ${parentVersion}
11 |
12 | #if>
13 |
14 | ${groupId}
15 | ${artifactId}
16 | ${version}
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | ${voGroupId}
33 | ${voArtifactId}
34 | ${voVersion}
35 |
36 |
37 | ${protoGroupId}
38 | ${protoArtifactId}
39 | ${protoVersion}
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/vo.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-maven-plugin. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import lombok.Data;
10 | import com.fasterxml.jackson.annotation.JsonProperty;
11 | import com.fasterxml.jackson.annotation.JsonCreator;
12 | import com.fasterxml.jackson.annotation.JsonValue;
13 | import io.swagger.v3.oas.annotations.media.Schema;
14 | import java.io.Serializable;
15 | import java.util.*;
16 | <#if imports??>
17 | <#list imports as import>
18 | import ${import};
19 | #list>
20 | #if>
21 |
22 | /**
23 | * @ProductName: ${companyName} ${parentArtifactId}
24 | * @Description: 控制层${name}类
25 | * @Author: ${author}
26 | * @CreateDate: ${createDate}
27 | * @Version: ${parentVersion}
28 | * @Copyright © ${year} ${copyright}
29 | */
30 | <#if description??>@Schema(description = "${description}")#if>
31 | @Data
32 | public class ${name} implements Serializable {
33 |
34 | private static final long serialVersionUID = 1L;
35 |
36 | <#list properties as property>
37 | <#if property.description??>@Schema(description = "${property.description}")#if>
38 | @JsonProperty("${property.jsonProperty}")
39 | private ${property.type} ${property.name};
40 | #list>
41 |
42 | <#if enumTypes??>
43 | <#list enumTypes as enumType>
44 | public enum ${enumType.name} {
45 | <#list enumType.enums as enum>
46 | ${enum.name}("${enum.value}")<#if enum?has_next>,<#else>;#if>
47 | #list>
48 |
49 | private String value;
50 |
51 | ${enumType.name}(String value) {
52 | this.value = value;
53 | }
54 |
55 | @Override
56 | @JsonValue
57 | public String toString() {
58 | return String.valueOf(value);
59 | }
60 |
61 | @JsonCreator
62 | public static ${enumType.name} fromValue(String text) {
63 | for (${enumType.name} b : ${enumType.name}.values()) {
64 | if (String.valueOf(b.value).equals(text)) {
65 | return b;
66 | }
67 | }
68 | return null;
69 | }
70 | }
71 | #list>
72 | #if>
73 | }
74 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/main/resources/templates/backend/springboot/vopom.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | <#if hasParent>
7 |
8 | ${parentGroupId}
9 | ${parentArtifactId}
10 | ${parentVersion}
11 |
12 | #if>
13 |
14 | ${groupId}
15 | ${artifactId}
16 | ${version}
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-annotations
26 | 2.10.2
27 |
28 |
29 | org.projectlombok
30 | lombok
31 | 1.18.12
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/PodamTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend;
2 |
3 | import uk.co.jemos.podam.api.PodamFactory;
4 | import uk.co.jemos.podam.api.PodamFactoryImpl;
5 |
6 | import java.util.List;
7 |
8 | public class PodamTest {
9 |
10 | public enum RoleType {
11 | PRODUCT_MEMBER;
12 | }
13 |
14 | public static void main(String[] args) {
15 | PodamFactory factory = new PodamFactoryImpl();
16 | Long aLong = factory.manufacturePojo(Long.class);
17 | System.out.println(aLong);
18 |
19 | Integer integer = factory.manufacturePojo(int.class);
20 | System.out.println(integer);
21 |
22 | @SuppressWarnings("unchecked")
23 | List list = factory.manufacturePojo(List.class, String.class);
24 | System.out.println(list);
25 |
26 | String[] strings = factory.manufacturePojo(String[].class);
27 | System.out.println(strings);
28 |
29 | RoleType roleType = factory.manufacturePojo(RoleType.class);
30 | System.out.println(roleType);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/docparser/BackendDocParserTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.docparser;
2 |
3 | import cloud.unionj.generator.backend.docparser.entity.Backend;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | import java.io.BufferedInputStream;
8 | import java.io.IOException;
9 |
10 | /**
11 | * @author created by wubin
12 | * @version v0.1
13 | * cloud.unionj.generator.backend.docparser
14 | * date 2020/12/22
15 | */
16 | public class BackendDocParserTest {
17 |
18 | @Test
19 | public void parse() throws IOException {
20 | try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("petstore3.json"))) {
21 | Backend backend = BackendDocParser.parse(is);
22 | Assert.assertNotNull(backend);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/ControllerPomGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import org.junit.Test;
4 |
5 | public class ControllerPomGeneratorTest {
6 |
7 | @Test
8 | public void test() {
9 | ControllerPomGenerator generator = new ControllerPomGenerator()
10 | .hasParent(true)
11 | .parentGroupId("com.github.myproject")
12 | .parentArtifactId("myproject")
13 | .parentVersion("1.0.0-SNAPSHOT")
14 | .groupIdAsParent()
15 | .artifactId("myproject-controller")
16 | .versionAsParent()
17 | .outputDirAsArtifactId()
18 | .protoGroupIdAsParent()
19 | .protoVersionAsParent()
20 | .protoArtifactId("myproject-proto")
21 | .serviceGroupIdAsParent()
22 | .serviceVersionAsParent()
23 | .serviceArtifactId("myproject-service");
24 |
25 | generator.generate();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/ProtoPomGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 | import org.junit.Test;
4 |
5 | /**
6 | * @author created by tqccc
7 | * @version v0.0.1
8 | * description: cloud.unionj.generator.backend.springboot
9 | * date:2021/1/17
10 | */
11 | public class ProtoPomGeneratorTest {
12 |
13 | @Test
14 | public void test() {
15 | ProtoPomGenerator generator = new ProtoPomGenerator()
16 | .hasParent(true)
17 | .parentGroupId("com.github.myproject")
18 | .parentArtifactId("myproject")
19 | .parentVersion("1.0.0-SNAPSHOT")
20 | .groupIdAsParent()
21 | .artifactId("myproject-proto")
22 | .versionAsParent()
23 | .outputDirAsArtifactId()
24 | .voGroupIdAsParent()
25 | .voVersionAsParent()
26 | .voArtifactId("myproject-vo");
27 |
28 | generator.generate();
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/VoPomGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot;
2 |
3 |
4 | import org.junit.Test;
5 |
6 | /**
7 | * @author created by tqccc
8 | * @version v0.0.1
9 | * description: cloud.unionj.generator.backend.springboot
10 | * date:2021/1/17
11 | */
12 | public class VoPomGeneratorTest {
13 |
14 | @Test
15 | public void test() {
16 | VoPomGenerator generator = new VoPomGenerator()
17 | .hasParent(true)
18 | .parentGroupId("com.github.myproject")
19 | .parentArtifactId("myproject")
20 | .parentVersion("1.0.0-SNAPSHOT")
21 | .groupIdAsParent()
22 | .artifactId("myproject-vo")
23 | .versionAsParent()
24 | .outputDirAsArtifactId();
25 |
26 | generator.generate();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/export/ExportComponents.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot.export;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 |
5 | import static cloud.unionj.generator.openapi3.dsl.Generic.generic;
6 | import static cloud.unionj.generator.openapi3.dsl.Schema.schema;
7 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.*;
8 |
9 | /**
10 | * @author: created by wubin
11 | * @version: v0.1
12 | * @description: cloud.unionj.gossip.gen
13 | * @date:2021/9/15
14 | */
15 | public class ExportComponents {
16 |
17 | public static Schema ResultDTO = schema(sb -> {
18 | sb.type("object");
19 | sb.title("ResultDTO");
20 | sb.properties("code", int32);
21 | sb.properties("msg", string);
22 | sb.properties("data", T);
23 | });
24 |
25 | public static Schema ResultDTOString = generic(gb -> gb.generic(ResultDTO, string("下载链接")));
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/export/ExportProto.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot.export;
2 |
3 | import cloud.unionj.generator.openapi3.PathConfig;
4 | import cloud.unionj.generator.openapi3.PathHelper;
5 | import cloud.unionj.generator.openapi3.dsl.IImporter;
6 | import cloud.unionj.generator.openapi3.expression.paths.ParameterBuilder;
7 | import cloud.unionj.generator.openapi3.model.paths.Parameter;
8 |
9 | import static cloud.unionj.generator.backend.springboot.export.ExportComponents.ResultDTOString;
10 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.int64Array;
11 |
12 | /**
13 | * @author: created by wubin
14 | * @version: v0.1
15 | * @description: cloud.unionj.gossip.gen
16 | * @date:2021/9/15
17 | */
18 | public class ExportProto implements IImporter {
19 | @Override
20 | public void doImport() {
21 | PathHelper.get("/export/case", PathConfig.builder()
22 | .summary("导出接口")
23 | .tags(new String[]{"导出"})
24 | .parameters(new Parameter[]{
25 | ParameterBuilder.builder().name("id").description("ID").in(Parameter.InEnum.QUERY).required(false).schema(int64Array).build(),
26 | })
27 | .respSchema(ResultDTOString)
28 | .build());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/user/UserComponents.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot.user;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 |
5 | import static cloud.unionj.generator.openapi3.dsl.Generic.generic;
6 | import static cloud.unionj.generator.openapi3.dsl.Schema.schema;
7 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.*;
8 |
9 | /**
10 | * @author: created by wubin
11 | * cloud.unionj.guide.gen.user
12 | * 2021/9/24
13 | */
14 | public class UserComponents {
15 |
16 | private static Schema ResultVO = schema(sb -> {
17 | sb.type("object");
18 | sb.title("ResultVO");
19 | sb.properties("code", int32);
20 | sb.properties("msg", string);
21 | sb.properties("data", T);
22 | });
23 |
24 | public static Schema UserRegisterFormVO = schema(sb -> {
25 | sb.type("object");
26 | sb.title("UserRegisterFormVO");
27 | sb.description("用户注册表单");
28 | sb.properties("username", string("用户名"));
29 | sb.properties("password", string("密码"));
30 | });
31 |
32 | public static Schema UserRegisterRespVO = schema(sb -> {
33 | sb.type("object");
34 | sb.title("UserRegisterRespVO");
35 | sb.description("用户注册结果");
36 | sb.properties("id", string("用户ID"));
37 | });
38 |
39 | public static Schema ResultVOUserRegisterRespVO = generic(gb -> {
40 | gb.generic(ResultVO, ref(UserRegisterRespVO.getTitle()));
41 | });
42 |
43 | public static Schema UserEditFormVO = schema(sb -> {
44 | sb.type("object");
45 | sb.title("UserEditFormVO");
46 | sb.description("用户信息编辑表单");
47 | sb.properties("name", string("真实姓名"));
48 | sb.properties("age", int32("年龄"));
49 | sb.properties("sex", enums("性别", new String[]{"BOY", "GIRL"}));
50 | sb.properties("avatar", file("用户头像"));
51 | });
52 |
53 | public static Schema ResultVOstring = generic(gb -> {
54 | gb.generic(ResultVO, string);
55 | });
56 |
57 | public static Schema UserDetailVO = schema(sb -> {
58 | sb.type("object");
59 | sb.title("UserDetailVO");
60 | sb.description("用户详情");
61 | sb.properties("id", string("用户ID"));
62 | sb.properties("name", string("真实姓名"));
63 | sb.properties("age", int32("年龄"));
64 | sb.properties("sex", enums("性别", new String[]{"BOY", "GIRL"}));
65 | sb.properties("avatar", string("用户头像下载地址"));
66 | });
67 |
68 | public static Schema ResultVOUserDetailVO = generic(gb -> {
69 | gb.generic(ResultVO, ref(UserDetailVO.getTitle()));
70 | });
71 |
72 | public static Schema UserPageReqVO = schema(sb -> {
73 | sb.type("object");
74 | sb.title("UserPageReqVO");
75 | sb.description("用户列表分页查询条件");
76 | sb.properties("size", int32("每页多少条数据"));
77 | sb.properties("current", int32("第几页"));
78 | sb.properties("sort", string("排序条件字符串:排序字段前使用'-'(降序)和'+'(升序)号表示排序规则,多个排序字段用','隔开",
79 | "+age,-create_at"));
80 | sb.properties("sex", string("筛选条件:用户性别"));
81 | });
82 |
83 | public static Schema PageResultVO = schema(sb -> {
84 | sb.type("object");
85 | sb.title("PageResultVO");
86 | sb.properties("items", ListT);
87 | sb.properties("total", int64("总数"));
88 | sb.properties("size", int32("每页多少条数据"));
89 | sb.properties("current", int32("当前页码"));
90 | sb.properties("pages", int32("总页数"));
91 | });
92 |
93 | public static Schema PageResultVOUserDetailVO = generic(gb -> {
94 | gb.generic(PageResultVO, ref(UserDetailVO.getTitle()));
95 | });
96 |
97 |
98 | public static Schema ResultVOPageResultVOUserDetailVO = generic(gb -> {
99 | gb.generic(ResultVO, ref(PageResultVOUserDetailVO.getTitle()));
100 | });
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/unionj-generator-backend/src/test/java/cloud/unionj/generator/backend/springboot/user/UserProto.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.backend.springboot.user;
2 |
3 | import cloud.unionj.generator.openapi3.PathConfig;
4 | import cloud.unionj.generator.openapi3.dsl.IImporter;
5 | import cloud.unionj.generator.openapi3.expression.paths.ParameterBuilder;
6 | import cloud.unionj.generator.openapi3.model.paths.Parameter;
7 |
8 | import static cloud.unionj.generator.backend.springboot.user.UserComponents.*;
9 | import static cloud.unionj.generator.openapi3.PathHelper.get;
10 | import static cloud.unionj.generator.openapi3.PathHelper.post;
11 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.string;
12 |
13 | /**
14 | * @author: created by wubin
15 | * cloud.unionj.guide.gen.user
16 | * 2021/9/24
17 | */
18 | public class UserProto implements IImporter {
19 |
20 | @Override
21 | public void doImport() {
22 | post("/api/user/register", PathConfig.builder()
23 | .summary("用户注册接口")
24 | .tags(new String[]{"用户管理模块", "User"})
25 | .reqSchema(UserRegisterFormVO)
26 | .reqSchemaType(PathConfig.SchemaType.FORMDATA)
27 | .respSchema(ResultVOUserRegisterRespVO)
28 | .build());
29 |
30 | post("/api/user/edit", PathConfig.builder()
31 | .summary("用户信息编辑接口")
32 | .tags(new String[]{"用户管理模块", "User"})
33 | .parameters(new Parameter[]{
34 | ParameterBuilder.builder().name("id").description("用户ID").in(Parameter.InEnum.QUERY).required(true).schema(string).build(),
35 | })
36 | .reqSchema(UserEditFormVO)
37 | .reqSchemaType(PathConfig.SchemaType.FORMDATA)
38 | .respSchema(ResultVOstring)
39 | .build());
40 |
41 | get("/api/user/detail", PathConfig.builder()
42 | .summary("用户信息查询接口")
43 | .tags(new String[]{"用户管理模块", "User"})
44 | .parameters(new Parameter[]{
45 | ParameterBuilder.builder().name("id").description("用户ID").in(Parameter.InEnum.QUERY).required(true).schema(string).build(),
46 | })
47 | .respSchema(ResultVOUserDetailVO)
48 | .build());
49 |
50 | get("/api/user/avatar", PathConfig.builder()
51 | .summary("用户头像下载接口")
52 | .tags(new String[]{"用户管理模块", "User"})
53 | .parameters(new Parameter[]{
54 | ParameterBuilder.builder().name("id").description("用户ID").in(Parameter.InEnum.QUERY).required(true).schema(string).build(),
55 | })
56 | .respSchema(ResultVOstring)
57 | .build());
58 |
59 | post("/api/user/page", PathConfig.builder()
60 | .summary("用户分页列表接口")
61 | .tags(new String[]{"用户管理模块", "User"})
62 | .reqSchema(UserPageReqVO)
63 | .respSchema(ResultVOPageResultVOUserDetailVO)
64 | .build());
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/unionj-generator-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 |
8 | io.github.unionj-cloud
9 | unionj-generator
10 | 1.6.8-SNAPSHOT
11 |
12 | unionj-generator-core
13 | unionj-generator-core
14 |
15 |
16 | 1.7
17 |
18 |
19 |
20 |
21 | org.projectlombok
22 | lombok
23 | 1.18.16
24 |
25 |
26 | com.fasterxml.jackson.core
27 | jackson-core
28 | 2.12.0
29 |
30 |
31 | com.fasterxml.jackson.core
32 | jackson-databind
33 | 2.12.0
34 |
35 |
36 | joda-time
37 | joda-time
38 | 2.10.8
39 |
40 |
41 | commons-io
42 | commons-io
43 | 2.8.0
44 |
45 |
46 | org.freemarker
47 | freemarker
48 | 2.3.30
49 |
50 |
51 | org.apache.commons
52 | commons-collections4
53 | 4.4
54 |
55 |
56 | com.github.javafaker
57 | javafaker
58 | 1.0.2
59 |
60 |
61 | org.json
62 | json
63 | 20201115
64 |
65 |
66 | org.reflections
67 | reflections
68 | 0.9.11
69 |
70 |
71 | org.apache.commons
72 | commons-text
73 | 1.9
74 |
75 |
76 | com.google.googlejavaformat
77 | google-java-format
78 | ${google-java-format.version}
79 |
80 |
81 | com.google.guava
82 | guava
83 | 31.1-jre
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/unionj-generator-core/src/main/java/cloud/unionj/generator/DefaultGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator;
2 |
3 | import com.google.googlejavaformat.java.Formatter;
4 | import freemarker.template.Configuration;
5 | import freemarker.template.Template;
6 | import freemarker.template.TemplateExceptionHandler;
7 | import freemarker.template.Version;
8 | import lombok.SneakyThrows;
9 | import org.apache.commons.lang3.ObjectUtils;
10 |
11 | import java.io.FileWriter;
12 | import java.io.Writer;
13 | import java.nio.file.Files;
14 | import java.nio.file.Path;
15 | import java.nio.file.Paths;
16 | import java.util.Locale;
17 |
18 | /**
19 | * @author created by wubin
20 | * @version v0.1
21 | * cloud.unionj.generator
22 | * date 2020/11/21
23 | */
24 | public abstract class DefaultGenerator implements Generator {
25 |
26 | protected boolean noDefaultComment;
27 | protected String parentArtifactId;
28 | protected String companyName;
29 | protected String baseName;
30 | protected String author;
31 | protected String createDate;
32 | protected String parentVersion;
33 | protected String year;
34 | protected String copyright;
35 |
36 | public DefaultGenerator(boolean noDefaultComment) {
37 | this.noDefaultComment = noDefaultComment;
38 | }
39 |
40 | public DefaultGenerator(boolean noDefaultComment, String parentArtifactId, String companyName, String baseName,
41 | String author, String createDate, String parentVersion, String year, String copyright) {
42 | this.noDefaultComment = noDefaultComment;
43 | this.parentArtifactId = ObjectUtils.defaultIfNull(parentArtifactId, "");
44 | this.companyName = ObjectUtils.defaultIfNull(companyName, "");
45 | this.baseName = ObjectUtils.defaultIfNull(baseName, "");
46 | this.author = ObjectUtils.defaultIfNull(author, "");
47 | this.createDate = ObjectUtils.defaultIfNull(createDate, "");
48 | this.parentVersion = ObjectUtils.defaultIfNull(parentVersion, "");
49 | this.year = ObjectUtils.defaultIfNull(year, "");
50 | this.copyright = ObjectUtils.defaultIfNull(copyright, "");
51 | }
52 |
53 | @SneakyThrows
54 | public void doGenerate() {
55 | // 1. Configure FreeMarker
56 | //
57 | // You should do this ONLY ONCE, when your application starts,
58 | // then reuse the same Configuration object elsewhere.
59 |
60 | Configuration cfg = new Configuration(new Version(2, 3, 20));
61 |
62 | // Where do we load the templates from:
63 | cfg.setClassForTemplateLoading(DefaultGenerator.class, "/templates");
64 |
65 | // Some other recommended settings:
66 | cfg.setDefaultEncoding("UTF-8");
67 | cfg.setLocale(Locale.SIMPLIFIED_CHINESE);
68 | cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
69 |
70 | // 2. Proccess template(s)
71 | //
72 | // You will do this for several times in typical applications.
73 |
74 | // 2.1. Prepare the template input:
75 |
76 |
77 | // 2.2. Get the template
78 | Template template = cfg.getTemplate(getTemplate());
79 |
80 | // 2.3. Generate the output
81 | Writer fileWriter = new FileWriter(getOutputFile());
82 | try {
83 | template.process(getInput(), fileWriter);
84 | } finally {
85 | fileWriter.close();
86 | }
87 | }
88 |
89 | @SneakyThrows
90 | @Override
91 | public String generate() {
92 | this.doGenerate();
93 | return getOutputFile();
94 | }
95 |
96 | @SneakyThrows
97 | @Override
98 | public String generateFormat() {
99 | this.doGenerate();
100 | Path path = Paths.get(getOutputFile());
101 | String sourceString = new String(Files.readAllBytes(path));
102 | String formattedSource = new Formatter().formatSource(sourceString);
103 | byte[] strToBytes = formattedSource.getBytes();
104 | Files.write(path, strToBytes);
105 | return getOutputFile();
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/unionj-generator-core/src/main/java/cloud/unionj/generator/Generator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator
9 | * date 2020/11/21
10 | */
11 | public interface Generator {
12 |
13 | Map getInput();
14 |
15 | String getTemplate();
16 |
17 | String getOutputFile();
18 |
19 | String generateFormat();
20 |
21 | String generate();
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-core/src/main/java/cloud/unionj/generator/GeneratorUtils.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator;
2 |
3 | import lombok.SneakyThrows;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.FileOutputStream;
9 | import java.io.IOException;
10 | import java.util.zip.ZipEntry;
11 | import java.util.zip.ZipInputStream;
12 | import java.util.zip.ZipOutputStream;
13 |
14 | /**
15 | * @author created by wubin
16 | * @version v0.1
17 | * cloud.unionj.generator
18 | * date 2020/11/26
19 | */
20 | public class GeneratorUtils {
21 |
22 | public static String getOutputDir(String outputDir) {
23 | if (StringUtils.isBlank(outputDir)) {
24 | outputDir = System.getProperty("user.dir");
25 | } else {
26 | File file = new File(outputDir);
27 | if (!file.isAbsolute()) {
28 | outputDir = System.getProperty("user.dir") + File.separator + outputDir;
29 | }
30 | file = new File(outputDir);
31 | if (!file.exists()) {
32 | file.mkdirs();
33 | }
34 | }
35 | return outputDir;
36 | }
37 |
38 | @SneakyThrows
39 | public static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) {
40 | if (fileToZip.isDirectory()) {
41 | if (fileName.endsWith("/")) {
42 | zipOut.putNextEntry(new ZipEntry(fileName));
43 | zipOut.closeEntry();
44 | } else {
45 | zipOut.putNextEntry(new ZipEntry(fileName + "/"));
46 | zipOut.closeEntry();
47 | }
48 | File[] children = fileToZip.listFiles();
49 | for (File childFile : children) {
50 | zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
51 | }
52 | return;
53 | }
54 | FileInputStream fis = new FileInputStream(fileToZip);
55 | ZipEntry zipEntry = new ZipEntry(fileName);
56 | zipOut.putNextEntry(zipEntry);
57 | byte[] bytes = new byte[1024];
58 | int length;
59 | while ((length = fis.read(bytes)) >= 0) {
60 | zipOut.write(bytes, 0, length);
61 | }
62 | fis.close();
63 | }
64 |
65 | @SneakyThrows
66 | public static String generateFolder(String sourceFile, String outputFile) {
67 | FileOutputStream fos = new FileOutputStream(outputFile);
68 | ZipOutputStream zipOut = new ZipOutputStream(fos);
69 | File fileToZip = new File(sourceFile);
70 |
71 | try {
72 | zipFile(fileToZip, fileToZip.getName(), zipOut);
73 | } catch (Exception exception) {
74 | throw exception;
75 | } finally {
76 | zipOut.close();
77 | fos.close();
78 | }
79 |
80 | return outputFile;
81 | }
82 |
83 | public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
84 | File destFile = new File(destinationDir, zipEntry.getName());
85 |
86 | String destDirPath = destinationDir.getCanonicalPath();
87 | String destFilePath = destFile.getCanonicalPath();
88 |
89 | if (!destFilePath.startsWith(destDirPath + File.separator)) {
90 | throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
91 | }
92 |
93 | return destFile;
94 | }
95 |
96 | @SneakyThrows
97 | public static void unzip(String fileZip, File destDir) {
98 | byte[] buffer = new byte[1024];
99 | ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
100 | ZipEntry zipEntry = zis.getNextEntry();
101 | while (zipEntry != null) {
102 | File newFile = newFile(destDir, zipEntry);
103 | if (zipEntry.isDirectory()) {
104 | if (!newFile.isDirectory() && !newFile.mkdirs()) {
105 | throw new IOException("Failed to create directory " + newFile);
106 | }
107 | } else {
108 | // fix for Windows-created archives
109 | File parent = newFile.getParentFile();
110 | if (!parent.isDirectory() && !parent.mkdirs()) {
111 | throw new IOException("Failed to create directory " + parent);
112 | }
113 |
114 | // write file content
115 | FileOutputStream fos = new FileOutputStream(newFile);
116 | int len;
117 | while ((len = zis.read(buffer)) > 0) {
118 | fos.write(buffer, 0, len);
119 | }
120 | fos.close();
121 | }
122 | zipEntry = zis.getNextEntry();
123 | }
124 | zis.closeEntry();
125 | zis.close();
126 |
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/unionj-generator-core/src/main/java/cloud/unionj/generator/Utils.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator;
2 |
3 | import com.google.common.base.CaseFormat;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import javax.lang.model.SourceVersion;
7 | import java.util.Arrays;
8 |
9 | /**
10 | * @ProductName: Hundsun unionj-generator
11 | * @Description: 描述
12 | * @Author: wubin48435 wubin48435@hundsun.com
13 | * @CreateDate: 2023/2/19 5:32 PM
14 | * @Version: 1.0
15 | * @Copyright © 2023 Hundsun Technologies Inc. All Rights Reserved
16 | */
17 | public class Utils {
18 | public static String cleanClassName(String name) {
19 | return Arrays.asList(StringUtils.trim(name)
20 | .split("[^a-zA-Z0-9_<>]"))
21 | .stream()
22 | .filter(StringUtils::isNotBlank)
23 | .map(key -> {
24 | CaseFormat originalFormat = CaseFormat.LOWER_CAMEL;
25 | if (Character.isUpperCase(key.charAt(0)) && key.contains("_")) {
26 | originalFormat = CaseFormat.UPPER_UNDERSCORE;
27 | } else if (Character.isUpperCase(key.charAt(0))) {
28 | originalFormat = CaseFormat.UPPER_CAMEL;
29 | } else if (key.contains("_")) {
30 | originalFormat = CaseFormat.LOWER_UNDERSCORE;
31 | } else if (key.contains("-")) {
32 | originalFormat = CaseFormat.LOWER_HYPHEN;
33 | }
34 | key = originalFormat.to(CaseFormat.UPPER_CAMEL, key);
35 | return key;
36 | })
37 | .reduce("", (x, y) -> x + y);
38 | }
39 |
40 | public static String cleanPropName(String name) {
41 | String propName = Arrays.asList(StringUtils.trim(name)
42 | .split("[^a-zA-Z0-9_<>]"))
43 | .stream()
44 | .filter(StringUtils::isNotBlank)
45 | .map(key -> {
46 | CaseFormat originalFormat = CaseFormat.LOWER_CAMEL;
47 | if (Character.isUpperCase(key.charAt(0)) && key.contains("_")) {
48 | originalFormat = CaseFormat.UPPER_UNDERSCORE;
49 | } else if (Character.isUpperCase(key.charAt(0))) {
50 | originalFormat = CaseFormat.UPPER_CAMEL;
51 | } else if (key.contains("_")) {
52 | originalFormat = CaseFormat.LOWER_UNDERSCORE;
53 | } else if (key.contains("-")) {
54 | originalFormat = CaseFormat.LOWER_HYPHEN;
55 | }
56 | key = originalFormat.to(CaseFormat.LOWER_CAMEL, key);
57 | return key;
58 | })
59 | .reduce("", (x, y) -> x + y);
60 | if (SourceVersion.isKeyword(propName)) {
61 | propName = StringUtils.capitalize(propName);
62 | }
63 | return propName;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/unionj-generator-maven-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 | .idea
25 | target
26 |
27 | unionj-generator-maven-plugin.iml
28 | unionj-generator-maven-plugin.ipr
29 | unionj-generator-maven-plugin.iws
30 |
--------------------------------------------------------------------------------
/unionj-generator-maven-plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | io.github.unionj-cloud
6 | unionj-generator
7 | 1.6.8-SNAPSHOT
8 |
9 | unionj-generator-maven-plugin
10 | maven-plugin
11 | unionj-generator-maven-plugin
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | io.github.unionj-cloud
20 | unionj-generator-backend
21 | ${project.version}
22 |
23 |
24 | io.github.unionj-cloud
25 | unionj-generator-mybatis
26 | ${project.version}
27 |
28 |
29 | org.apache.maven
30 | maven-plugin-api
31 | 3.6.3
32 |
33 |
34 | org.apache.maven.plugin-tools
35 | maven-plugin-annotations
36 | 3.6.0
37 | provided
38 |
39 |
40 | org.apache.maven
41 | maven-project
42 | 2.2.1
43 |
44 |
45 | org.apache.maven
46 | maven-artifact
47 | 2.2.1
48 |
49 |
50 | org.twdata.maven
51 | mojo-executor
52 | 2.3.0
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-plugin-plugin
61 | 3.6.1
62 |
63 | unionj-generator
64 | true
65 |
66 |
67 |
68 | mojo-descriptor
69 |
70 | descriptor
71 |
72 |
73 |
74 | help-goal
75 |
76 | helpmojo
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | org.apache.maven.plugins
88 | maven-plugin-plugin
89 | 3.6.1
90 |
91 |
92 |
93 | report
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/unionj-generator-maven-plugin/src/test/java/cloud/unionj/CodegenTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj;
2 |
3 | import cloud.unionj.generator.backend.docparser.BackendDocParser;
4 | import cloud.unionj.generator.backend.docparser.entity.Backend;
5 | import junit.framework.TestCase;
6 | import lombok.SneakyThrows;
7 |
8 | import java.io.BufferedInputStream;
9 | import java.net.URL;
10 | import java.net.URLConnection;
11 | import java.util.Base64;
12 |
13 | /**
14 | * @author: created by wubin
15 | * cloud.unionj
16 | * 2022/7/17
17 | */
18 | public class CodegenTest extends TestCase {
19 |
20 | @SneakyThrows
21 | public void testExecute() {
22 | URL url = new URL(
23 | "http://qylz:1234@api.gateway.c92358f369e164c2bbbdee14238b6e9a6.cn-beijing.alicontainer" + ".com/lottery-svc" +
24 | "/go-doudou/openapi.json");
25 | URLConnection uc = url.openConnection();
26 | String basicAuth = "Basic " + new String(Base64.getEncoder()
27 | .encode(url.getUserInfo()
28 | .getBytes()));
29 | uc.setRequestProperty("Authorization", basicAuth);
30 | try (BufferedInputStream in = new BufferedInputStream(uc.getInputStream())) {
31 | Backend backend = BackendDocParser.parse(in);
32 | System.out.println(backend);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 |
8 | io.github.unionj-cloud
9 | unionj-generator
10 | 1.6.8-SNAPSHOT
11 |
12 | unionj-generator-mybatis
13 | unionj-generator-mybatis
14 |
15 |
16 |
17 | io.github.unionj-cloud
18 | unionj-generator-core
19 | ${project.version}
20 |
21 |
22 | org.mybatis
23 | mybatis
24 | 3.5.13
25 |
26 |
27 | uk.co.jemos.podam
28 | podam
29 | 8.0.0.RELEASE
30 |
31 |
32 | org.slf4j
33 | slf4j-api
34 | 1.7.25
35 |
36 |
37 | org.slf4j
38 | slf4j-simple
39 | 1.7.25
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/java/cloud/unionj/generator/mybatis/Constants.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * cloud.unionj.generator.backend.springboot
7 | * date 2020/12/22
8 | */
9 | public class Constants {
10 |
11 | public static final String OUTPUT_DIR = "mybatis";
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/java/cloud/unionj/generator/mybatis/MapperInfo.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | @Data
8 | public class MapperInfo {
9 |
10 | private String mapperName;
11 | private String mapperPackage;
12 | private List methods;
13 | private List imports;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/java/cloud/unionj/generator/mybatis/MapperTestJavaGenerator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | import cloud.unionj.generator.DefaultGenerator;
4 | import cloud.unionj.generator.GeneratorUtils;
5 | import com.google.common.collect.Lists;
6 | import com.google.common.collect.Sets;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.apache.commons.lang3.StringUtils;
9 |
10 | import java.io.File;
11 | import java.nio.file.Paths;
12 | import java.util.*;
13 |
14 | import static cloud.unionj.generator.mybatis.Constants.OUTPUT_DIR;
15 |
16 | /**
17 | * @author created by wubin
18 | * @version v0.1
19 | * cloud.unionj.generator
20 | * date 2020/11/22
21 | */
22 | @Slf4j
23 | public class MapperTestJavaGenerator extends DefaultGenerator {
24 |
25 | private String outputDir;
26 | private String mainClassReferenceName;
27 | private String mainClassName;
28 | private MapperInfo mapperInfo;
29 |
30 | public MapperTestJavaGenerator(String outputDir, String mainClassReferenceName, MapperInfo mapperInfo,
31 | boolean noDefaultComment) {
32 | super(noDefaultComment);
33 | List parts = new ArrayList<>();
34 | parts.add("src");
35 | parts.add("test");
36 | parts.add("java");
37 | parts.addAll(Lists.newArrayList(StringUtils.split(mapperInfo.getMapperPackage(), ".")));
38 | this.outputDir = Paths.get(outputDir, parts.toArray(new String[]{})).toString();
39 | this.mainClassReferenceName = mainClassReferenceName;
40 | this.mainClassName = StringUtils.substringAfterLast(mainClassReferenceName, ".");
41 | this.mapperInfo = mapperInfo;
42 | }
43 |
44 | @Override
45 | public Map getInput() {
46 | Map input = new HashMap<>();
47 | input.put("packageName", this.mapperInfo.getMapperPackage());
48 | input.put("mainClassName", this.mainClassName);
49 | Set imports = Sets.newHashSet(this.mainClassReferenceName);
50 | imports.addAll(this.mapperInfo.getImports());
51 | input.put("imports", imports);
52 | input.put("mapperName", this.mapperInfo.getMapperName());
53 | input.put("methods", this.mapperInfo.getMethods());
54 | input.put("noDefaultComment", this.noDefaultComment);
55 | input.put("parentArtifactId", this.parentArtifactId);
56 | input.put("companyName", this.companyName);
57 | input.put("baseName", this.baseName);
58 | input.put("author", this.author);
59 | input.put("createDate", this.createDate);
60 | input.put("parentVersion", this.parentVersion);
61 | input.put("year", this.year);
62 | input.put("copyright", this.copyright);
63 | return input;
64 | }
65 |
66 | @Override
67 | public String getTemplate() {
68 | return OUTPUT_DIR + File.separator + "mappertest.java.ftl";
69 | }
70 |
71 | @Override
72 | public String getOutputFile() {
73 | return GeneratorUtils.getOutputDir(this.outputDir) + File.separator + this.mapperInfo.getMapperName() + "Test.java";
74 | }
75 |
76 | @Override
77 | public String generate() {
78 | File file = new File(getOutputFile());
79 | if (file.exists()) {
80 | log.info(file + " already exists, skip generating");
81 | return getOutputFile();
82 | }
83 | try {
84 | return super.generateFormat();
85 | } catch (Exception ex) {
86 | log.error(ex.getMessage());
87 | log.error(this.mapperInfo.getMapperPackage() + "." + this.mapperInfo.getMapperName());
88 | }
89 | return getOutputFile();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/java/cloud/unionj/generator/mybatis/MethodInfo.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | @Data
8 | public class MethodInfo {
9 | private String methodName;
10 | private List parameters;
11 | }
12 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/java/cloud/unionj/generator/mybatis/ParameterInfo.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | @Data
8 | public class ParameterInfo {
9 | private List types;
10 | private String fullType;
11 | }
12 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/main/resources/templates/mybatis/mappertest.java.ftl:
--------------------------------------------------------------------------------
1 | <#if !noDefaultComment>
2 | /**
3 | * Code generated by unionj-generator-mybatis. DO NOT EDIT.
4 | * https://github.com/unionj-cloud/unionj-generator
5 | */
6 |
7 | #if>package ${packageName};
8 |
9 | import cn.hutool.core.util.StrUtil;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.transaction.annotation.Transactional;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.test.context.junit4.SpringRunner;
16 | import uk.co.jemos.podam.api.PodamFactory;
17 | import uk.co.jemos.podam.api.PodamFactoryImpl;
18 | import lombok.extern.slf4j.Slf4j;
19 | <#if imports??>
20 | <#list imports as import>
21 | import ${import};
22 | #list>
23 | #if>
24 |
25 | @Slf4j
26 | @RunWith(SpringRunner.class)
27 | @SpringBootTest(classes = {${mainClassName}.class})
28 | @Transactional
29 | public class ${mapperName}Test {
30 |
31 | @Autowired
32 | private ${mapperName} mapper;
33 |
34 | <#list methods as method>
35 | <#compress>@Test
36 | public void ${method.methodName}() {
37 | <#if method.parameters??>
38 | PodamFactory factory = new PodamFactoryImpl();
39 | <#assign params=[]>
40 | <#list method.parameters as parameter>
41 | ${parameter.fullType} arg${parameter?index} = factory.manufacturePojo(<#list parameter.types as atype><#if !atype?is_first>, #if>${atype}.class#list>);
42 | <#assign params = params + [ "arg${parameter?index}" ] />
43 | log.debug(StrUtil.format("{}", arg${parameter?index}));
44 | #list>
45 | mapper.${method.methodName}(<#list params as param><#if !param?is_first>, #if>${param}#list>);
46 | <#else>
47 | mapper.${method.methodName}();
48 | #if>
49 | }#compress>
50 | <#sep>
51 |
52 | #sep>
53 | #list>
54 | }
55 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/test/java/cloud/unionj/generator/mybatis/Main.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | public class Main {
4 | }
5 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/test/java/cloud/unionj/generator/mybatis/MainTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis;
2 |
3 | import java.util.List;
4 |
5 | public class MainTest {
6 | public static void main(String[] args) {
7 | MapperLoader mapperLoader = new MapperLoader();
8 | List mapperInfos = mapperLoader.load("cloud.unionj.generator.mybatis.dao", false);
9 | System.out.println(mapperInfos);
10 |
11 | for (int i = 0; i < mapperInfos.size(); i++) {
12 | MapperInfo mapperInfo = mapperInfos.get(i);
13 | MapperTestJavaGenerator mapperTestJavaGenerator = new MapperTestJavaGenerator("/Users/wubin1989/workspace/cloud/unionj-generator/unionj-generator-mybatis", "cloud.unionj.generator.mybatis.Main", mapperInfo, false);
14 | String generate = mapperTestJavaGenerator.generate();
15 | System.out.println(generate);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/test/java/cloud/unionj/generator/mybatis/dao/ProductMapper.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis.dao;
2 |
3 | import cloud.unionj.generator.mybatis.entity.Product;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | public interface ProductMapper {
11 |
12 | // void insert(Product product);
13 | //
14 | // List selectByIds(List ids, Boolean isDeleted);
15 | //
16 | // int deletequalityByPrimaryKey(int id);
17 |
18 | List getRoleListByGroup(@Param("roleGroup") Product.RoleType roleGroup);
19 |
20 | // Set getTaskByVersion(@Param("versions") String[] versions, @Param("versionsIds") Set versionsIds, @Param("projectId") Long projectId);
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-mybatis/src/test/java/cloud/unionj/generator/mybatis/entity/Product.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.mybatis.entity;
2 |
3 | public class Product {
4 |
5 | public enum RoleType {
6 | PRODUCT_MEMBER;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 |
8 | io.github.unionj-cloud
9 | unionj-generator
10 | 1.6.8-SNAPSHOT
11 |
12 | unionj-generator-openapi
13 | unionj-generator-openapi
14 |
15 |
16 |
17 | io.github.unionj-cloud
18 | unionj-generator-core
19 | ${project.version}
20 |
21 |
22 | com.google.code.gson
23 | gson
24 | 2.8.6
25 |
26 |
27 | io.swagger.parser.v3
28 | swagger-parser
29 | 2.1.12
30 |
31 |
32 | commons-beanutils
33 | commons-beanutils
34 | 1.9.4
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/ExceptionHelper.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * cloud.unionj.generator.openapi3
7 | * date 2020/12/29
8 | */
9 | public class ExceptionHelper {
10 |
11 | public static final Exception NotGenericSchemaException = new Exception("not generic schema");
12 | }
13 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/NullAwareBeanUtilsBean.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3;
2 |
3 | import org.apache.commons.beanutils.BeanUtilsBean;
4 |
5 | import java.lang.reflect.InvocationTargetException;
6 |
7 | /**
8 | * @ProductName: Hundsun unionj-generator
9 | * @Description: 描述
10 | * @Author: wubin48435 wubin48435@hundsun.com
11 | * @CreateDate: 2023/3/2 10:55 PM
12 | * @Version: 1.0
13 | * @Copyright © 2023 Hundsun Technologies Inc. All Rights Reserved
14 | */
15 | public class NullAwareBeanUtilsBean extends BeanUtilsBean {
16 |
17 | @Override
18 | public void copyProperty(Object dest, String name, Object value)
19 | throws IllegalAccessException, InvocationTargetException {
20 | if (value == null) return;
21 | super.copyProperty(dest, name, value);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/PathConfig.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 | import cloud.unionj.generator.openapi3.model.paths.Parameter;
5 | import com.fasterxml.jackson.annotation.JsonCreator;
6 | import com.fasterxml.jackson.annotation.JsonValue;
7 | import lombok.Builder;
8 | import lombok.Data;
9 |
10 | /**
11 | * @author created by wubin
12 | * @version v0.0.1
13 | * description: cloud.unionj.generator.openapi3
14 | * date:2021/5/11
15 | */
16 | @Builder
17 | @Data
18 | public class PathConfig {
19 | private String summary;
20 | private String[] tags;
21 | private Parameter[] parameters;
22 | private Schema reqSchema;
23 | private Schema respSchema;
24 | private SchemaType reqSchemaType;
25 | private SchemaType respSchemaType;
26 |
27 | public enum SchemaType {
28 | JSON("json"),
29 | FORMDATA("formdata"),
30 | STREAM("stream");
31 |
32 | private String value;
33 |
34 | SchemaType(String value) {
35 | this.value = value;
36 | }
37 |
38 | @Override
39 | @JsonValue
40 | public String toString() {
41 | return String.valueOf(value);
42 | }
43 |
44 | @JsonCreator
45 | public static SchemaType fromValue(String text) {
46 | for (SchemaType b : SchemaType.values()) {
47 | if (String.valueOf(b.value).equals(text)) {
48 | return b;
49 | }
50 | }
51 | return null;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/Discriminator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.expression.DiscriminatorBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/16
12 | */
13 | public class Discriminator {
14 |
15 | public static cloud.unionj.generator.openapi3.model.Discriminator discriminator(Consumer consumer) {
16 | DiscriminatorBuilder discriminatorBuilder = new DiscriminatorBuilder();
17 | consumer.accept(discriminatorBuilder);
18 | cloud.unionj.generator.openapi3.model.Discriminator discriminator = discriminatorBuilder.build();
19 | return discriminator;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/Generic.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.expression.GenericBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/16
12 | */
13 | public class Generic extends Openapi3 {
14 | public static cloud.unionj.generator.openapi3.model.Generic generic(Consumer consumer) {
15 | GenericBuilder genericBuilder = new GenericBuilder();
16 | consumer.accept(genericBuilder);
17 | cloud.unionj.generator.openapi3.model.Generic generic = genericBuilder.build();
18 | openapi3Builder.components(generic.getxTitle(), generic);
19 | return generic;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/IGeneric.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.model.Generic;
4 | import cloud.unionj.generator.openapi3.model.Schema;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * date 2020/12/28
10 | */
11 | public interface IGeneric {
12 | Generic generic(Schema schema);
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/IImporter.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * date 2020/12/28
7 | */
8 | public interface IImporter {
9 | void doImport();
10 | }
11 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/Openapi3.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.expression.Openapi3Builder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/15
12 | */
13 | public class Openapi3 {
14 |
15 | protected static Openapi3Builder openapi3Builder;
16 |
17 | public static cloud.unionj.generator.openapi3.model.Openapi3 openapi3(Consumer consumer) {
18 | if (openapi3Builder == null) {
19 | openapi3Builder = new Openapi3Builder();
20 | }
21 | consumer.accept(openapi3Builder);
22 | return openapi3Builder.build();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/PathHelper.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import lombok.SneakyThrows;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.dsl
9 | * date 2020/12/26
10 | */
11 | public class PathHelper {
12 |
13 | @SneakyThrows
14 | public static void doImport(Class clazz) {
15 | clazz.newInstance().doImport();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/Reference.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.expression.ReferenceBuilder;
4 | import cloud.unionj.generator.openapi3.model.Schema;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.dsl
12 | * date 2020/12/16
13 | */
14 | public class Reference {
15 |
16 | public static Schema reference(Consumer consumer) {
17 | ReferenceBuilder referenceBuilder = new ReferenceBuilder();
18 | consumer.accept(referenceBuilder);
19 | Schema schema = referenceBuilder.build();
20 | return schema;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/Schema.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.expression.Openapi3Builder;
4 | import cloud.unionj.generator.openapi3.expression.SchemaBuilder;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | import java.util.function.Consumer;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.openapi3.dsl
13 | * date 2020/12/16
14 | */
15 | public class Schema extends Openapi3 {
16 | public static cloud.unionj.generator.openapi3.model.Schema schema(Consumer consumer) {
17 | if (openapi3Builder == null) {
18 | openapi3Builder = new Openapi3Builder();
19 | }
20 | SchemaBuilder schemaBuilder = new SchemaBuilder(openapi3Builder);
21 | consumer.accept(schemaBuilder);
22 | cloud.unionj.generator.openapi3.model.Schema schema = schemaBuilder.build();
23 | if (StringUtils.isNotBlank(schema.getxTitle())) {
24 | openapi3Builder.components(schema.getxTitle(), schema);
25 | }
26 | return schema;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/info/Contact.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.info;
2 |
3 | import cloud.unionj.generator.openapi3.expression.info.ContactBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Contact extends Info {
14 |
15 | public static void contact(Consumer consumer) {
16 | ContactBuilder contactBuilder = new ContactBuilder();
17 | consumer.accept(contactBuilder);
18 | cloud.unionj.generator.openapi3.model.info.Contact contact = contactBuilder.build();
19 | infoBuilder.contact(contact);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/info/Info.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.info;
2 |
3 | import cloud.unionj.generator.openapi3.expression.info.InfoBuilder;
4 | import cloud.unionj.generator.openapi3.dsl.Openapi3;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.dsl
12 | * date 2020/12/14
13 | */
14 | public class Info extends Openapi3 {
15 |
16 | protected static InfoBuilder infoBuilder;
17 |
18 | public static void info(Consumer consumer) {
19 | infoBuilder = new InfoBuilder();
20 | consumer.accept(infoBuilder);
21 | cloud.unionj.generator.openapi3.model.info.Info info = infoBuilder.build();
22 | openapi3Builder.info(info);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/info/License.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.info;
2 |
3 | import cloud.unionj.generator.openapi3.expression.info.LicenseBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class License extends Info {
14 |
15 | public static void license(Consumer consumer) {
16 | LicenseBuilder licenseBuilder = new LicenseBuilder();
17 | consumer.accept(licenseBuilder);
18 | cloud.unionj.generator.openapi3.model.info.License license = licenseBuilder.build();
19 | infoBuilder.license(license);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Content.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.ContentBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/16
12 | */
13 | public class Content {
14 |
15 | public static cloud.unionj.generator.openapi3.model.paths.Content content(Consumer consumer) {
16 | ContentBuilder contentBuilder = new ContentBuilder();
17 | consumer.accept(contentBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Content content = contentBuilder.build();
19 | return content;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Delete.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.OperationBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Delete extends Operation {
14 |
15 | public static void delete(Consumer consumer) {
16 | operationBuilder = new OperationBuilder();
17 | consumer.accept(operationBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Operation delete = operationBuilder.build();
19 | pathBuilder.delete(delete);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Get.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.OperationBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Get extends Operation {
14 |
15 | public static void get(Consumer consumer) {
16 | operationBuilder = new OperationBuilder();
17 | consumer.accept(operationBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Operation get = operationBuilder.build();
19 | pathBuilder.get(get);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/MediaType.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.MediaTypeBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl.paths
11 | * date 2020/12/19
12 | */
13 | public class MediaType {
14 |
15 | public static cloud.unionj.generator.openapi3.model.paths.MediaType mediaType(Consumer consumer) {
16 | MediaTypeBuilder mediaTypeBuilder = new MediaTypeBuilder();
17 | consumer.accept(mediaTypeBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.MediaType mediaType = mediaTypeBuilder.build();
19 | return mediaType;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Operation.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.OperationBuilder;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.dsl
9 | * date 2020/12/14
10 | */
11 | public class Operation extends Path {
12 |
13 | protected static OperationBuilder operationBuilder;
14 | }
15 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Parameter.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.ParameterBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Parameter extends Operation {
14 |
15 | public static void parameter(Consumer consumer) {
16 | ParameterBuilder parameterBuilder = ParameterBuilder.builder();
17 | consumer.accept(parameterBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Parameter parameter = parameterBuilder.build();
19 | operationBuilder.parameters(parameter);
20 | }
21 |
22 | public static void parameter(cloud.unionj.generator.openapi3.model.paths.Parameter parameter) {
23 | operationBuilder.parameters(parameter);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Path.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.dsl.Openapi3;
4 | import cloud.unionj.generator.openapi3.expression.paths.PathBuilder;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.dsl
12 | * date 2020/12/14
13 | */
14 | public class Path extends Openapi3 {
15 |
16 | protected static PathBuilder pathBuilder;
17 |
18 | public static void path(String endpoint, Consumer consumer) {
19 | pathBuilder = new PathBuilder();
20 | consumer.accept(pathBuilder);
21 | pathBuilder.endpoint(endpoint);
22 | cloud.unionj.generator.openapi3.model.paths.Path path = pathBuilder.build();
23 | openapi3Builder.paths(path);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Post.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.OperationBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Post extends Operation {
14 |
15 | public static void post(Consumer consumer) {
16 | operationBuilder = new OperationBuilder();
17 | consumer.accept(operationBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Operation post = operationBuilder.build();
19 | pathBuilder.post(post);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Put.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.OperationBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class Put extends Operation {
14 |
15 | public static void put(Consumer consumer) {
16 | operationBuilder = new OperationBuilder();
17 | consumer.accept(operationBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Operation put = operationBuilder.build();
19 | pathBuilder.put(put);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/RequestBody.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.RequestBodyBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl
11 | * date 2020/12/14
12 | */
13 | public class RequestBody extends Operation {
14 |
15 | public static void requestBody(Consumer consumer) {
16 | RequestBodyBuilder requestBodyBuilder = new RequestBodyBuilder();
17 | consumer.accept(requestBodyBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.RequestBody requestBody = requestBodyBuilder.build();
19 | operationBuilder.requestBody(requestBody);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Response.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.ResponseBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl.paths
11 | * date 2020/12/19
12 | */
13 | public class Response {
14 |
15 | public static cloud.unionj.generator.openapi3.model.paths.Response response(Consumer consumer) {
16 | ResponseBuilder responseBuilder = new ResponseBuilder();
17 | consumer.accept(responseBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Response response = responseBuilder.build();
19 | return response;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/paths/Responses.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.expression.paths.ResponsesBuilder;
4 |
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.dsl.paths
11 | * date 2020/12/19
12 | */
13 | public class Responses extends Operation {
14 |
15 | public static void responses(Consumer consumer) {
16 | ResponsesBuilder responsesBuilder = new ResponsesBuilder();
17 | consumer.accept(responsesBuilder);
18 | cloud.unionj.generator.openapi3.model.paths.Responses responses = responsesBuilder.build();
19 | operationBuilder.responses(responses);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/servers/Server.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.servers;
2 |
3 | import cloud.unionj.generator.openapi3.dsl.Openapi3;
4 | import cloud.unionj.generator.openapi3.expression.servers.ServerBuilder;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.dsl
12 | * date 2020/12/14
13 | */
14 | public class Server extends Openapi3 {
15 |
16 | public static void server(Consumer consumer) {
17 | ServerBuilder serverBuilder = new ServerBuilder();
18 | consumer.accept(serverBuilder);
19 | cloud.unionj.generator.openapi3.model.servers.Server server = serverBuilder.build();
20 | openapi3Builder.servers(server);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/dsl/tags/Tag.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.tags;
2 |
3 | import cloud.unionj.generator.openapi3.dsl.Openapi3;
4 | import cloud.unionj.generator.openapi3.expression.tags.TagBuilder;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.dsl
12 | * date 2020/12/14
13 | */
14 | public class Tag extends Openapi3 {
15 |
16 | public static void tag(Consumer consumer) {
17 | TagBuilder tagBuilder = new TagBuilder();
18 | consumer.accept(tagBuilder);
19 | cloud.unionj.generator.openapi3.model.tags.Tag tag = tagBuilder.build();
20 | openapi3Builder.tags(tag);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/DiscriminatorBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression;
2 |
3 | import cloud.unionj.generator.openapi3.model.Discriminator;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.expression
9 | * date 2020/12/16
10 | */
11 | public class DiscriminatorBuilder {
12 |
13 | private Discriminator discriminator;
14 |
15 | public void propertyName(String propertyName) {
16 | this.discriminator.setPropertyName(propertyName);
17 | }
18 |
19 | public void mapping(String key, String value) {
20 | this.discriminator.setMapping(key, value);
21 | }
22 |
23 | public Discriminator build() {
24 | return this.discriminator;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/GenericBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression;
2 |
3 | import cloud.unionj.generator.openapi3.dsl.IGeneric;
4 | import cloud.unionj.generator.openapi3.model.Generic;
5 | import cloud.unionj.generator.openapi3.model.Schema;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.expression
11 | * date 2020/12/16
12 | */
13 | public class GenericBuilder {
14 |
15 | protected Generic generic;
16 |
17 | public GenericBuilder() {
18 | }
19 |
20 | public void generic(IGeneric iGeneric, Schema element) {
21 | this.generic = iGeneric.generic(element);
22 | }
23 |
24 | public Generic build() {
25 | return this.generic;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/ISchemaFinder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * date 2020/12/28
9 | */
10 | public interface ISchemaFinder {
11 | Schema find(String key);
12 | }
13 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/Openapi3Builder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression;
2 |
3 |
4 | import cloud.unionj.generator.openapi3.model.ExternalDocs;
5 | import cloud.unionj.generator.openapi3.model.Openapi3;
6 | import cloud.unionj.generator.openapi3.model.Schema;
7 | import cloud.unionj.generator.openapi3.model.info.Info;
8 | import cloud.unionj.generator.openapi3.model.paths.Path;
9 | import cloud.unionj.generator.openapi3.model.servers.Server;
10 | import cloud.unionj.generator.openapi3.model.tags.Tag;
11 |
12 | /**
13 | * @author created by wubin
14 | * @version v0.1
15 | * cloud.unionj.generator.openapi3.expression
16 | * date 2020/12/14
17 | */
18 | public class Openapi3Builder implements ISchemaFinder {
19 |
20 | private Openapi3 openapi3;
21 |
22 | public Openapi3Builder() {
23 | this.openapi3 = new Openapi3();
24 | }
25 |
26 | public void servers(Server server) {
27 | this.openapi3.servers(server);
28 | }
29 |
30 | public void tags(Tag tag) {
31 | this.openapi3.tags(tag);
32 | }
33 |
34 | public void paths(Path path) {
35 | this.openapi3.paths(path);
36 | }
37 |
38 | public void info(Info info) {
39 | this.openapi3.setInfo(info);
40 | }
41 |
42 | public void externalDocs(ExternalDocs externalDocs) {
43 | this.openapi3.setExternalDocs(externalDocs);
44 | }
45 |
46 | public void components(String key, Schema schema) {
47 | this.openapi3.getComponents().schemas(key, schema);
48 | }
49 |
50 | public Openapi3 build() {
51 | return this.openapi3;
52 | }
53 |
54 | @Override
55 | public Schema find(String key) {
56 | return this.openapi3.getComponents().getSchemas().get(key);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/ReferenceBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.expression
9 | * date 2020/12/16
10 | */
11 | public class ReferenceBuilder {
12 |
13 | private Schema reference;
14 |
15 | public ReferenceBuilder() {
16 | this.reference = new Schema(null);
17 | }
18 |
19 | public void ref(String ref) {
20 | this.reference.setRef("#/components/schemas/" + ref);
21 | }
22 |
23 | public Schema build() {
24 | return this.reference;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/info/ContactBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.info;
2 |
3 | import cloud.unionj.generator.openapi3.model.info.Contact;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.expression
9 | * date 2020/12/14
10 | */
11 | public class ContactBuilder {
12 |
13 | private Contact contact;
14 |
15 | public ContactBuilder() {
16 | this.contact = new Contact();
17 | }
18 |
19 | public void email(String email) {
20 | this.contact.setEmail(email);
21 | }
22 |
23 | public Contact build() {
24 | return this.contact;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/info/InfoBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.info;
2 |
3 |
4 | import cloud.unionj.generator.openapi3.model.info.Contact;
5 | import cloud.unionj.generator.openapi3.model.info.Info;
6 | import cloud.unionj.generator.openapi3.model.info.License;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.expression
12 | * date 2020/12/14
13 | */
14 | public class InfoBuilder {
15 |
16 | private Info info;
17 |
18 | public InfoBuilder() {
19 | this.info = new Info();
20 | }
21 |
22 | public void title(String title) {
23 | this.info.setTitle(title);
24 | }
25 |
26 | public void description(String description) {
27 | this.info.setDescription(description);
28 | }
29 |
30 | public void termsOfService(String termsOfService) {
31 | this.info.setTermsOfService(termsOfService);
32 | }
33 |
34 | public void version(String version) {
35 | this.info.setVersion(version);
36 | }
37 |
38 | public void contact(Contact contact) {
39 | this.info.setContact(contact);
40 | }
41 |
42 | public void license(License license) {
43 | this.info.setLicense(license);
44 | }
45 |
46 | public Info build() {
47 | return this.info;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/info/LicenseBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.info;
2 |
3 | import cloud.unionj.generator.openapi3.model.info.License;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.expression
9 | * date 2020/12/14
10 | */
11 | public class LicenseBuilder {
12 |
13 | private License license;
14 |
15 | public LicenseBuilder() {
16 | this.license = new License();
17 | }
18 |
19 | public void name(String name) {
20 | this.license.setName(name);
21 | }
22 |
23 | public void url(String url) {
24 | this.license.setUrl(url);
25 | }
26 |
27 | public License build() {
28 | return this.license;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/ContentBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.Content;
4 | import cloud.unionj.generator.openapi3.model.paths.MediaType;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression
10 | * date 2020/12/16
11 | */
12 | public class ContentBuilder {
13 |
14 | private Content content;
15 |
16 | public ContentBuilder() {
17 | this.content = new Content();
18 | }
19 |
20 | public void textPlain(MediaType textPlain) {
21 | this.content.setTextPlain(textPlain);
22 | }
23 |
24 | public void applicationJson(MediaType applicationJson) {
25 | this.content.setApplicationJson(applicationJson);
26 | }
27 |
28 | public void applicationXWwwFormUrlencoded(MediaType applicationXWwwFormUrlencoded) {
29 | this.content.setApplicationXWwwFormUrlencoded(applicationXWwwFormUrlencoded);
30 | }
31 |
32 | public void applicationOctetStream(MediaType applicationOctetStream) {
33 | this.content.setApplicationOctetStream(applicationOctetStream);
34 | }
35 |
36 | public void multipartFormData(MediaType multipartFormData) {
37 | this.content.setMultipartFormData(multipartFormData);
38 | }
39 |
40 | public Content build() {
41 | return this.content;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/MediaTypeBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 | import cloud.unionj.generator.openapi3.model.paths.MediaType;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression.paths
10 | * date 2020/12/19
11 | */
12 | public class MediaTypeBuilder {
13 |
14 | private MediaType mediaType;
15 |
16 | public MediaTypeBuilder() {
17 | this.mediaType = new MediaType();
18 | }
19 |
20 | public void schema(Schema schema) {
21 | this.mediaType.setSchema(schema);
22 | }
23 |
24 | public void example(Object example) {
25 | this.mediaType.setExample(example);
26 | }
27 |
28 | public MediaType build() {
29 | return this.mediaType;
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/OperationBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.Operation;
4 | import cloud.unionj.generator.openapi3.model.paths.Parameter;
5 | import cloud.unionj.generator.openapi3.model.paths.RequestBody;
6 | import cloud.unionj.generator.openapi3.model.paths.Responses;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.expression
12 | * date 2020/12/14
13 | */
14 | public class OperationBuilder {
15 |
16 | private Operation operation;
17 |
18 | public OperationBuilder() {
19 | this.operation = new Operation();
20 | }
21 |
22 | public void summary(String summary) {
23 | this.operation.setSummary(summary);
24 | }
25 |
26 | public void description(String description) {
27 | this.operation.setDescription(description);
28 | }
29 |
30 | public void operationId(String operationId) {
31 | this.operation.setOperationId(operationId);
32 | }
33 |
34 | public void deprecated(boolean deprecated) {
35 | this.operation.setDeprecated(deprecated);
36 | }
37 |
38 | public void tags(String tag) {
39 | this.operation.tags(tag);
40 | }
41 |
42 | public void parameters(Parameter parameter) {
43 | this.operation.parameters(parameter);
44 | }
45 |
46 | public void requestBody(RequestBody requestBody) {
47 | this.operation.setRequestBody(requestBody);
48 | }
49 |
50 | // TODO
51 | public void responses(Responses responses) {
52 | this.operation.setResponses(responses);
53 | }
54 |
55 | public Operation build() {
56 | return this.operation;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/ParameterBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 | import cloud.unionj.generator.openapi3.model.paths.Parameter;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression
10 | * date 2020/12/14
11 | */
12 | public class ParameterBuilder {
13 |
14 | private Parameter parameter;
15 |
16 | private ParameterBuilder() {
17 | this.parameter = new Parameter();
18 | }
19 |
20 | public static ParameterBuilder builder() {
21 | return new ParameterBuilder();
22 | }
23 |
24 | public ParameterBuilder name(String name) {
25 | this.parameter.setName(name);
26 | return this;
27 | }
28 |
29 | public ParameterBuilder in(String in) {
30 | this.parameter.setIn(Parameter.InEnum.fromValue(in));
31 | return this;
32 | }
33 |
34 | public ParameterBuilder in(Parameter.InEnum in) {
35 | this.parameter.setIn(in);
36 | return this;
37 | }
38 |
39 | public ParameterBuilder description(String description) {
40 | this.parameter.setDescription(description);
41 | return this;
42 | }
43 |
44 | public ParameterBuilder required(boolean required) {
45 | this.parameter.setRequired(required);
46 | return this;
47 | }
48 |
49 | public ParameterBuilder deprecated(boolean deprecated) {
50 | this.parameter.setDeprecated(deprecated);
51 | return this;
52 | }
53 |
54 | public ParameterBuilder example(Object example) {
55 | this.parameter.setExample(example);
56 | return this;
57 | }
58 |
59 | public ParameterBuilder schema(Schema schema) {
60 | this.parameter.setSchema(schema);
61 | return this;
62 | }
63 |
64 | public Parameter build() {
65 | return this.parameter;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/PathBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 |
4 | import cloud.unionj.generator.openapi3.model.paths.Operation;
5 | import cloud.unionj.generator.openapi3.model.paths.Path;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.expression
11 | * date 2020/12/14
12 | */
13 | public class PathBuilder {
14 |
15 | private Path path;
16 |
17 | public PathBuilder() {
18 | this.path = new Path();
19 | }
20 |
21 | public void endpoint(String endpoint) {
22 | this.path.setEndpoint(endpoint);
23 | }
24 |
25 | public void get(Operation get) {
26 | this.path.setGet(get);
27 | }
28 |
29 | public void post(Operation post) {
30 | this.path.setPost(post);
31 | }
32 |
33 | public void put(Operation put) {
34 | this.path.setPut(put);
35 | }
36 |
37 | public void delete(Operation delete) {
38 | this.path.setDelete(delete);
39 | }
40 |
41 | public Path build() {
42 | return this.path;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/RequestBodyBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.Content;
4 | import cloud.unionj.generator.openapi3.model.paths.RequestBody;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression
10 | * date 2020/12/14
11 | */
12 | public class RequestBodyBuilder {
13 |
14 | private RequestBody requestBody;
15 |
16 | public RequestBodyBuilder() {
17 | this.requestBody = new RequestBody();
18 | }
19 |
20 | public void content(Content content) {
21 | this.requestBody.setContent(content);
22 | }
23 |
24 | public void description(String description) {
25 | this.requestBody.setDescription(description);
26 | }
27 |
28 | public void required(boolean required) {
29 | this.requestBody.setRequired(required);
30 | }
31 |
32 |
33 | public RequestBody build() {
34 | return this.requestBody;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/ResponseBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.Content;
4 | import cloud.unionj.generator.openapi3.model.paths.Response;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression.paths
10 | * date 2020/12/19
11 | */
12 | public class ResponseBuilder {
13 |
14 | private Response response;
15 |
16 | public ResponseBuilder() {
17 | this.response = new Response();
18 | }
19 |
20 | public void description(String description) {
21 | this.response.setDescription(description);
22 | }
23 |
24 | public void content(Content content) {
25 | this.response.setContent(content);
26 | }
27 |
28 | public Response build() {
29 | return this.response;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/paths/ResponsesBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.Response;
4 | import cloud.unionj.generator.openapi3.model.paths.Responses;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression.paths
10 | * date 2020/12/19
11 | */
12 | public class ResponsesBuilder {
13 |
14 | private Responses responses;
15 |
16 | public ResponsesBuilder() {
17 | this.responses = new Responses();
18 | }
19 |
20 | public void response200(Response response200) {
21 | this.responses.setResponse200(response200);
22 | }
23 |
24 | public void response400(Response response400) {
25 | this.responses.setResponse400(response400);
26 | }
27 |
28 | public void response401(Response response401) {
29 | this.responses.setResponse401(response401);
30 | }
31 |
32 | public void response403(Response response403) {
33 | this.responses.setResponse403(response403);
34 | }
35 |
36 | public void response404(Response response404) {
37 | this.responses.setResponse404(response404);
38 | }
39 |
40 | public void response405(Response response405) {
41 | this.responses.setResponse405(response405);
42 | }
43 |
44 | public void defaultResp(Response defaultResp) {
45 | this.responses.setDefaultResp(defaultResp);
46 | }
47 |
48 | public Responses build() {
49 | return this.responses;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/servers/ServerBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.servers;
2 |
3 |
4 | import cloud.unionj.generator.openapi3.model.servers.Server;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression
10 | * date 2020/12/14
11 | */
12 | public class ServerBuilder {
13 |
14 | private Server server;
15 |
16 | public ServerBuilder() {
17 | this.server = new Server();
18 | }
19 |
20 | public void url(String url) {
21 | this.server.setUrl(url);
22 | }
23 |
24 | public Server build() {
25 | return this.server;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/expression/tags/TagBuilder.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.expression.tags;
2 |
3 |
4 | import cloud.unionj.generator.openapi3.model.tags.Tag;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.expression
10 | * date 2020/12/14
11 | */
12 | public class TagBuilder {
13 |
14 | private Tag tag;
15 |
16 | public TagBuilder() {
17 | this.tag = new Tag();
18 | }
19 |
20 | public void name(String name) {
21 | this.tag.setName(name);
22 | }
23 |
24 | public void description(String description) {
25 | this.tag.setDescription(description);
26 | }
27 |
28 | public Tag build() {
29 | return this.tag;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/AdditionalPropertiesDeserializer.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 | import com.fasterxml.jackson.core.JsonParser;
5 | import com.fasterxml.jackson.core.JsonProcessingException;
6 | import com.fasterxml.jackson.core.ObjectCodec;
7 | import com.fasterxml.jackson.core.type.TypeReference;
8 | import com.fasterxml.jackson.databind.DeserializationContext;
9 | import com.fasterxml.jackson.databind.JsonDeserializer;
10 | import com.fasterxml.jackson.databind.JsonMappingException;
11 | import com.fasterxml.jackson.databind.JsonNode;
12 | import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
13 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
14 | import com.fasterxml.jackson.databind.node.IntNode;
15 |
16 | import java.io.IOException;
17 |
18 | public class AdditionalPropertiesDeserializer extends StdDeserializer {
19 |
20 | public AdditionalPropertiesDeserializer() {
21 | this(null);
22 | }
23 |
24 | public AdditionalPropertiesDeserializer(Class> vc) {
25 | super(vc);
26 | }
27 |
28 | @Override
29 | public Schema deserialize(JsonParser jp, DeserializationContext ctxt)
30 | throws IOException, JsonProcessingException {
31 | ObjectCodec codec = jp.getCodec();
32 | JsonNode node = codec.readTree(jp);
33 | if (node.isBoolean()) {
34 | return null;
35 | }
36 | Schema schema = codec.treeToValue(node, Schema.class);
37 | return schema;
38 | }
39 | }
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Callback.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * cloud.unionj.generator.openapi3.model
7 | * date 2020/12/14
8 | */
9 | public class Callback {
10 | }
11 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Components.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import cloud.unionj.generator.openapi3.model.paths.*;
4 | import cloud.unionj.generator.openapi3.model.paths.*;
5 | import lombok.Data;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | /**
11 | * @author created by wubin
12 | * @version v0.1
13 | * cloud.unionj.generator.openapi3.model
14 | * date 2020/12/14
15 | */
16 | @Data
17 | public class Components {
18 |
19 | private Map schemas = new HashMap<>();
20 |
21 | public void schemas(String key, Schema schema) {
22 | this.schemas.put(key, schema);
23 | }
24 |
25 | // TODO
26 | private Map responses;
27 |
28 | // TODO
29 | private Map parameters;
30 |
31 | // TODO
32 | private Map examples;
33 |
34 | // TODO
35 | private Map requestBodies;
36 |
37 | // TODO
38 | private Map headers;
39 |
40 | // TODO
41 | private Map securitySchemes;
42 |
43 | // TODO
44 | private Map links;
45 |
46 | // TODO
47 | private Map callbacks;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Discriminator.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.model
12 | * date 2020/12/16
13 | */
14 | @Data
15 | public class Discriminator {
16 |
17 | private String propertyName;
18 | private Map mapping = new HashMap<>();
19 |
20 | public void setMapping(String key, String value) {
21 | this.mapping.put(key, value);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Example.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class Example {
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/ExternalDocs.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class ExternalDocs {
13 |
14 | private String description;
15 | private String url;
16 | }
17 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Generic.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import cloud.unionj.generator.openapi3.expression.ISchemaFinder;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | public class Generic extends Schema {
12 | public Generic(ISchemaFinder schemaFinder) {
13 | super(schemaFinder);
14 | }
15 |
16 | public Generic() {
17 | super(null);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Openapi3.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import cloud.unionj.generator.openapi3.NullAwareBeanUtilsBean;
4 | import cloud.unionj.generator.openapi3.model.info.Info;
5 | import cloud.unionj.generator.openapi3.model.paths.Path;
6 | import cloud.unionj.generator.openapi3.model.servers.Server;
7 | import cloud.unionj.generator.openapi3.model.tags.Tag;
8 | import lombok.Data;
9 | import lombok.SneakyThrows;
10 | import org.apache.commons.beanutils.BeanUtilsBean;
11 |
12 | import java.util.ArrayList;
13 | import java.util.LinkedHashMap;
14 | import java.util.List;
15 | import java.util.Map;
16 |
17 | /**
18 | * @author created by wubin
19 | * @version v0.1
20 | * cloud.unionj.generator.openapi3.model
21 | * date 2020/12/14
22 | */
23 | @Data
24 | public class Openapi3 {
25 |
26 | private String openapi = "3.0.2";
27 | private Info info;
28 | private List servers = new ArrayList<>();
29 | private List tags = new ArrayList<>();
30 | private Map paths = new LinkedHashMap<>();
31 | private Components components = new Components();
32 |
33 | public void servers(Server server) {
34 | this.servers.add(server);
35 | }
36 |
37 | public void tags(Tag tag) {
38 | this.tags.add(tag);
39 | }
40 |
41 | @SneakyThrows
42 | public void paths(Path path) {
43 | Path origin = this.paths.get(path.getEndpoint());
44 | if (origin != null) {
45 | BeanUtilsBean notNull = new NullAwareBeanUtilsBean();
46 | notNull.copyProperties(path, origin);
47 | }
48 | this.paths.put(path.getEndpoint(), path);
49 | }
50 |
51 | // TODO
52 | private ExternalDocs externalDocs;
53 | }
54 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/Security.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class Security {
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/SecurityScheme.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class SecurityScheme {
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/info/Contact.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.info;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class Contact {
13 |
14 | private String email;
15 | }
16 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/info/Info.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.info;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class Info {
13 | private String title;
14 | private String description;
15 | private String termsOfService;
16 | private Contact contact;
17 | private License license;
18 | private String version;
19 | }
20 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/info/License.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.info;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class License {
13 |
14 | private String name;
15 | private String url;
16 | }
17 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Content.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.model
10 | * date 2020/12/14
11 | */
12 | @Data
13 | public class Content {
14 |
15 | @JsonProperty("text/plain")
16 | private MediaType textPlain;
17 |
18 | @JsonProperty("application/json")
19 | private MediaType applicationJson;
20 |
21 | /**
22 | * requestBody:
23 | * content:
24 | * application/x-www-form-urlencoded:
25 | * schema:
26 | * type: object
27 | * properties:
28 | * id:
29 | * type: string
30 | * format: uuid
31 | * address:
32 | * # complex types are stringified to support RFC 1866
33 | * type: object
34 | * properties: {}
35 | */
36 | @JsonProperty("application/x-www-form-urlencoded")
37 | private MediaType applicationXWwwFormUrlencoded;
38 |
39 | /**
40 | * for single file upload
41 | *
42 | * requestBody:
43 | * content:
44 | * application/octet-stream:
45 | * schema:
46 | * # a binary file of any type
47 | * type: string
48 | * format: binary
49 | */
50 | @JsonProperty("application/octet-stream")
51 | private MediaType applicationOctetStream;
52 |
53 | /**
54 | * for multiple files upload
55 | *
56 | * requestBody:
57 | * content:
58 | * multipart/form-data:
59 | * schema:
60 | * properties:
61 | * # The property name 'file' will be used for all files.
62 | * file:
63 | * type: array
64 | * items:
65 | * type: string
66 | * format: binary
67 | */
68 | @JsonProperty("multipart/form-data")
69 | private MediaType multipartFormData;
70 |
71 | @JsonProperty("*/*")
72 | private MediaType defaultMediaType;
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Encoding.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model.paths
9 | * date 2020/12/19
10 | */
11 | @Data
12 | public class Encoding {
13 | }
14 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Header.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import cloud.unionj.generator.openapi3.model.Schema;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author created by wubin
9 | * @version v0.1
10 | * cloud.unionj.generator.openapi3.model
11 | * date 2020/12/14
12 | */
13 | @Data
14 | public class Header {
15 |
16 | @JsonProperty("$ref")
17 | private String ref;
18 |
19 | private String description;
20 | private boolean required;
21 | private boolean deprecated;
22 | private Object example;
23 | public Schema schema;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Link.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | /**
4 | * @author created by wubin
5 | * @version v0.1
6 | * cloud.unionj.generator.openapi3.model
7 | * date 2020/12/14
8 | */
9 | public class Link {
10 | }
11 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/MediaType.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.Example;
4 | import cloud.unionj.generator.openapi3.model.Schema;
5 | import lombok.Data;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.openapi3.model.paths
13 | * date 2020/12/19
14 | */
15 | @Data
16 | public class MediaType {
17 |
18 | private Schema schema;
19 |
20 | private Object example;
21 |
22 | // TODO
23 | private Map examples;
24 |
25 | // TODO
26 | private Map encoding;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Parameter.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 | import com.fasterxml.jackson.annotation.JsonCreator;
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 | import com.fasterxml.jackson.annotation.JsonValue;
7 | import lombok.Data;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.openapi3.model
13 | * date 2020/12/14
14 | */
15 | @Data
16 | public class Parameter {
17 |
18 | @JsonProperty("$ref")
19 | private String ref;
20 |
21 | private String name;
22 |
23 | public enum InEnum {
24 | QUERY("query"),
25 | HEADER("header"),
26 | PATH("path");
27 |
28 | private String value;
29 |
30 | InEnum(String value) {
31 | this.value = value;
32 | }
33 |
34 | @Override
35 | @JsonValue
36 | public String toString() {
37 | return String.valueOf(value);
38 | }
39 |
40 | @JsonCreator
41 | public static InEnum fromValue(String text) {
42 | for (InEnum b : InEnum.values()) {
43 | if (String.valueOf(b.value).equals(text)) {
44 | return b;
45 | }
46 | }
47 | return null;
48 | }
49 | }
50 |
51 | private InEnum in;
52 | private String description;
53 | private boolean required;
54 | private boolean deprecated;
55 | private Object example;
56 | public Schema schema;
57 |
58 | // TODO
59 | private String style;
60 |
61 | // TODO
62 | private boolean explode;
63 |
64 | // TODO
65 | private boolean allowReserved;
66 |
67 | // TODO
68 | private Content content;
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Path.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 | import org.apache.commons.collections4.CollectionUtils;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * @author created by wubin
12 | * @version v0.1
13 | * cloud.unionj.generator.openapi3.model
14 | * date 2020/12/14
15 | */
16 | @Data
17 | public class Path {
18 |
19 | @JsonProperty("x-endpoint")
20 | private String endpoint;
21 |
22 | private Operation get;
23 |
24 | private Operation post;
25 |
26 | private Operation put;
27 |
28 | private Operation delete;
29 |
30 | // TODO
31 | private List parameters;
32 |
33 | public List returnTags() {
34 | List result = new ArrayList<>();
35 | if (CollectionUtils.isEmpty(result)) {
36 | if (this.get != null) {
37 | result = this.get.getTags();
38 | }
39 | }
40 | if (CollectionUtils.isEmpty(result)) {
41 | if (this.post != null) {
42 | result = this.post.getTags();
43 | }
44 | }
45 | if (CollectionUtils.isEmpty(result)) {
46 | if (this.put != null) {
47 | result = this.put.getTags();
48 | }
49 | }
50 | if (CollectionUtils.isEmpty(result)) {
51 | if (this.delete != null) {
52 | result = this.delete.getTags();
53 | }
54 | }
55 | return result;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/RequestBody.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.model
10 | * date 2020/12/14
11 | */
12 | @Data
13 | public class RequestBody {
14 |
15 | @JsonProperty("$ref")
16 | private String ref;
17 |
18 | private String description;
19 | private Content content;
20 | private boolean required;
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Response.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * @author created by wubin
10 | * @version v0.1
11 | * cloud.unionj.generator.openapi3.model
12 | * date 2020/12/14
13 | */
14 | @Data
15 | public class Response {
16 |
17 | @JsonProperty("$ref")
18 | private String ref;
19 |
20 | // REQUIRED
21 | private String description;
22 |
23 | private Content content;
24 |
25 | // TODO
26 | private Map headers;
27 |
28 | // TODO
29 | private Map links;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/paths/Responses.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.paths;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.model
10 | * date 2020/12/14
11 | */
12 | @Data
13 | public class Responses {
14 |
15 | @JsonProperty("200")
16 | private Response response200;
17 |
18 | @JsonProperty("400")
19 | private Response response400;
20 |
21 | @JsonProperty("401")
22 | private Response response401;
23 |
24 | @JsonProperty("403")
25 | private Response response403;
26 |
27 | @JsonProperty("404")
28 | private Response response404;
29 |
30 | @JsonProperty("405")
31 | private Response response405;
32 |
33 | // TODO
34 | @JsonProperty("default")
35 | private Response defaultResp;
36 | }
37 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/servers/Server.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.servers;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author created by wubin
7 | * @version v0.1
8 | * cloud.unionj.generator.openapi3.model
9 | * date 2020/12/14
10 | */
11 | @Data
12 | public class Server {
13 |
14 | private String url;
15 | }
16 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/model/tags/Tag.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model.tags;
2 |
3 | import cloud.unionj.generator.openapi3.model.ExternalDocs;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author created by wubin
8 | * @version v0.1
9 | * cloud.unionj.generator.openapi3.model
10 | * date 2020/12/14
11 | */
12 | @Data
13 | public class Tag {
14 |
15 | private String name;
16 | private String description;
17 |
18 | // TODO
19 | private ExternalDocs externalDocs;
20 | }
21 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/main/java/cloud/unionj/generator/openapi3/parser/Openapi3Parser.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.parser;
2 |
3 | import cloud.unionj.generator.openapi3.model.Openapi3;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import com.fasterxml.jackson.databind.DeserializationFeature;
6 | import com.fasterxml.jackson.databind.JsonNode;
7 | import com.fasterxml.jackson.databind.ObjectMapper;
8 | import io.swagger.parser.OpenAPIParser;
9 | import io.swagger.v3.parser.core.models.SwaggerParseResult;
10 | import lombok.SneakyThrows;
11 | import org.apache.commons.io.IOUtils;
12 |
13 | import java.io.*;
14 | import java.net.URL;
15 | import java.nio.charset.StandardCharsets;
16 |
17 | /**
18 | * @author created by wubin
19 | * @version v0.1
20 | * cloud.unionj.generator.openapi3.parser
21 | * date 2020/12/20
22 | */
23 | public class Openapi3Parser {
24 |
25 | private static ObjectMapper objectMapper;
26 |
27 | static {
28 | objectMapper = new ObjectMapper();
29 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
30 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
31 | }
32 |
33 | public Openapi3 parse(File doc) throws IOException {
34 | try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(doc))) {
35 | return parse(is);
36 | }
37 | }
38 |
39 | public Openapi3 parse(URL doc) throws IOException {
40 | try (BufferedInputStream is = new BufferedInputStream(doc.openStream())) {
41 | return parse(is);
42 | }
43 | }
44 |
45 | public Openapi3 parse(InputStream is) throws IOException {
46 | String doc = IOUtils.toString(is, StandardCharsets.UTF_8.name());
47 | JsonNode jsonNode = objectMapper.readValue(doc, JsonNode.class);
48 | Openapi3 openapi3;
49 | if (jsonNode.hasNonNull("openapi")) {
50 | openapi3 = objectMapper.readValue(doc, Openapi3.class);
51 | } else {
52 | String parsed = parse(doc);
53 | openapi3 = objectMapper.readValue(parsed, Openapi3.class);
54 | }
55 | return openapi3;
56 | }
57 |
58 | @SneakyThrows
59 | private String parse(String inputAsString) {
60 | SwaggerParseResult output = new OpenAPIParser().readContents(inputAsString, null, null);
61 | if (output == null) {
62 | throw new Exception("Invalid Swagger/OpenAPI specification!");
63 | }
64 | if (output.getOpenAPI() == null) {
65 | throw new Exception("Invalid Swagger/OpenAPI specification!");
66 | }
67 | return objectMapper.writeValueAsString(output.getOpenAPI());
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/test/java/cloud/unionj/generator/openapi3/dsl/InfoTest.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl;
2 |
3 | import cloud.unionj.generator.openapi3.PathConfig;
4 | import cloud.unionj.generator.openapi3.PathHelper;
5 | import cloud.unionj.generator.openapi3.model.Openapi3;
6 | import com.fasterxml.jackson.annotation.JsonInclude;
7 | import com.fasterxml.jackson.core.JsonProcessingException;
8 | import com.fasterxml.jackson.databind.ObjectMapper;
9 | import org.junit.Test;
10 |
11 | import static cloud.unionj.generator.openapi3.dsl.Generic.generic;
12 | import static cloud.unionj.generator.openapi3.dsl.Reference.reference;
13 | import static cloud.unionj.generator.openapi3.dsl.Schema.schema;
14 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.*;
15 | import static cloud.unionj.generator.openapi3.dsl.info.Info.info;
16 | import static cloud.unionj.generator.openapi3.dsl.info.Info.openapi3;
17 | import static cloud.unionj.generator.openapi3.dsl.servers.Server.server;
18 |
19 | /**
20 | * @author created by wubin
21 | * @version v0.1
22 | * cloud.unionj.generator.openapi3.dsl
23 | * date 2020/12/14
24 | */
25 | public class InfoTest {
26 |
27 | public static cloud.unionj.generator.openapi3.model.Schema ResultDTO = schema(sb -> {
28 | sb.type("object");
29 | sb.title("ResultDTO");
30 | sb.properties("code", int32);
31 | sb.properties("msg", string);
32 | sb.properties("data", T);
33 | });
34 |
35 | public static cloud.unionj.generator.openapi3.model.Schema PageResultVO = schema(sb -> {
36 | sb.type("object");
37 | sb.title("PageResultVO");
38 | sb.properties("items", ListT);
39 | sb.properties("searchCount", bool);
40 | sb.properties("pages", int32("当前分页总页数"));
41 | });
42 |
43 | public static cloud.unionj.generator.openapi3.model.Schema OptLogVO = schema(sb -> {
44 | sb.type("object");
45 | sb.title("OptLogVO");
46 | sb.properties("id", int32);
47 | sb.properties("eventStatus", string("事件状态"));
48 | sb.properties("eventType", string("事件类型"));
49 | sb.properties("eventObject", string("事件对象"));
50 | sb.properties("creatorUserId", int32);
51 | sb.properties("creatorCompanyId", int32);
52 | sb.properties("createAt", dateTime);
53 | sb.properties("name", string("操作人名字"));
54 | });
55 |
56 | public static cloud.unionj.generator.openapi3.model.Schema OptLogPageCondition = schema(sb -> {
57 | sb.type("object");
58 | sb.title("OptLogPageCondition");
59 | sb.properties("startTime", dateTime("开始时间"));
60 | sb.properties("endTime", dateTime("结束时间"));
61 | sb.properties("keyword", string("关键字搜索"));
62 | sb.properties("eventStatus", string("事件状态"));
63 | sb.properties("eventType", string("事件类型"));
64 | });
65 |
66 | public static cloud.unionj.generator.openapi3.model.Schema PageResultVOOptLogVO = generic(gb -> gb.generic(PageResultVO, reference(rb -> rb.ref(OptLogVO.getTitle()))));
67 | public static cloud.unionj.generator.openapi3.model.Schema ResultDTOPageResultVOOptLogVO = generic(gb -> gb.generic(ResultDTO, reference(rb -> rb.ref(PageResultVOOptLogVO.getTitle()))));
68 |
69 | @Test
70 | public void TestInfo1() throws JsonProcessingException {
71 | Openapi3 openAPI3 = openapi3(ob -> {
72 | info(ib -> {
73 | ib.title("用户管理模块");
74 | ib.version("v1.0.0");
75 | });
76 |
77 | server(sb -> {
78 | sb.url("http://unionj.cloud");
79 | });
80 |
81 | PathHelper.post("/admin/opt/log/list", PathConfig.builder()
82 | .summary("操作日志")
83 | .tags(new String[]{"admin_operate_log", "AdminOperateLog"})
84 | .reqSchema(OptLogPageCondition)
85 | .respSchema(ResultDTOPageResultVOOptLogVO)
86 | .build()
87 | );
88 | });
89 | ObjectMapper objectMapper = new ObjectMapper();
90 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
91 | System.out.println(objectMapper.writeValueAsString(openAPI3));
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/test/java/cloud/unionj/generator/openapi3/dsl/paths/Components.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.dsl.paths;
2 |
3 | import cloud.unionj.generator.openapi3.model.Schema;
4 |
5 | import static cloud.unionj.generator.openapi3.dsl.Generic.generic;
6 | import static cloud.unionj.generator.openapi3.dsl.Schema.schema;
7 | import static cloud.unionj.generator.openapi3.dsl.SchemaHelper.*;
8 |
9 | /**
10 | * @author created by wubin
11 | * @version v0.1
12 | * cloud.unionj.generator.openapi3.dsl.paths
13 | * date 2020/12/19
14 | */
15 | public class Components {
16 |
17 | private static Schema sizeProperty = int32("每页条数,默认10,传-1查出全部数据");
18 |
19 | private static Schema currentProperty = int32("当前页,从1开始");
20 |
21 | private static Schema offsetProperty = int32("偏移量");
22 |
23 | private static Schema sortProperty = string("排序条件字符串:排序字段前使用'-'(降序)和'+'(升序)号表示排序规则,多个排序字段用','隔开",
24 | "+id,-create_at");
25 |
26 | private static Schema pageProperty = int32("当前页,从1开始");
27 |
28 | private static Schema limitProperty = int32("每页条数,默认10, 传-1查出全部数据", 10);
29 |
30 | private static Schema maxPageProperty = int32("导出结束页");
31 |
32 | private static Schema totalProperty = int64("总数,入参传入此参数则不再查询count,以此total为准");
33 |
34 | private static Schema topStatusProperty = int32("需要排在前的状态");
35 |
36 | public static Schema ShopRecommendApplyDetailCondition = schema(sb -> {
37 | sb.type("object");
38 | sb.title("ShopRecommendApplyDetailCondition");
39 | sb.properties("total", totalProperty);
40 | sb.properties("size", sizeProperty);
41 | sb.properties("current", currentProperty);
42 | sb.properties("maxPage", maxPageProperty);
43 | sb.properties("topStatus", topStatusProperty);
44 | sb.properties("shopName", string("店铺名称"));
45 | sb.properties("status", int32Array("审批状态"));
46 | sb.properties("limit", limitProperty);
47 | sb.properties("page", pageProperty);
48 | sb.properties("sort", sortProperty);
49 | sb.properties("offset", offsetProperty);
50 | });
51 |
52 | public static Schema ResultDTO = schema(sb -> {
53 | sb.type("object");
54 | sb.title("ResultDTO");
55 | sb.properties("code", int32);
56 | sb.properties("msg", string);
57 | sb.properties("data", T);
58 | });
59 |
60 | public static Schema PageResultVO = schema(sb -> {
61 | sb.type("object");
62 | sb.title("PageResultVO");
63 | sb.properties("items", ListT);
64 | sb.properties("total", totalProperty);
65 | sb.properties("size", sizeProperty);
66 | sb.properties("current", currentProperty);
67 | sb.properties("searchCount", bool);
68 | sb.properties("pages", int32("当前分页总页数"));
69 | sb.properties("offset", offsetProperty);
70 | });
71 |
72 | public static Schema User = schema(sb -> {
73 | sb.type("object");
74 | sb.title("User");
75 | sb.properties("name", string);
76 | sb.properties("info", T);
77 | });
78 |
79 | public static Schema UserDate = generic(gb -> gb.generic(User, dateTime));
80 | public static Schema UserInteger = generic(gb -> gb.generic(User, int32));
81 | public static Schema ResultDTOListUserDate = generic(gb -> gb.generic(ResultDTO, uniqueRefArray(UserDate.getxTitle())));
82 |
83 | public static Schema ResultDTOListUserInteger = generic(gb -> gb.generic(ResultDTO, uniqueRefArray(UserInteger.getxTitle())));
84 |
85 | public static Schema ResultDTOString = generic(gb -> gb.generic(ResultDTO, string));
86 | }
87 |
--------------------------------------------------------------------------------
/unionj-generator-openapi/src/test/java/cloud/unionj/generator/openapi3/model/Openapi3Test.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.openapi3.model;
2 |
3 | import cloud.unionj.generator.openapi3.dsl.SchemaHelper;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import com.fasterxml.jackson.databind.DeserializationFeature;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 | import org.junit.Test;
8 |
9 | import java.io.*;
10 | import java.lang.reflect.Field;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import static cloud.unionj.generator.openapi3.dsl.Schema.schema;
15 |
16 | /**
17 | * @author created by wubin
18 | * @version v0.1
19 | * cloud.unionj.generator.openapi3.model
20 | * date 2020/12/19
21 | */
22 | public class Openapi3Test {
23 |
24 | public static Schema MAGIC = new Schema(null);
25 | private static String privateMagic = "privateMagic";
26 |
27 | @Test
28 | public void parse() throws IOException {
29 | ObjectMapper objectMapper = new ObjectMapper();
30 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
31 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
32 |
33 | try (InputStream is = ClassLoader.getSystemResourceAsStream("petstore3.json")) {
34 | Openapi3 openapi3 = objectMapper.readValue(is, Openapi3.class);
35 | System.out.println(openapi3);
36 | }
37 | }
38 |
39 | @Test
40 | public void reflectionTest() throws IllegalAccessException {
41 | Field[] declaredFields = Openapi3Test.class.getDeclaredFields();
42 | List staticFields = new ArrayList<>();
43 | for (Field field : declaredFields) {
44 | if (java.lang.reflect.Modifier.isStatic(field.getModifiers()) && java.lang.reflect.Modifier.isPublic(field.getModifiers())) {
45 | staticFields.add(field);
46 | }
47 | }
48 | System.out.println(staticFields.get(0).get(null));
49 | }
50 |
51 | @Test
52 | public void testSchemaEqual() {
53 | Schema avatar = schema(file -> {
54 | file.type("string");
55 | file.format("binary");
56 | file.description("用户头像");
57 | });
58 | System.out.println(avatar.equals(SchemaHelper.file));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/unionj-generator-ui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 |
8 | io.github.unionj-cloud
9 | unionj-generator
10 | 1.6.8-SNAPSHOT
11 |
12 | unionj-generator-ui
13 | unionj-generator-ui
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 | 2.2.5.RELEASE
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-thymeleaf
24 | 2.2.5.RELEASE
25 |
26 |
27 | io.github.unionj-cloud
28 | unionj-generator-core
29 | ${project.version}
30 |
31 |
32 | io.github.unionj-cloud
33 | unionj-generator-openapi
34 | ${project.version}
35 |
36 |
37 | commons-codec
38 | commons-codec
39 | 1.15
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/java/cloud/unionj/generator/ui/config/DocAuthProperties.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.ui.config;
2 |
3 | import lombok.Data;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.PropertySource;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Data
9 | @Component
10 | @PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
11 | public class DocAuthProperties {
12 | @Value("${doc.auth.username:}")
13 | private String username;
14 | @Value("${doc.auth.password:}")
15 | private String password;
16 | @Value("${spring.mvc.servlet.path:}")
17 | private String prefix;
18 | }
19 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/java/cloud/unionj/generator/ui/config/JacksonConfig.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.ui.config;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import org.springframework.boot.autoconfigure.AutoConfigureBefore;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
7 | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
8 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 |
12 | import java.time.ZoneId;
13 | import java.util.Locale;
14 | import java.util.TimeZone;
15 |
16 | @Configuration
17 | @ConditionalOnClass(ObjectMapper.class)
18 | @AutoConfigureBefore(JacksonAutoConfiguration.class)
19 | public class JacksonConfig {
20 | @Bean
21 | public Jackson2ObjectMapperBuilderCustomizer customizer() {
22 | return builder -> {
23 | builder.serializationInclusion(JsonInclude.Include.NON_EMPTY);
24 | builder.locale(Locale.CHINA);
25 | builder.failOnUnknownProperties(false);
26 | builder.failOnEmptyBeans(false);
27 | builder.timeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
28 | };
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/java/cloud/unionj/generator/ui/config/UIConfig.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.ui.config;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | /**
7 | * @author: created by wubin
8 | * cloud.unionj.generator.ui.config
9 | * 2021/8/16
10 | */
11 | @Configuration
12 | @ComponentScan(basePackages = {"cloud.unionj.generator.ui"})
13 | public class UIConfig {
14 | }
15 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/java/cloud/unionj/generator/ui/controller/UIController.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.ui.controller;
2 |
3 | import cloud.unionj.generator.openapi3.model.Openapi3;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import com.fasterxml.jackson.databind.SerializationFeature;
7 | import lombok.SneakyThrows;
8 | import org.apache.commons.lang3.StringUtils;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.stereotype.Controller;
11 | import org.springframework.ui.Model;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 | import org.springframework.web.bind.annotation.RequestMapping;
14 | import org.springframework.web.bind.annotation.ResponseBody;
15 |
16 | import javax.annotation.PostConstruct;
17 | import javax.servlet.http.HttpServletRequest;
18 | import java.lang.reflect.Method;
19 |
20 | /**
21 | * @author: created by wubin
22 | * cloud.unionj.generator.ui
23 | * 2021/8/16
24 | */
25 | @Controller
26 | @RequestMapping("/unionj-cloud")
27 | public class UIController {
28 |
29 | private static String entry = null;
30 | private static Openapi3 openAPI = new Openapi3();
31 |
32 | @Value("${cloud.unionj.generator.entry:gen.Openapi3Designer.design}")
33 | public void setPrivateName(String privateName) {
34 | UIController.entry = privateName;
35 | }
36 |
37 | @PostConstruct
38 | public void init() {
39 | String designClass = UIController.entry.substring(0, UIController.entry.lastIndexOf("."));
40 | String designMethod = UIController.entry.substring(UIController.entry.lastIndexOf(".") + 1);
41 | try {
42 | Class> designer = UIController.class.getClassLoader().loadClass(designClass);
43 | Method design = designer.getMethod(designMethod);
44 | openAPI = (Openapi3) design.invoke(null);
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | }
48 | }
49 |
50 | @SneakyThrows
51 | @GetMapping("/doc")
52 | public String doc(HttpServletRequest request, Model model) {
53 | ObjectMapper objectMapper = new ObjectMapper();
54 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
55 | objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
56 | model.addAttribute("doc", objectMapper.writeValueAsString(openAPI));
57 | String full = request.getRequestURL().toString();
58 | String uri = request.getRequestURI();
59 | String servletPath = request.getServletPath();
60 | if (servletPath.equals(uri)) {
61 | servletPath = "";
62 | }
63 | String docUrl = StringUtils.removeEnd(full, uri) + servletPath + "/unionj-cloud/openapi3.json";
64 | model.addAttribute("docUrl", docUrl);
65 | return "index";
66 | }
67 |
68 | @SneakyThrows
69 | @GetMapping("/openapi3.json")
70 | @ResponseBody
71 | public Openapi3 openapi3() {
72 | return openAPI;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/java/cloud/unionj/generator/ui/filter/DocAuthFilter.java:
--------------------------------------------------------------------------------
1 | package cloud.unionj.generator.ui.filter;
2 |
3 | import cloud.unionj.generator.ui.config.DocAuthProperties;
4 | import lombok.RequiredArgsConstructor;
5 | import lombok.SneakyThrows;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.apache.commons.codec.binary.Base64;
8 | import org.apache.commons.lang3.StringUtils;
9 | import org.springframework.http.HttpStatus;
10 | import org.springframework.stereotype.Component;
11 |
12 | import javax.servlet.*;
13 | import javax.servlet.annotation.WebFilter;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 | import java.io.IOException;
17 |
18 | @Component
19 | @WebFilter(filterName = "DocAuthFilter", urlPatterns = "/**")
20 | @RequiredArgsConstructor
21 | @Slf4j
22 | public class DocAuthFilter implements Filter {
23 | private final DocAuthProperties docAuthProperties;
24 | private static final String AUTHORIZATION_HEADER = "Authorization";
25 | private static final String BASIC = "Basic";
26 | private static final String SPLIT = ":";
27 | private static final String DOC_PREFIX = "/unionj-cloud";
28 | private static final String DEFAULT_USER_PASSWORD = "admin";
29 |
30 | @SneakyThrows
31 | @Override
32 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
33 | throws IOException, ServletException {
34 | HttpServletRequest httpServletRequest = (HttpServletRequest) request;
35 | String token = httpServletRequest.getHeader(AUTHORIZATION_HEADER);
36 | String prefix = docAuthProperties.getPrefix();
37 | if (httpServletRequest.getRequestURI()
38 | .startsWith(prefix + DOC_PREFIX)) {
39 | boolean passed = false;
40 | if (StringUtils.isNotBlank(token)) {
41 | String userNameAndPassword = StringUtils.removeStart(token, BASIC)
42 | .trim();
43 | if (StringUtils.isNotBlank(userNameAndPassword)) {
44 | userNameAndPassword = new String(Base64.decodeBase64(userNameAndPassword));
45 | String[] params = userNameAndPassword.split(SPLIT);
46 | String username;
47 | String password;
48 | if (StringUtils.isBlank(docAuthProperties.getUsername()) || StringUtils.isBlank(
49 | docAuthProperties.getPassword())) {
50 | username = DEFAULT_USER_PASSWORD;
51 | password = DEFAULT_USER_PASSWORD;
52 | } else {
53 | username = docAuthProperties.getUsername();
54 | password = docAuthProperties.getPassword();
55 | }
56 | if (username.equals(params[0]) && password.equals(params[1])) {
57 | passed = true;
58 | }
59 | }
60 | }
61 | if (!passed) {
62 | HttpServletResponse httpServletResponse = (HttpServletResponse) response;
63 | httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
64 | httpServletResponse.setHeader("WWW-Authenticate", "Basic realm=provide username and password");
65 | httpServletResponse.getWriter()
66 | .write(HttpStatus.UNAUTHORIZED.getReasonPhrase());
67 | return;
68 | }
69 | }
70 | chain.doFilter(request, response);
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/resources/META-INF/resources/css/chunk-libs.dc65e09b.css:
--------------------------------------------------------------------------------
1 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}[hidden],template{display:none}#nprogress{pointer-events:none}#nprogress .bar{background:#29d;position:fixed;z-index:1031;top:0;left:0;width:100%;height:2px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;box-shadow:0 0 10px #29d,0 0 5px #29d;opacity:1;transform:rotate(3deg) translateY(-4px)}#nprogress .spinner{display:block;position:fixed;z-index:1031;top:15px;right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:#29d;border-left-color:#29d;border-radius:50%;-webkit-animation:nprogress-spinner .4s linear infinite;animation:nprogress-spinner .4s linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0deg)}to{-webkit-transform:rotate(1turn)}}@keyframes nprogress-spinner{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/resources/META-INF/resources/fonts/element-icons.535877f5.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unionj-cloud/unionj-generator/0ff0bb3895e285b55362892291d5561eaa8d76df/unionj-generator-ui/src/main/resources/META-INF/resources/fonts/element-icons.535877f5.woff
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/resources/META-INF/resources/fonts/element-icons.732389de.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unionj-cloud/unionj-generator/0ff0bb3895e285b55362892291d5561eaa8d76df/unionj-generator-ui/src/main/resources/META-INF/resources/fonts/element-icons.732389de.ttf
--------------------------------------------------------------------------------
/unionj-generator-ui/src/main/resources/META-INF/resources/js/runtime.9dc2cf20.js:
--------------------------------------------------------------------------------
1 | (function(e){function r(r){for(var n,l,i=r[0],a=r[1],f=r[2],c=0,s=[];c