# unionj-generator
**Repository Path**: unionj-cloud/unionj-generator
## Basic Information
- **Project Name**: unionj-generator
- **Description**: OpenAPI 3.0 specification Dsl and a collection of code generators
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2021-07-02
- **Last Updated**: 2022-07-17
## Categories & Tags
**Categories**: code-generator
**Tags**: None
## README
# unionj-generator
Unionj-generator is a collection of code generators for spring boot applications with a built-in RESTful api design tool(DSL) compatible with
[OpenAPI 3.0.0 specification](http://spec.openapis.org/oas/v3.0.3).
Including:
- backend: Using dsl or OpenAPI 3.0 json doc to generate vo, proto, controller, service and feign modules for spring boot backend
- openapi: dsl implementing [OpenAPI 3.0.0 specification](http://spec.openapis.org/oas/v3.0.3)
- ui: OpenAPI3 documentation web UI
- maven plugin: maven command line command to generate backend code
### TOC
- [Installation](#installation)
- [OpenAPI3 Web UI Screenshot](#openapi3-web-ui-screenshot)
- [Usage](#usage)
- [Demo project](#demo-project)
- [Recommend project structure](#recommend-project-structure)
- [DSL](#dsl)
- [Schema](#schema)
- [Example](#example)
- [SchemaHelper](#schemahelper)
- [Generic](#generic)
- [Syntax](#syntax)
- [Path](#path)
- [Example](#example-1)
- [Backend](#backend)
- [Example](#example-2)
- [Must Know](#must-know)
- [Tutorials](#tutorials)
- [TODO](#todo)
- [Sister Project](#sister-project)
- [Community](#community)
# Installation
```xml
io.github.unionj-cloud
unionj-generator-backend
1.6.7-SNAPSHOT
io.github.unionj-cloud
unionj-generator-openapi
1.6.7-SNAPSHOT
io.github.unionj-cloud
unionj-generator-ui
1.6.7-SNAPSHOT
```
```xml
io.github.unionj-cloud
unionj-generator-maven-plugin
1.6.7-SNAPSHOT
false
petStore
codegen
false
https://petstore3.swagger.io/api/v3/openapi.json
io.github.unionj-cloud.feign
${project.basedir}/cloud-petStore-feign
io.github.unionj-cloud.vo
${project.basedir}/cloud-petStore-vo
FEIGN
VO
cloud-petStore
petStore.baseUrl
io.github.unionj-cloud
cloud-unionj
1.0.0-SNAPSHOT
```
# OpenAPI3 Web UI Screenshot

# Usage
## Demo project
It's a simple typescript http client code download restful service project. Upload OpenAPI3 spec json file, download ts code.
It's used in our company project.
Repo: https://github.com/unionj-cloud/openapi-svc
Screenshot:

## Recommend project structure
Repo: https://github.com/unionj-cloud/unionj-generator-guide

## DSL
### Schema
#### Example
```java
import static cloud.unionj.generator.OpenAPI3.dsl.Schema.schema;
import static cloud.unionj.generator.OpenAPI3.dsl.SchemaHelper.*;
public class Components {
private static Schema sizeProperty = int32("每页条数,默认10,传-1查出全部数据");
private static Schema currentProperty = int32("当前页,从1开始");
private static Schema offsetProperty = int32("偏移量");
private static Schema sortProperty = string("排序条件字符串:排序字段前使用'-'(降序)和'+'(升序)号表示排序规则,多个排序字段用','隔开",
"+id,-create_at");
private static Schema pageProperty = int32("当前页,从1开始");
private static Schema limitProperty = int32("每页条数,默认10, 传-1查出全部数据", 10);
private static Schema maxPageProperty = int32("导出结束页");
private static Schema totalProperty = int64("总数,入参传入此参数则不再查询count,以此total为准");
private static Schema topStatusProperty = int32("需要排在前的状态");
public static Schema PageResultVO = schema(sb -> {
// Schema type. Required.
sb.type("object");
// Schema title. Required. Otherwise the generator tool won't know it.
sb.title("PageResultVO");
// Generic as List
sb.properties("items", ListT);
sb.properties("total", totalProperty);
sb.properties("size", sizeProperty);
sb.properties("current", currentProperty);
sb.properties("searchCount", bool);
sb.properties("pages", int32("当前分页总页数"));
sb.properties("offset", offsetProperty);
});
public static Schema RankVO = schema(sb -> {
sb.type("object");
sb.title("RankVO");
sb.description("排行榜");
sb.properties("serialNo", int32);
sb.properties("name", string);
sb.properties("income", doubleNumer("累计收入"));
sb.properties("quantity", int32("完成任务数量"));
});
public static Schema PageResultVOJobVO = generic(gb -> {
gb.generic(PageResultVO, ref(RankVO.getTitle()));
});
}
```
#### SchemaHelper
There are some built-in schemas in cloud.unionj.generator.OpenAPI3.dsl.SchemaHelper.
| Type | Java |
| ------------- | -------------------- |
| int32 | Integer |
| int64 | Long |
| string | String |
| bool | Boolean |
| floatNumber | Float |
| doubleNumer | Double |
| dateTime | java.util.Date |
| T | |
| ListT | List |
| SetT | Set |
| stringArray | List |
| int32Array | List |
| int64Array | List |
| floatArray | List |
| doubleArray | List |
| boolArray | List |
| dateTimeArray | List |
| enums | enum |
| ref | Object |
| refArray | List