@@ -4,13 +4,16 @@ This is a tool that generates API call code in various programming languages bas
44
55根据openapi (swagger) 文档生成不同编程语言客户端接口代码
66
7- | Ts | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_ts.jpg ) |
8- | ------ | ------------------------------------------------------------ |
9- | Java | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_java.jpg ) |
10- | Go | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_go.jpg ) |
11- | Swift | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_swift.jpg ) |
12- | Python | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_python.jpg ) |
13- | Kotlin | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_kotlin.jpg ) |
7+ | Language | 参考 |
8+ | ------------| -------------------------------------------------------------------------------------------|
9+ | Java | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_java.jpg ) |
10+ | Typescript | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_ts.jpg ) |
11+ | Go | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_go.jpg ) |
12+ | Swift | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_swift.jpg ) |
13+ | Python | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_python.jpg ) |
14+ | Kotlin | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_kotlin.jpg ) |
15+ | C# | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_cs.jpg ) |
16+ | Rust | ![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/api_rs.jpg ) |
1417
1518![ image] ( https://github.com/otk-final/openapi-codegen/blob/master/_images/home_api.png )
1619
@@ -19,7 +22,7 @@ This is a tool that generates API call code in various programming languages bas
1922## Feature
2023
2124- 支持` v2 ` /` v3 ` 文档格式
22- - 支持语言:` ts ` ,` swift ` ,` kotlin ` ,` java ` ,` python ` ,` go `
25+ - 支持语言:` ts ` ,` swift ` ,` kotlin ` ,` java ` ,` python ` ,` go ` , ` rust ` , ` c# `
2326- *** 支持泛型***
2427- 支持自定义模版
2528
@@ -31,11 +34,11 @@ This is a tool that generates API call code in various programming languages bas
3134go build -o openapi
3235```
3336
34- ## Download - 1.0.1
37+ ## Download - 1.0.2
3538
36- - [ mac] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1 /openapi_darwin.zip )
37- - [ windows] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1 /openapi_windows.zip )
38- - [ linux] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1 /openapi_linux.zip )
39+ - [ mac] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.2 /openapi_darwin.zip )
40+ - [ windows] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.2 /openapi_windows.zip )
41+ - [ linux] ( https://github.com/otk-final/openapi-codegen/releases/download/v1.0.2 /openapi_linux.zip )
3942
4043安装并添加到环境变量
4144
@@ -52,24 +55,21 @@ Usage:
5255 start [flags]
5356
5457Flags:
55- -c, --client_output string client output file
5658 -e, --endpoint string example:https://{server}:{port}/v3/api-docs
5759 -h, --help help for start
58- -l, --lang string kotlin,python,ts,typescript,swift,java,go,golang
59- -o, --output string api output file
60- -s, --style string customize template file
60+ -l, --lang string kotlin,python,ts,typescript,swift,java,go,golang,rust,cs(c#)
6161 -v, --version string openapi version (default " v3" )
6262
6363```
6464
6565例子
6666
6767``` shell
68- openapi -l ts -o src/api.ts -c src/client.ts - v v3 -e http://localhost:8080/v3/api_docs
68+ openapi -l ts -v v3 -e http://localhost:8080/v3/api_docs
6969```
7070
7171```
72- openapi -l kotlin -o src/api.kt -c src/client.kt - v v2 -e http://localhost:8080/v2/api_docs
72+ openapi -l kotlin -v v2 -e http://localhost:8080/v2/api_docs
7373```
7474
7575
@@ -80,7 +80,8 @@ openapi -l kotlin -o src/api.kt -c src/client.kt -v v2 -e http://localhost:8080
8080openapi init
8181```
8282
83- 在当前目录下生成` openapi.json ` 配置文件
83+ 在当前目录下生成[ openapi.json] ( https://github.com/otk-final/openapi-codegen/openapi.json ) 配置文件
84+
8485
8586### reload
8687
@@ -95,8 +96,8 @@ openapi reload -f /app/openapi.json
9596根据` openapi.json ` 配置文件重新生成接口代码,默认全部
9697
9798``` shell
98- # 指定env
99- openapi reload -f /app/openapi.json -n server_name
99+ # 指定name 或者 language
100+ openapi reload -f /app/openapi.json -n ts
100101```
101102
102103
@@ -108,16 +109,38 @@ openapi reload -f /app/openapi.json -n server_name
108109 " name:" server_name",
109110 //openapi 文档地址
110111 "endpoint" : " http://localhost:8083/v3/api-docs" ,
111- //api文件路径
112- "output" : " src/api.ts" ,
113- //client文件路径
114- "client_output" : " src/client.ts" ,
115112 //目标语言
116113 "lang" : " ts" ,
117- //自定义模版路径
118- "style" : " custom.tmpl" ,
119114 //openapi 版本
120115 "version" : " v3" ,
116+ //输出文件 - 可自定义,系统仅内置(api,model,client)
117+ "output" : {
118+ // api 模版
119+ "api" : {
120+ //输出文件 文件头
121+ "header" : [
122+ " package demo.api;" ,
123+ " " ,
124+ " import demo.model.*;" ,
125+ " import demo.ApiClient;"
126+ ],
127+ //自定义模版路径
128+ "template" : " custom.tmpl" ,
129+ //输出文件路径
130+ "file" : " src/main/java/demo/api/{api}.java" ,
131+ // 自定义变量 - 继承全局变量
132+ "variables" : {
133+ "k1" : " k2"
134+ }
135+ },
136+ // api 模版
137+ "client" : {
138+ "file" : " src/main/java/demo/ApiClient.java"
139+ },
140+ "model" : {
141+ "file" : " src/main/java/demo/model/{model}.java"
142+ }
143+ },
121144 //忽略路径
122145 "ignore" : [" /error" ," /v3/" ],
123146 //匹配路径
@@ -129,7 +152,7 @@ openapi reload -f /app/openapi.json -n server_name
129152 "JsonNode" :" any"
130153 },
131154 //结构体别名
132- "modes " : {
155+ "models " : {
133156 "User" :" People"
134157 },
135158 //类型别名
@@ -144,11 +167,9 @@ openapi reload -f /app/openapi.json -n server_name
144167 "export" : " output"
145168 }
146169 },
147- //模版文件变量
170+ //模版全局变量
148171 "variables" : {
149- "apiPackage" : " com.demo.api" ,
150- "structPackage" : " com.demo.dto" ,
151- "clientPackage" : " com.demo"
172+ "name" : " value"
152173 },
153174 //泛型
154175 "generics" : {
@@ -194,6 +215,7 @@ openapi reload -f /app/openapi.json -n server_name
194215
195216> [ openapi-server] ( https://github.com/otk-final/openapi-server )
196217
218+
197219#### client端
198220
199221> [ ts] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/ts )
@@ -206,4 +228,8 @@ openapi reload -f /app/openapi.json -n server_name
206228>
207229> [ swift] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/swift )
208230>
209- > [ python] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/python )
231+ > [ python] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/python )
232+ >
233+ > [ c#] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/cs )
234+ >
235+ > [ rust] ( https://github.com/otk-final/openapi-codegen/tree/master/_example/rust )
0 commit comments