INNER CODE UNIT · Go
decodeDocument
stacklok/toolhive · cmd/help/openapi-normalize/main.go:80
func decodeDocument(input []byte, extension string) (map[string]any, error) {
var document map[string]any
if extension == ".yaml" || extension == ".yml" {
if err := yaml.Unmarshal(input, &document); err != nil {
return nil, fmt.Errorf("decode YAML: %w", err)
}
} else if err := json.Unmarshal(input, &document); err != nil {
return nil, fmt.Errorf("decode JSON: %w", err)
}
if document == nil {
return nil, fmt.Errorf("OpenAPI document must be an object")
}
return document, nil
}
func normalize(document map[string]any) error {
components, ok := object(document["components"])
if !ok {