Documentation
¶
Overview ¶
Package edit provides structural edits to an OpenAPI document — changes where touching one place obliges you to touch several others.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeSchema ¶
MergeSchema repoints every reference to oldName at newName and removes oldName from components.schemas, leaving newName's own definition untouched.
It differs from RenameSchema, which refuses to rename a schema onto a name that already exists (ErrSchemaExists): merging onto an existing schema is exactly the point here, typically because several near-duplicate schemas (e.g. ones an OpenAPI generator produced one per endpoint, that happen to describe the same thing) are being consolidated into one.
If description is non-empty, it becomes the $ref-level description on every reference this repoints, replacing whatever description that reference already had. The usual reason to reach for Merge rather than Rename is that oldName's own definition — its bounds, its wording — is about to be discarded once oldName is gone; setting description is how that information survives on the fields that used it, rather than being lost in the merge.
It fails, changing nothing, if oldName or newName is not in components.schemas (ErrSchemaNotFound).
func RenameSchema ¶
RenameSchema renames a schema in components.schemas and rewrites every reference to it, wherever in the document that reference occurs.
The schema keeps its position among the components, so renaming produces a one-line change rather than reordering the section.
Renaming a schema to its current name does nothing and reports no error. Otherwise it fails, changing nothing, if:
- oldName is not in components.schemas (ErrSchemaNotFound);
- newName is already taken (ErrSchemaExists) — renaming onto an existing schema would silently discard one of two different definitions, and point every reference to whichever survived;
- newName could not be referenced (ErrInvalidSchemaName).
func WalkSchemaRefs ¶
WalkSchemaRefs calls fn once for every schema reference reachable from doc: through components (schemas, responses, parameters, request bodies, headers, callbacks, path items) and through every path, operation, and webhook.
A schema reachable through more than one reference — directly, or because two references resolve to the same schema — is still walked into only once, so fn can freely mutate the references it's given without risking infinite recursion on a self-referential schema.
This is the traversal RenameSchema uses to find every occurrence of a reference; it's exported because other structural edits need the same walk with a different fn, e.g. finding every reference to a schema that's about to be merged into another with MergeSchema.
Types ¶
type ErrInvalidSchemaName ¶
type ErrInvalidSchemaName struct{ Name string }
ErrInvalidSchemaName is returned when the new name is not a valid key under components, and so could not be referenced.
func (*ErrInvalidSchemaName) Error ¶
func (e *ErrInvalidSchemaName) Error() string
type ErrSchemaExists ¶
type ErrSchemaExists struct{ Name string }
ErrSchemaExists is returned when the new name is already taken by another schema. Renaming onto it would silently merge two definitions into one.
func (*ErrSchemaExists) Error ¶
func (e *ErrSchemaExists) Error() string
type ErrSchemaNotFound ¶
type ErrSchemaNotFound struct{ Name string }
ErrSchemaNotFound is returned when the schema to rename is not in components.schemas.
func (*ErrSchemaNotFound) Error ¶
func (e *ErrSchemaNotFound) Error() string