Skip to content

Commit cfa2be3

Browse files
committed
fix: Remove openAPI docs
1 parent fe4c6b8 commit cfa2be3

File tree

3 files changed

+189
-4793
lines changed

3 files changed

+189
-4793
lines changed

bundle/internal/docs/docs.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,32 @@ type rootProp struct {
3434
topLevel bool
3535
}
3636

37-
func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, a annotationFile) []rootNode {
37+
func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool) []rootNode {
3838
rootProps := []rootProp{}
3939
for k, v := range s.Properties {
4040
rootProps = append(rootProps, rootProp{k, v, true})
4141
}
4242
nodes := make([]rootNode, 0, len(rootProps))
4343

4444
for i := 0; i < len(rootProps); i++ {
45-
k := rootProps[i].k
46-
v := rootProps[i].v
45+
item := rootProps[i]
46+
k := item.k
47+
v := item.v
4748
v = resolveRefs(v, refs)
4849
node := rootNode{
4950
Title: k,
50-
Description: getDescription(v),
51-
TopLevel: rootProps[i].topLevel,
51+
Description: getDescription(v, item.topLevel),
52+
TopLevel: item.topLevel,
5253
}
5354

5455
node.Attributes = getAttributes(v.Properties, refs)
55-
rootProps = append(rootProps, extractNodes(k, v.Properties, refs, a)...)
56+
rootProps = append(rootProps, extractNodes(k, v.Properties, refs, customFields)...)
5657

5758
additionalProps, ok := v.AdditionalProperties.(*jsonschema.Schema)
5859
if ok {
5960
objectKeyType := resolveRefs(additionalProps, refs)
6061
node.ObjectKeyAttributes = getAttributes(objectKeyType.Properties, refs)
61-
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, a)...)
62+
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, customFields)...)
6263
}
6364

6465
if v.Items != nil {
@@ -181,7 +182,7 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
181182
attributes = append(attributes, attributeNode{
182183
Title: k,
183184
Type: typeString,
184-
Description: getDescription(v),
185+
Description: getDescription(v, true),
185186
})
186187
}
187188
sort.Slice(attributes, func(i, j int) bool {
@@ -190,8 +191,8 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
190191
return attributes
191192
}
192193

193-
func getDescription(s *jsonschema.Schema) string {
194-
if s.MarkdownDescription != "" {
194+
func getDescription(s *jsonschema.Schema, allowMarkdown bool) string {
195+
if allowMarkdown && s.MarkdownDescription != "" {
195196
return s.MarkdownDescription
196197
}
197198
return s.Description
@@ -226,14 +227,22 @@ func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *js
226227
return node
227228
}
228229

229-
func extractNodes(prefix string, props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, a annotationFile) []rootProp {
230+
func shouldExtract(ref string, customFields map[string]bool) bool {
231+
refKey := strings.TrimPrefix(ref, "#/$defs/")
232+
_, isCustomField := customFields[refKey]
233+
return isCustomField
234+
}
235+
236+
func extractNodes(prefix string, props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool) []rootProp {
230237
nodes := []rootProp{}
231238
for k, v := range props {
239+
if !shouldExtract(*v.Reference, customFields) {
240+
continue
241+
}
232242
v = resolveRefs(v, refs)
233243
if v.Type == "object" {
234244
nodes = append(nodes, rootProp{prefix + "." + k, v, false})
235245
}
236-
v.MarkdownDescription = ""
237246
}
238247
return nodes
239248
}

0 commit comments

Comments
 (0)