Skip to content

Commit d2cfdcb

Browse files
authored
Mark output-only fields with doNotSuggest (#3599)
## Changes 1. Mark output-only fields with `doNotSuggest: true` to exclude them from autocompletion 2. Remove output-only fields from docs ## Why Currently, we suggest all fields in code-completion, but fields marked in the OpenAPI spec as output-only are not used by the CLI ## Tests Added 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 a6398a3 commit d2cfdcb

File tree

12 files changed

+2104
-1082
lines changed

12 files changed

+2104
-1082
lines changed

bundle/docsgen/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) {
141141
s.DoNotSuggest = true
142142
s.Preview = a.Preview
143143
}
144+
if a.OutputOnly != nil && *a.OutputOnly {
145+
s.DoNotSuggest = true
146+
}
144147
}
145148

146149
func fillTemplateVariables(s string) string {

bundle/docsgen/nodes.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ func buildNodes(s jsonschema.Schema, refs map[string]*jsonschema.Schema, ownFiel
6161
continue
6262
}
6363
visited[k] = true
64+
v = resolveRefs(v, refs)
6465

6566
if v.Deprecated {
6667
continue
6768
}
69+
if v.DoNotSuggest {
70+
continue
71+
}
6872

69-
v = resolveRefs(v, refs)
7073
node := rootNode{
7174
Title: k,
7275
Description: getDescription(v),
@@ -172,6 +175,9 @@ func getAttributes(props, refs map[string]*jsonschema.Schema, ownFields map[stri
172175
var attributes []attributeNode
173176
for k, v := range props {
174177
v = resolveRefs(v, refs)
178+
if v.DoNotSuggest {
179+
continue
180+
}
175181
typeString := getHumanReadableType(v.Type)
176182
if typeString == "" {
177183
typeString = "Any"

bundle/docsgen/nodes_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,35 @@ func TestDeprecatedFields(t *testing.T) {
142142
assert.Equal(t, "nested deprecation message", nodes[0].Attributes[0].Description)
143143
}
144144

145+
func TestDoNotSuggestFields(t *testing.T) {
146+
s := jsonschema.Schema{
147+
Type: "object",
148+
Properties: map[string]*jsonschema.Schema{
149+
"doNotSuggestField": {Extension: jsonschema.Extension{DoNotSuggest: true}},
150+
"notDoNotSuggestField": {
151+
Properties: map[string]*jsonschema.Schema{
152+
"nestedDoNotSuggestField": {
153+
Description: "nested description",
154+
Extension: jsonschema.Extension{
155+
DeprecationMessage: "nested do message",
156+
DoNotSuggest: true,
157+
},
158+
},
159+
"nestedNotDoNotSuggestField": {
160+
Description: "nested suggested field",
161+
},
162+
},
163+
},
164+
},
165+
}
166+
nodes := buildNodes(s, nil, nil)
167+
assert.Len(t, nodes, 1)
168+
assert.Equal(t, "notDoNotSuggestField", nodes[0].Title)
169+
170+
assert.Len(t, nodes[0].Attributes, 1)
171+
assert.Equal(t, "nestedNotDoNotSuggestField", nodes[0].Attributes[0].Title)
172+
}
173+
145174
func strPtr(s string) *string {
146175
return &s
147176
}

0 commit comments

Comments
 (0)