-
Notifications
You must be signed in to change notification settings - Fork 28
/
deprecated.go
54 lines (48 loc) · 1.32 KB
/
deprecated.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package openapi3edit
import (
"regexp"
oas3 "github.com/getkin/kin-openapi/openapi3"
"github.com/grokify/spectrum/openapi3"
)
func SpecSchemasSetDeprecated(spec *openapi3.Spec, newDeprecated bool) {
for _, schemaRef := range spec.Components.Schemas {
if len(schemaRef.Ref) == 0 && schemaRef.Value != nil {
schemaRef.Value.Deprecated = newDeprecated
}
}
}
func SpecOperationsSetDeprecated(spec *openapi3.Spec, newDeprecated bool) {
openapi3.VisitOperations(
spec,
func(path, method string, op *oas3.Operation) {
if op != nil {
op.Deprecated = newDeprecated
}
},
)
}
var rxDeprecated = regexp.MustCompile(`(?i)\bdeprecated\b`)
func SpecSetDeprecatedImplicit(spec *openapi3.Spec) {
openapi3.VisitOperations(
spec,
func(path, method string, op *oas3.Operation) {
if op != nil && rxDeprecated.MatchString(op.Description) {
op.Deprecated = true
}
},
)
for _, schemaRef := range spec.Components.Schemas {
if len(schemaRef.Ref) == 0 && schemaRef.Value != nil {
if rxDeprecated.MatchString(schemaRef.Value.Description) {
schemaRef.Value.Deprecated = true
}
for _, propRef := range schemaRef.Value.Properties {
if len(propRef.Ref) == 0 && propRef.Value != nil {
if rxDeprecated.MatchString(propRef.Value.Description) {
propRef.Value.Deprecated = true
}
}
}
}
}
}