Skip to content

Commit 08e353f

Browse files
authored
Code Generator (#610)
1 parent 1b7ecc5 commit 08e353f

File tree

189 files changed

+17737
-988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+17737
-988
lines changed

CHANGELOG.md

+119-21
Large diffs are not rendered by default.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Qiniu Resource Storage SDK for Java
2+
23
[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)
34
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
45
[![Build Status](https://travis-ci.org/qiniu/java-sdk.svg)](https://travis-ci.org/qiniu/java-sdk)
56
[![GitHub release](https://img.shields.io/github/v/tag/qiniu/java-sdk.svg?label=release)](https://github.com/qiniu/java-sdk/releases)
67
[![Docs](https://img.shields.io/github/v/tag/qiniu/java-sdk.svg?label=docs&color=yellow)](https://qiniu.github.io/java-sdk/)
78
[![Coverage Status](https://codecov.io/gh/qiniu/java-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/qiniu/java-sdk)
89
[![Latest Stable Version](https://img.shields.io/maven-central/v/com.qiniu/qiniu-java-sdk.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.qiniu%22%20AND%20a%3A%22qiniu-java-sdk%22)
10+
911
## 安装
1012

1113
下载 [the latest JAR][1] 或者 通过 Maven:
14+
1215
```xml
1316
<dependency>
1417
<groupId>com.qiniu</groupId>
1518
<artifactId>qiniu-java-sdk</artifactId>
1619
<version>[7.16.0, 7.16.99]</version>
1720
</dependency>
1821
```
22+
1923
或者 Gradle:
24+
2025
```groovy
2126
implementation 'com.qiniu:qiniu-java-sdk:7.16.+'
2227
```
@@ -28,6 +33,7 @@ JDK 7 及以上
2833
## 使用方法
2934

3035
### 上传
36+
3137
```Java
3238
// 分片上传 v1
3339
import com.qiniu.storage.UploadManager;
@@ -73,6 +79,7 @@ $ ./gradlew build
7379
```
7480

7581
## 生成Eclipse工程文件
82+
7683
``` bash
7784
$ ./gradlew gen_eclipse
7885
```
@@ -105,6 +112,9 @@ $ ./gradlew gen_eclipse
105112
The MIT License (MIT).详情见 [License文件](https://github.com/qiniu/java-sdk/blob/master/LICENSE).
106113

107114
[1]: https://search.maven.org/remote_content?g=com.qiniu&a=qiniu-java-sdk&v=LATEST
115+
108116
[2]: https://github.com/Nextpeer/okhttp
117+
109118
[3]: https://raw.githubusercontent.com/qiniu/java-sdk/master/libs/okhttp-2.3.0-SNAPSHOT.jar
119+
110120
[4]: https://raw.githubusercontent.com/qiniu/java-sdk/master/libs/okio-1.3.0-SNAPSHOT.jar

build.gradle

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ task getHomeDir {
5151
apply plugin: 'checkstyle'
5252

5353
task apiJavadocs(type: Javadoc) {
54-
source = sourceSets.main.allJava
55-
classpath = sourceSets.main.runtimeClasspath
56-
title = "七牛 Java SDK API 文档"
57-
options {
58-
memberLevel = JavadocMemberLevel.PUBLIC
59-
setEncoding 'UTF-8'
60-
setWindowTitle "七牛 Java SDK API 文档"
61-
}
54+
source = sourceSets.main.allJava
55+
classpath = sourceSets.main.runtimeClasspath
56+
title = "七牛 Java SDK API 文档"
57+
options {
58+
memberLevel = JavadocMemberLevel.PUBLIC
59+
setEncoding 'UTF-8'
60+
setWindowTitle "七牛 Java SDK API 文档"
61+
}
6262
}
6363

6464
def versionName() {

code-gen/go.mod

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/YangSen-qn/code-gen
2+
3+
require (
4+
github.com/getkin/kin-openapi v0.124.0
5+
github.com/iancoleman/strcase v0.3.0
6+
gopkg.in/yaml.v3 v3.0.1
7+
)
8+
9+
require (
10+
github.com/go-openapi/jsonpointer v0.20.2 // indirect
11+
github.com/go-openapi/swag v0.22.8 // indirect
12+
github.com/invopop/yaml v0.2.0 // indirect
13+
github.com/josharian/intern v1.0.0 // indirect
14+
github.com/mailru/easyjson v0.7.7 // indirect
15+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
16+
github.com/perimeterx/marshmallow v1.1.5 // indirect
17+
)
18+
19+
go 1.21.8

code-gen/src/api_desc.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package main

code-gen/src/apidesc/api.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package apidesc
2+
3+
type ApiDetailedDescription struct {
4+
Documentation string `yaml:"documentation,omitempty"` // API 文档
5+
PackageName string `yaml:"package_name,omitempty"` // 包名,文件路径中提取
6+
Name string `yaml:"name,omitempty"` // API 名称,文件名
7+
CamelCaseName string `yaml:"camel_case_name,omitempty"` // 驼峰命名
8+
SnakeCaseName string `yaml:"snake_case_name,omitempty"` // 蛇形命名:特指下划线命名
9+
Method MethodName `yaml:"method,omitempty"` // HTTP 方法
10+
ServiceNames []ServiceName `yaml:"service_names,omitempty"` // 七牛服务名称
11+
Command string `yaml:"command,omitempty"` // URL 查询命令
12+
BasePath string `yaml:"base_path,omitempty"` // URL 基础路径
13+
PathSuffix string `yaml:"path_suffix,omitempty"` // URL 路径后缀
14+
Request ApiRequestDescription `yaml:"request,omitempty"` // 请求参数
15+
Response ApiResponseDescription `yaml:"response,omitempty"` // 响应参数
16+
}

code-gen/src/apidesc/body_json.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package apidesc
2+
3+
import (
4+
"fmt"
5+
6+
"gopkg.in/yaml.v3"
7+
)
8+
9+
type (
10+
JsonType struct {
11+
String bool `yaml:"string,omitempty"` // 字符串
12+
Integer bool `yaml:"integer,omitempty"` // 整型数字
13+
Float bool `yaml:"float,omitempty"` // 浮点型数字
14+
Boolean bool `yaml:"boolean,omitempty"` // 布尔值
15+
Array *JsonArray `yaml:"array,omitempty"` // 数组
16+
Struct *JsonStruct `yaml:"struct,omitempty"` // 结构体
17+
Any bool `yaml:"any,omitempty"` // 任意数据结构
18+
StringMap bool `yaml:"string_map,omitempty"` // 任意字符串映射结构
19+
}
20+
21+
JsonArray struct {
22+
Documentation string `yaml:"documentation,omitempty"` // JSON 数组参数文档
23+
Name string `yaml:"name,omitempty"` // JSON 数组名称
24+
CamelCaseName string `yaml:"camel_case_name,omitempty"` // JSON 数组驼峰命名
25+
SnakeCaseName string `yaml:"snake_case_name,omitempty"` // JSON 数组下划线命名
26+
Type *JsonType `yaml:"type,omitempty"` // JSON 数组类型
27+
}
28+
29+
JsonStruct struct {
30+
Documentation string `yaml:"documentation,omitempty"` // JSON 结构体参数文档
31+
Name string `yaml:"name,omitempty"` // JSON 结构体名称
32+
CamelCaseName string `yaml:"camel_case_name,omitempty"` // JSON 结构体驼峰命名
33+
SnakeCaseName string `yaml:"snake_case_name,omitempty"` // JSON 结构体下划线命名
34+
Fields []JsonField `yaml:"fields,omitempty"` // JSON 字段列表
35+
}
36+
37+
JsonField struct {
38+
Documentation string `yaml:"documentation,omitempty"` // JSON 字段参数文档
39+
Key string `yaml:"key,omitempty"` // JSON 字段参数名称
40+
FieldName string `yaml:"field_name,omitempty"` // JSON 字段名称
41+
FieldCamelCaseName string `yaml:"field_camel_case_name,omitempty"` // JSON 字段驼峰命名
42+
FieldSnakeCaseName string `yaml:"field_snake_case_name,omitempty"` // JSON 字段下划线命名
43+
Type JsonType `yaml:"type,omitempty"` // JSON 字段类型
44+
Optional *OptionalType `yaml:"optional,omitempty"` // JSON 字段是否可选,如果为空,则表示必填
45+
ServiceBucket *ServiceBucketType `yaml:"service_bucket,omitempty"` // JSON 字段是否是空间名称,如果为空,则表示不是,如果不为空,则填写格式
46+
ServiceObject *ServiceObjectType `yaml:"service_object,omitempty"` // JSON 字段是否是对象名称,如果为空,则表示不是,如果不为空,则填写格式
47+
}
48+
)
49+
50+
func (jsonType *JsonType) UnmarshalYAML(value *yaml.Node) error {
51+
switch value.ShortTag() {
52+
case "!!str":
53+
switch value.Value {
54+
case "string":
55+
jsonType.String = true
56+
case "integer":
57+
jsonType.Integer = true
58+
case "float":
59+
jsonType.Float = true
60+
case "boolean":
61+
jsonType.Boolean = true
62+
case "any":
63+
jsonType.Any = true
64+
case "string_map":
65+
jsonType.StringMap = true
66+
default:
67+
return fmt.Errorf("unknown json type: %s", value.Value)
68+
}
69+
return nil
70+
case "!!map":
71+
switch value.Content[0].Value {
72+
case "array":
73+
return value.Content[1].Decode(&jsonType.Array)
74+
case "struct":
75+
return value.Content[1].Decode(&jsonType.Struct)
76+
default:
77+
return fmt.Errorf("unknown json type: %s", value.Content[0].Value)
78+
}
79+
default:
80+
return fmt.Errorf("unknown json type: %s", value.ShortTag())
81+
}
82+
}

code-gen/src/apidesc/consts.go

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package apidesc
2+
3+
import (
4+
"net/http"
5+
)
6+
7+
type MethodName string
8+
9+
const (
10+
MethodNameGET MethodName = http.MethodGet
11+
MethodNamePOST MethodName = http.MethodPost
12+
MethodNamePUT MethodName = http.MethodPut
13+
MethodNameDELETE MethodName = http.MethodDelete
14+
)
15+
16+
type ServiceName string
17+
18+
const (
19+
ServiceNameUp ServiceName = "up"
20+
ServiceNameIo ServiceName = "io"
21+
ServiceNameRs ServiceName = "rs"
22+
ServiceNameRsf ServiceName = "rsf"
23+
ServiceNameApi ServiceName = "api"
24+
ServiceNameBucket ServiceName = "uc"
25+
)
26+
27+
// StringLikeType 类字符串参数类型
28+
type StringLikeType = string
29+
30+
const (
31+
StringLikeTypeString StringLikeType = "string" // 字符串
32+
StringLikeTypeInteger StringLikeType = "integer" // 整型数字
33+
StringLikeTypeFloat StringLikeType = "float" // 浮点型数字
34+
StringLikeTypeBoolean StringLikeType = "boolean" // 布尔值
35+
)
36+
37+
type MultipartFormDataType = string
38+
39+
const (
40+
MultipartFormDataTypeString MultipartFormDataType = "string" // 字符串
41+
MultipartFormDataTypeInteger MultipartFormDataType = "integer"
42+
MultipartFormDataTypeUploadToken MultipartFormDataType = "upload_token"
43+
MultipartFormDataTypeBinaryData MultipartFormDataType = "binary_data"
44+
)
45+
46+
type OptionalType string
47+
48+
const (
49+
OptionalTypeRequired OptionalType = "" // 用户必须传值
50+
OptionalTypeOmitEmpty OptionalType = "omitempty" // 如果用户不传值,则该字段省略
51+
OptionalTypeKeepEmpty OptionalType = "keepempty" // 即使用户不传值,也会发送空值
52+
OptionalTypeNullable OptionalType = "nullable" // 如果用户不传值,则该字段省略,但如果用户传值,即使是空值也会发送
53+
)
54+
55+
type Authorization string
56+
57+
const (
58+
AuthorizationNone Authorization = ""
59+
AuthorizationQbox Authorization = "Qbox"
60+
AuthorizationQiniu Authorization = "qiniu"
61+
AuthorizationUpToken Authorization = "UploadToken"
62+
)
63+
64+
type Idempotent string
65+
66+
const (
67+
IdempotentDefault Idempotent = "default" // 默认幂等性(根据 HTTP 方法判定)
68+
IdempotentAlways Idempotent = "always" // 总是幂等
69+
IdempotentNever Idempotent = "never" // 总是不幂等
70+
)
71+
72+
type EncodeType string
73+
74+
const (
75+
EncodeTypeNone EncodeType = "none"
76+
EncodeTypeUrlSafeBase64 EncodeType = "url_safe_base64" // 需要进行编码
77+
EncodeTypeUrlSafeBase64OrNone EncodeType = "url_safe_base64_or_none" // 不仅需要编码,即使路径参数的值是 None 也要编码。该选项暗示了 nullable
78+
)
79+
80+
type ServiceBucketType string
81+
82+
const (
83+
ServiceBucketTypeNone ServiceBucketType = "" //
84+
ServiceBucketTypePlainText ServiceBucketType = "plain_text" // 该值为存储空间名称
85+
ServiceBucketTypeEntry ServiceBucketType = "entry" // 该值格式为 UrlSafeBase64("$bucket:$key")
86+
ServiceBucketTypeUploadToken ServiceBucketType = "upload_token" // 该值为上传凭证,内部包含存储空间信息
87+
)
88+
89+
type ServiceObjectType string
90+
91+
const (
92+
ServiceObjectTypeNone ServiceObjectType = "" //
93+
ServiceObjectTypePlainText ServiceObjectType = "plain_text" // 该值为对象名称
94+
ServiceObjectTypeEntry ServiceObjectType = "entry" // 该值格式为 UrlSafeBase64("$bucket:$key")
95+
)

code-gen/src/apidesc/header.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package apidesc
2+
3+
type HeaderName struct {
4+
HeaderName string `yaml:"header_name,omitempty"` // HTTP 头名称
5+
Documentation string `yaml:"documentation,omitempty"` // HTTP 头参数文档
6+
FieldName string `yaml:"field_name,omitempty"` // HTTP 头参数名称
7+
FieldCamelCaseName string `yaml:"field_camel_case_name,omitempty"` // HTTP 头参数驼峰命名
8+
FieldSnakeCaseName string `yaml:"field_snake_case_name,omitempty"` // HTTP 头参数下划线命名
9+
Optional *OptionalType `yaml:"optional,omitempty"` // HTTP 头参数是否可选,如果为空,则表示必填
10+
}
11+
12+
type HeaderNames []HeaderName

code-gen/src/apidesc/request.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package apidesc
2+
3+
import (
4+
"fmt"
5+
6+
"gopkg.in/yaml.v3"
7+
)
8+
9+
type NamedPathParam struct {
10+
Documentation string `yaml:"documentation,omitempty"` // URL 路径参数文档
11+
PathSegment string `yaml:"path_segment,omitempty"` // URL 路径段落,如果为空,则表示参数直接追加在 URL 路径末尾
12+
FieldName string `yaml:"field_name,omitempty"` // URL 路径参数名称
13+
FieldCamelCaseName string `yaml:"field_camel_case_name,omitempty"` // URL 路径参数驼峰命名
14+
FieldSnakeCaseName string `yaml:"field_snake_case_name,omitempty"` // URL 路径参数下划线命名
15+
Type *StringLikeType `yaml:"type,omitempty"` // URL 路径参数类型
16+
Encode *EncodeType `yaml:"encode,omitempty"` // URL 路径参数编码方式,如果为空,表示直接转码成字符串
17+
ServiceBucket *ServiceBucketType `yaml:"service_bucket,omitempty"` // URL 路径参数是否是空间名称,如果为空,则表示不是,如果不为空,则填写格式
18+
ServiceObject *ServiceObjectType `yaml:"service_object,omitempty"` // URL 路径参数是否是对象名称,如果为空,则表示不是,如果不为空,则填写格式
19+
Optional *OptionalType `yaml:"optional,omitempty"` // URL 路径参数是否可选,如果为空,则表示必填
20+
}
21+
22+
type FreePathParams struct {
23+
FieldName string `yaml:"field_name,omitempty"` // URL 路径参数名称
24+
FieldCamelCaseName string `yaml:"field_camel_case_name,omitempty"` // URL 路径参数驼峰命名
25+
FieldSnakeCaseName string `yaml:"field_snake_case_name,omitempty"` // URL 路径参数下划线命名
26+
Documentation string `yaml:"documentation,omitempty"` // URL 路径参数文档
27+
EncodeParamKey *EncodeType `yaml:"encode_param_key"` // URL 路径参数键编码方式,如果为空,表示直接转码成字符串
28+
EncodeParamValue *EncodeType `yaml:"encode_param_value"` // URL 路径参数值编码方式,如果为空,表示直接转码成字符串
29+
}
30+
31+
type PathParams struct {
32+
Named []NamedPathParam `yaml:"named,omitempty"` // URL 路径有名参数列表
33+
Free *FreePathParams `yaml:"free,omitempty"` // URL 路径自由参数列表
34+
}
35+
36+
type RequestBody struct {
37+
Json *JsonType `yaml:"json,omitempty"` // JSON 类型
38+
FormUrlencoded *FormUrlencodedRequestStruct `yaml:"form_urlencoded,omitempty"` // URL 编码表单调用(无法上传二进制数据)
39+
MultipartFormData *MultipartFormFields `yaml:"multipart_form_data,omitempty"` // 复合表单调用(可以上传二进制数据)
40+
BinaryData bool `yaml:"binary_data,omitempty"` // 二进制数据
41+
}
42+
43+
func (body *RequestBody) UnmarshalYAML(value *yaml.Node) error {
44+
switch value.ShortTag() {
45+
case "!!str":
46+
switch value.Value {
47+
case "binary_data":
48+
body.BinaryData = true
49+
default:
50+
return fmt.Errorf("unknown request body type: %s", value.Value)
51+
}
52+
return nil
53+
case "!!map":
54+
switch value.Content[0].Value {
55+
case "json":
56+
return value.Content[1].Decode(&body.Json)
57+
case "form_urlencoded":
58+
return value.Content[1].Decode(&body.FormUrlencoded)
59+
case "multipart_form_data":
60+
return value.Content[1].Decode(&body.MultipartFormData)
61+
default:
62+
return fmt.Errorf("unknown request body type: %s", value.Content[0].Value)
63+
}
64+
default:
65+
return fmt.Errorf("unknown request body type: %s", value.ShortTag())
66+
}
67+
}
68+
69+
type ApiRequestDescription struct {
70+
PathParams *PathParams `yaml:"path_params,omitempty"` // URL 路径参数列表
71+
HeaderNames HeaderNames `yaml:"header_names,omitempty"` // HTTP 头参数列表
72+
QueryNames QueryNames `yaml:"query_names,omitempty"` // URL 查询参数列表
73+
Body *RequestBody `yaml:"body,omitempty"` // 请求体
74+
Authorization *Authorization `yaml:"authorization,omitempty"` // 鉴权参数
75+
Idempotent *Idempotent `yaml:"idempotent,omitempty"` // 幂等性
76+
responseTypeRequired bool `yaml:"response_type_required"` //
77+
}

0 commit comments

Comments
 (0)