|
1 | 1 | // |
2 | 2 | // DISCLAIMER |
3 | 3 | // |
4 | | -// Copyright 2023 ArangoDB GmbH, Cologne, Germany |
| 4 | +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany |
5 | 5 | // |
6 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | // you may not use this file except in compliance with the License. |
@@ -35,6 +35,7 @@ import ( |
35 | 35 | openapi "k8s.io/kube-openapi/pkg/common" |
36 | 36 |
|
37 | 37 | "github.com/arangodb/kube-arangodb/pkg/util" |
| 38 | + "github.com/arangodb/kube-arangodb/pkg/util/errors" |
38 | 39 | ) |
39 | 40 |
|
40 | 41 | const ( |
@@ -73,10 +74,13 @@ func parseDocDefinition(t *testing.T, root, path, typ string, field *ast.Field, |
73 | 74 | def.Important = util.NewType[string](important[0]) |
74 | 75 | } |
75 | 76 |
|
76 | | - if docs, ok := extractNotTags(field); !ok { |
| 77 | + if docs, dep, ok, err := extractNotTags(field); err != nil { |
| 78 | + require.Fail(t, fmt.Sprintf("Error while getting tags for %s: %s", path, err.Error())) |
| 79 | + } else if !ok { |
77 | 80 | println(def.Path, " is missing documentation!") |
78 | 81 | } else { |
79 | 82 | def.Docs = docs |
| 83 | + def.Deprecated = dep |
80 | 84 | } |
81 | 85 |
|
82 | 86 | file := fs.File(field.Pos()) |
@@ -246,22 +250,40 @@ func extract(n *ast.Field, tag string) ([]string, bool) { |
246 | 250 | return ret, len(ret) > 0 |
247 | 251 | } |
248 | 252 |
|
249 | | -func extractNotTags(n *ast.Field) ([]string, bool) { |
| 253 | +func extractNotTags(n *ast.Field) ([]string, []string, bool, error) { |
250 | 254 | if n.Doc == nil { |
251 | | - return nil, false |
| 255 | + return nil, nil, false, nil |
252 | 256 | } |
253 | 257 |
|
254 | | - var ret []string |
| 258 | + var ret, dep []string |
| 259 | + |
| 260 | + var deprecated bool |
255 | 261 |
|
256 | 262 | for _, c := range n.Doc.List { |
257 | 263 | if strings.HasPrefix(c.Text, "// ") { |
| 264 | + if strings.HasPrefix(c.Text, "// Deprecated") { |
| 265 | + if !strings.HasPrefix(c.Text, "// Deprecated: ") { |
| 266 | + return nil, nil, false, errors.Errorf("Invalid deprecated field") |
| 267 | + } |
| 268 | + } |
| 269 | + if strings.HasPrefix(c.Text, "// Deprecated:") { |
| 270 | + deprecated = true |
| 271 | + dep = append(dep, strings.TrimSpace(strings.TrimPrefix(c.Text, "// Deprecated:"))) |
| 272 | + continue |
| 273 | + } |
| 274 | + |
258 | 275 | if !strings.HasPrefix(c.Text, "// +doc/") { |
259 | | - ret = append(ret, strings.TrimPrefix(c.Text, "// ")) |
| 276 | + v := strings.TrimSpace(strings.TrimPrefix(c.Text, "// ")) |
| 277 | + if deprecated { |
| 278 | + dep = append(dep, v) |
| 279 | + } else { |
| 280 | + ret = append(ret, v) |
| 281 | + } |
260 | 282 | } |
261 | 283 | } |
262 | 284 | } |
263 | 285 |
|
264 | | - return ret, len(ret) > 0 |
| 286 | + return ret, dep, len(ret) > 0 || len(dep) > 0, nil |
265 | 287 | } |
266 | 288 |
|
267 | 289 | // isSimpleType returns the OpenAPI-compatible type name, type format and boolean indicating if this is simple type or not |
|
0 commit comments