Skip to content

Commit e0d87fe

Browse files
authored
Hide deprecated fields in docsgen (#2581)
## Changes If field is deprecated * Show deprecation message in the attributes table * Do not show extended section of that field ## Why We do have deprecated fields and we don't want to show them in documentation. If deprecated field belongs to some complex type (e.g. `pydabs` or `compute_id`) we show explicit deprecation message ## Tests Unit test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent e490e07 commit e0d87fe

File tree

6 files changed

+117
-898
lines changed

6 files changed

+117
-898
lines changed

bundle/docsgen/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) {
133133
if a.MarkdownExamples != "" {
134134
s.Examples = []string{a.MarkdownExamples}
135135
}
136+
if a.DeprecationMessage != "" {
137+
s.Deprecated = true
138+
s.DeprecationMessage = a.DeprecationMessage
139+
}
136140
}
137141

138142
func fillTemplateVariables(s string) string {

bundle/docsgen/nodes.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func buildNodes(s jsonschema.Schema, refs map[string]*jsonschema.Schema, ownFiel
6262
}
6363
visited[k] = true
6464

65+
if v.Deprecated {
66+
continue
67+
}
68+
6569
v = resolveRefs(v, refs)
6670
node := rootNode{
6771
Title: k,
@@ -173,7 +177,7 @@ func getAttributes(props, refs map[string]*jsonschema.Schema, ownFields map[stri
173177
typeString = "Any"
174178
}
175179
var reference string
176-
if isReferenceType(v, refs, ownFields) && !circular {
180+
if isReferenceType(v, refs, ownFields) && !circular && !v.Deprecated {
177181
reference = prefix + "." + k
178182
}
179183
attributes = append(attributes, attributeNode{
@@ -190,6 +194,9 @@ func getAttributes(props, refs map[string]*jsonschema.Schema, ownFields map[stri
190194
}
191195

192196
func getDescription(s *jsonschema.Schema) string {
197+
if s.DeprecationMessage != "" {
198+
return s.DeprecationMessage
199+
}
193200
if s.MarkdownDescription != "" {
194201
return s.MarkdownDescription
195202
}

bundle/docsgen/nodes_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ func TestBuildNodes_ChildExpansion(t *testing.T) {
115115
}
116116
}
117117

118+
func TestDeprecatedFields(t *testing.T) {
119+
s := jsonschema.Schema{
120+
Type: "object",
121+
Properties: map[string]*jsonschema.Schema{
122+
"deprecatedField": {Deprecated: true},
123+
"notDeprecatedField": {
124+
Properties: map[string]*jsonschema.Schema{
125+
"nestedDeprecatedField": {
126+
Deprecated: true,
127+
Description: "nested description",
128+
Extension: jsonschema.Extension{
129+
DeprecationMessage: "nested deprecation message",
130+
},
131+
},
132+
"nestedNotDeprecatedField": {},
133+
},
134+
},
135+
},
136+
}
137+
nodes := buildNodes(s, nil, nil)
138+
assert.Len(t, nodes, 1)
139+
assert.Equal(t, "notDeprecatedField", nodes[0].Title)
140+
141+
assert.Len(t, nodes[0].Attributes, 2)
142+
assert.Equal(t, "nested deprecation message", nodes[0].Attributes[0].Description)
143+
}
144+
118145
func strPtr(s string) *string {
119146
return &s
120147
}

0 commit comments

Comments
 (0)