Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 00dabc6

Browse files
committed
@ignore and @deprecated field detection implemented. @deprecated is unused presently.
1 parent 7fd4bed commit 00dabc6

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

intermediate_map.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type MapIntermediate struct {
1515
ValueType *MemberIntermediate
1616
Description string
1717
Validations Validator
18+
Deprecated bool
1819
}
1920

2021
func (this *MapIntermediate) IsRequired() bool {

intermediate_member.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MemberIntermediate struct {
1818
JsonOmitEmpty bool // If the omitempty flag was given in the JSON.
1919
Description string
2020
Validations Validator
21+
Deprecated bool
2122
}
2223

2324
func (this *MemberIntermediate) IsRequired() bool {

intermediate_slice.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type SliceIntermediate struct {
1414
ValueType *MemberIntermediate
1515
Description string
1616
Validations Validator
17+
Deprecated bool
1718
}
1819

1920
func (this *SliceIntermediate) IsRequired() bool {

walker_definitions.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ func (this *DefinitionVisitor) Visit(node ast.Node) (w ast.Visitor) {
119119
}
120120
case *ast.Field:
121121

122+
controlsDoc := parseOpenApiControls(t.Doc.Text())
123+
controlsComment := parseOpenApiControls(t.Comment.Text())
124+
125+
controls := OpenApiControls{
126+
Ignore: controlsDoc.Ignore || controlsComment.Ignore,
127+
Deprecated: controlsDoc.Deprecated || controlsComment.Deprecated,
128+
}
129+
130+
if controls.Ignore {
131+
return nil
132+
}
133+
122134
if this.Definition == nil {
123135
// Ignore fields that don't belong to our definition.
124136
return nil
@@ -197,6 +209,7 @@ func (this *DefinitionVisitor) Visit(node ast.Node) (w ast.Visitor) {
197209
KeyType: keyType,
198210
Description: desc,
199211
Validations: validations,
212+
Deprecated: controls.Deprecated,
200213
}
201214

202215
} else if isSlice, v := IsSlice(goType); isSlice {
@@ -214,6 +227,7 @@ func (this *DefinitionVisitor) Visit(node ast.Node) (w ast.Visitor) {
214227
ValueType: valueType,
215228
Description: desc,
216229
Validations: validations,
230+
Deprecated: controls.Deprecated,
217231
}
218232
} else {
219233
member = &MemberIntermediate{
@@ -223,6 +237,7 @@ func (this *DefinitionVisitor) Visit(node ast.Node) (w ast.Visitor) {
223237
JsonOmitEmpty: jsonOmitEmpty,
224238
Description: desc,
225239
Validations: validations,
240+
Deprecated: controls.Deprecated,
226241
}
227242
}
228243

@@ -419,3 +434,26 @@ func parseValidateTag(s string) map[string]string {
419434
return validations
420435

421436
}
437+
438+
type OpenApiControls struct {
439+
Ignore bool
440+
Deprecated bool
441+
}
442+
443+
func parseOpenApiControls(s string) OpenApiControls {
444+
445+
var controls OpenApiControls
446+
447+
rxIgnore := regexp.MustCompile(`@(?i:ignore)`)
448+
rxDeprecated := regexp.MustCompile(`@(?i:deprecated)`)
449+
450+
if rxIgnore.MatchString(s) {
451+
controls.Ignore = true
452+
}
453+
454+
if rxDeprecated.MatchString(s) {
455+
controls.Deprecated = true
456+
}
457+
458+
return controls
459+
}

0 commit comments

Comments
 (0)