INNER CODE UNIT · Go

rewriteReferences

stacklok/toolhive · cmd/help/openapi-normalize/main.go:214

func rewriteReferences(value any, renames map[string]string) error {
	switch value := value.(type) {
	case map[string]any:
		if reference, ok := value["$ref"].(string); ok {
			const prefix = "#/components/schemas/"
			if oldName, found := strings.CutPrefix(reference, prefix); found {
				newName, exists := renames[oldName]
				if !exists {
					return fmt.Errorf("reference %q points to a schema that does not exist", reference)
				}
				value["$ref"] = prefix + newName
			}
		}
		for _, child := range value {
			if err := rewriteReferences(child, renames); err != nil {
				return err
			}
		}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…