fix: Remove openAPI docs

This commit is contained in:
Ilya Kuznetsov 2024-12-18 20:53:38 +01:00
parent fe4c6b8a68
commit cfa2be3c35
No known key found for this signature in database
GPG Key ID: 91F3DDCF5D21CDDF
3 changed files with 30 additions and 4634 deletions

View File

@ -34,7 +34,7 @@ type rootProp struct {
topLevel bool
}
func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, a annotationFile) []rootNode {
func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool) []rootNode {
rootProps := []rootProp{}
for k, v := range s.Properties {
rootProps = append(rootProps, rootProp{k, v, true})
@ -42,23 +42,24 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, a annotati
nodes := make([]rootNode, 0, len(rootProps))
for i := 0; i < len(rootProps); i++ {
k := rootProps[i].k
v := rootProps[i].v
item := rootProps[i]
k := item.k
v := item.v
v = resolveRefs(v, refs)
node := rootNode{
Title: k,
Description: getDescription(v),
TopLevel: rootProps[i].topLevel,
Description: getDescription(v, item.topLevel),
TopLevel: item.topLevel,
}
node.Attributes = getAttributes(v.Properties, refs)
rootProps = append(rootProps, extractNodes(k, v.Properties, refs, a)...)
rootProps = append(rootProps, extractNodes(k, v.Properties, refs, customFields)...)
additionalProps, ok := v.AdditionalProperties.(*jsonschema.Schema)
if ok {
objectKeyType := resolveRefs(additionalProps, refs)
node.ObjectKeyAttributes = getAttributes(objectKeyType.Properties, refs)
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, a)...)
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, customFields)...)
}
if v.Items != nil {
@ -181,7 +182,7 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
attributes = append(attributes, attributeNode{
Title: k,
Type: typeString,
Description: getDescription(v),
Description: getDescription(v, true),
})
}
sort.Slice(attributes, func(i, j int) bool {
@ -190,8 +191,8 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
return attributes
}
func getDescription(s *jsonschema.Schema) string {
if s.MarkdownDescription != "" {
func getDescription(s *jsonschema.Schema, allowMarkdown bool) string {
if allowMarkdown && s.MarkdownDescription != "" {
return s.MarkdownDescription
}
return s.Description
@ -226,14 +227,22 @@ func resolveRefs(s *jsonschema.Schema, schemas map[string]jsonschema.Schema) *js
return node
}
func extractNodes(prefix string, props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, a annotationFile) []rootProp {
func shouldExtract(ref string, customFields map[string]bool) bool {
refKey := strings.TrimPrefix(ref, "#/$defs/")
_, isCustomField := customFields[refKey]
return isCustomField
}
func extractNodes(prefix string, props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema, customFields map[string]bool) []rootProp {
nodes := []rootProp{}
for k, v := range props {
if !shouldExtract(*v.Reference, customFields) {
continue
}
v = resolveRefs(v, refs)
if v.Type == "object" {
nodes = append(nodes, rootProp{prefix + "." + k, v, false})
}
v.MarkdownDescription = ""
}
return nodes
}

File diff suppressed because it is too large Load Diff

View File

@ -91,21 +91,24 @@ type annotation struct {
func generateDocs(workdir, outputPath string) error {
annotationsPath := filepath.Join(workdir, "annotations.yml")
annotationsOpenApiPath := filepath.Join(workdir, "annotations_openapi.yml")
annotationsOpenApiOverridesPath := filepath.Join(workdir, "annotations_openapi_overrides.yml")
annotations, err := LoadAndMergeAnnotations([]string{annotationsPath, annotationsOpenApiPath, annotationsOpenApiOverridesPath})
annotations, err := LoadAndMergeAnnotations([]string{annotationsPath})
if err != nil {
log.Fatal(err)
}
schemas := map[string]jsonschema.Schema{}
customFields := map[string]bool{}
s, err := jsonschema.FromType(reflect.TypeOf(config.Root{}), []func(reflect.Type, jsonschema.Schema) jsonschema.Schema{
removeJobsFields,
makeVolumeTypeOptional,
func(typ reflect.Type, s jsonschema.Schema) jsonschema.Schema {
_, isCustomField := annotations[jsonschema.TypePath(typ)]
if isCustomField {
customFields[jsonschema.TypePath(typ)] = true
}
schemas[jsonschema.TypePath(typ)] = s
refPath := getPath(typ)
@ -135,7 +138,7 @@ func generateDocs(workdir, outputPath string) error {
log.Fatal(err)
}
nodes := getNodes(s, schemas, annotations)
nodes := getNodes(s, schemas, customFields)
err = buildMarkdown(nodes, outputPath)
if err != nil {
log.Fatal(err)