fix: Description of root types with additional properties

This commit is contained in:
Ilya Kuznetsov 2025-01-08 16:11:35 +01:00
parent fe6ba76b7d
commit c355fbfcb2
2 changed files with 8 additions and 1 deletions

View File

@ -61,6 +61,12 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFiel
additionalProps, ok := v.AdditionalProperties.(*jsonschema.Schema)
if ok {
objectKeyType := resolveRefs(additionalProps, refs)
if node.Description == "" {
node.Description = getDescription(objectKeyType, true)
}
if len(node.Example) == 0 {
node.Example = getExample(objectKeyType)
}
node.ObjectKeyAttributes = getAttributes(objectKeyType.Properties, refs)
rootProps = append(rootProps, extractNodes(k, objectKeyType.Properties, refs, customFields)...)
}

View File

@ -88,11 +88,11 @@ func generateDocs(inputPaths []string, outputPath string, rootType reflect.Type,
if isCustomField {
customFields[jsonschema.TypePath(typ)] = true
}
schemas[jsonschema.TypePath(typ)] = s
refPath := getPath(typ)
shouldHandle := strings.HasPrefix(refPath, "github.com")
if !shouldHandle {
schemas[jsonschema.TypePath(typ)] = s
return s
}
@ -110,6 +110,7 @@ func generateDocs(inputPaths []string, outputPath string, rootType reflect.Type,
assignAnnotation(v, a[k])
}
schemas[jsonschema.TypePath(typ)] = s
return s
},
})