Skip to content

Commit 52645e1

Browse files
authored
Adjust documentation generation (#2364)
* chore: adjust documentation generation * style: remove redundant comments * docs: 调整文档
1 parent 8c0f241 commit 52645e1

File tree

3,356 files changed

+48746
-52115
lines changed

Some content is hidden

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

3,356 files changed

+48746
-52115
lines changed

gendoc/main.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"go/parser"
6-
"go/token"
75
"os"
86
"path/filepath"
97
"reflect"
@@ -16,6 +14,7 @@ import (
1614
"github.com/fatih/color"
1715
"github.com/hashicorp/hcl/v2/hclwrite"
1816
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
1918
cloud "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud"
2019
)
2120

@@ -28,9 +27,10 @@ const (
2827
)
2928

3029
var (
31-
hclMatch = regexp.MustCompile("(?si)([^`]+)?```(hcl)?(.*?)```")
32-
usageMatch = regexp.MustCompile(`(?s)(?m)^([^ \n].*?)(?:\n{2}|$)(.*)`)
33-
bigSymbol = regexp.MustCompile("([\u007F-\uffff])")
30+
hclMatch = regexp.MustCompile("(?si)([^`]+)?```(hcl)?(.*?)```")
31+
usageMatch = regexp.MustCompile(`(?s)(?m)^([^ \n].*?)(?:\n{2}|$)(.*)`)
32+
bigSymbol = regexp.MustCompile("([\u007F-\uffff])")
33+
productNameRegexp = regexp.MustCompile(`^.*\((.*)\)$`)
3434
)
3535

3636
func main() {
@@ -59,15 +59,16 @@ func main() {
5959

6060
// genIdx generating index for resource
6161
func genIdx(filePath string) (prods []Product) {
62-
filename := "provider.go"
62+
filename := "provider.md"
6363

6464
message("[START]get description from file: %s\n", filename)
6565

66-
description, err := getFileDescription(filepath.Join(filePath, filename))
66+
raw, err := os.ReadFile(filepath.Join(filePath, filename))
6767
if err != nil {
6868
message("[SKIP!]get description failed, skip: %s", err)
6969
return
7070
}
71+
description := string(raw)
7172

7273
description = strings.TrimSpace(description)
7374
if description == "" {
@@ -132,14 +133,24 @@ func genDoc(product, dtype, fpath, name string, resource *schema.Resource) {
132133
"import": "",
133134
}
134135

135-
filename := fmt.Sprintf("%s_%s_%s.go", dtype, cloudMarkShort, data["resource"])
136+
productDir := strings.ToLower(product)
137+
groups := productNameRegexp.FindStringSubmatch(productDir)
138+
if groups != nil {
139+
productDir = groups[1]
140+
}
141+
if productDir == "provider data sources" {
142+
productDir = "common"
143+
}
144+
145+
filename := fmt.Sprintf("%s/%s_%s_%s.md", productDir, dtype, cloudMarkShort, data["resource"])
136146
message("[START]get description from file: %s\n", filename)
137147

138-
description, err := getFileDescription(filepath.Join(fpath, filename))
148+
raw, err := os.ReadFile(filepath.Join(fpath, filename))
139149
if err != nil {
140150
message("[FAIL!]get description failed: %s", err)
141151
os.Exit(1)
142152
}
153+
description := string(raw)
143154

144155
description = strings.TrimSpace(description)
145156
if description == "" {
@@ -334,18 +345,6 @@ func getAttributes(step int, k string, v *schema.Schema) []string {
334345
return attributes
335346
}
336347

337-
// getFileDescription get description from go file
338-
func getFileDescription(fname string) (string, error) {
339-
fset := token.NewFileSet()
340-
341-
parsedAst, err := parser.ParseFile(fset, fname, nil, parser.ParseComments)
342-
if err != nil {
343-
return "", err
344-
}
345-
346-
return parsedAst.Doc.Text(), nil
347-
}
348-
349348
// getSubStruct get sub structure from go file
350349
func getSubStruct(step int, k string, v *schema.Schema) []string {
351350
var subStructs []string
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Use this data source to query detailed information of antiddos basic_device_status
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_antiddos_basic_device_status" "basic_device_status" {
7+
ip_list = [
8+
"127.0.0.1"
9+
]
10+
filter_region = 1
11+
}
12+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Use this data source to query detailed information of antiddos bgp_biz_trend
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_antiddos_bgp_biz_trend" "bgp_biz_trend" {
7+
business = "bgp-multip"
8+
start_time = "2023-11-22 09:25:00"
9+
end_time = "2023-11-22 10:25:00"
10+
metric_name = "intraffic"
11+
instance_id = "bgp-00000ry7"
12+
flag = 0
13+
}
14+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Use this data source to query detailed information of antiddos list_listener
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_antiddos_list_listener" "list_listener" {
7+
}
8+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Use this data source to query detailed information of antiddos overview_attack_trend
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_antiddos_overview_attack_trend" "overview_attack_trend" {
7+
type = "ddos"
8+
dimension = "attackcount"
9+
period = 86400
10+
start_time = "2023-11-21 10:28:31"
11+
end_time = "2023-11-22 10:28:31"
12+
}
13+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Use this data source to query detailed information of apiGateway api_app_api
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_api_gateway_api_app_api" "example" {
7+
service_id = "service-nxz6yync"
8+
api_id = "api-0cvmf4x4"
9+
api_region = "ap-guangzhou"
10+
}
11+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Use this data source to query detailed information of apigateway api_app_services
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_api_gateway_api_app_service" "example" {
7+
service_id = tencentcloud_api_gateway_api.example.service_id
8+
api_region = "ap-guangzhou"
9+
}
10+
11+
resource "tencentcloud_api_gateway_service" "example" {
12+
service_name = "tf_example"
13+
protocol = "http&https"
14+
service_desc = "desc."
15+
net_type = ["INNER", "OUTER"]
16+
ip_version = "IPv4"
17+
}
18+
19+
resource "tencentcloud_api_gateway_api" "example" {
20+
service_id = tencentcloud_api_gateway_service.example.id
21+
api_name = "tf_example"
22+
api_desc = "my hello api update"
23+
auth_type = "APP"
24+
protocol = "HTTP"
25+
enable_cors = true
26+
request_config_path = "/user/info"
27+
request_config_method = "POST"
28+
request_parameters {
29+
name = "email"
30+
position = "QUERY"
31+
type = "string"
32+
desc = "desc."
33+
default_value = "test@qq.com"
34+
required = true
35+
}
36+
service_config_type = "HTTP"
37+
service_config_timeout = 10
38+
service_config_url = "http://www.tencent.com"
39+
service_config_path = "/user"
40+
service_config_method = "POST"
41+
response_type = "XML"
42+
response_success_example = "<note>success</note>"
43+
response_fail_example = "<note>fail</note>"
44+
response_error_codes {
45+
code = 500
46+
msg = "system error"
47+
desc = "system error code"
48+
converted_code = 5000
49+
need_convert = true
50+
}
51+
}
52+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Use this data source to query list information of api_gateway api_app
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_api_gateway_api_apps" "test" {
7+
api_app_id = ["app-rj8t6zx3"]
8+
api_app_name = ["app_test"]
9+
}
10+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Use this data source to query list information of api_gateway api_doc
2+
Example Usage
3+
```hcl
4+
data "tencentcloud_api_gateway_api_docs" "my_api_doc" {
5+
}
6+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Use this data source to query API gateway access keys.
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_api_gateway_api_key" "test" {
7+
secret_name = "my_api_key"
8+
status = "on"
9+
}
10+
11+
data "tencentcloud_api_gateway_api_keys" "name" {
12+
secret_name = tencentcloud_api_gateway_api_key.test.secret_name
13+
}
14+
15+
data "tencentcloud_api_gateway_api_keys" "id" {
16+
api_key_id = tencentcloud_api_gateway_api_key.test.id
17+
}
18+
```

0 commit comments

Comments
 (0)