openapipatch

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddComponentSchemaPrefixPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "add-component-schema-prefix",
	Description:         "Adds a prefix to all component schemas in the OpenAPI document",
	PatchV3DocumentFunc: AddComponentSchemaPrefix,
}
View Source
var AddIdempotencyKeyPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "add-idempotency-key",
	Description:         "Adds an idempotency key to all POST operations in the OpenAPI document (see https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header)",
	PatchV3DocumentFunc: AddIdempotencyKey,
}
View Source
var AddPathPrefixPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "add-path-prefix",
	Description:         "Adds a prefix to all paths in the OpenAPI document",
	PatchV3DocumentFunc: AddPathPrefix,
}
View Source
var EmbeddedPatcherMap = util.SliceToMapWithKeyFunc(EmbeddedPatchers, func(p BuiltInPatcher) string {
	return p.Type + ":" + p.ID
})
View Source
var FixCommonPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-common",
	Description:         "Fixes various common issues.",
	PatchV3DocumentFunc: FixCommon,
}
View Source
var FixInvalidMaxValuePatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-invalid-max-value",
	Description:         "Fixes integer and long schemas where the maximum value is out of bounds for the type, e.g. max: 9223372036854775807 for long.",
	PatchV3DocumentFunc: FixInvalidMaxValue,
}
View Source
var FixMissingOneOfFromDiscriminatorPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-missing-oneof-from-discriminator",
	Description:         "Recursively populates missing oneOf lists using discriminator mapping entries across the entire document",
	PatchV3DocumentFunc: FixMissingOneOfFromDiscriminator,
}
View Source
var FixMissingSchemaTitlePatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-missing-schema-title",
	Description:         "Adds a title to all schemas that are missing a title",
	PatchV3DocumentFunc: FixMissingSchemaTitle,
}
View Source
var FixOAS300VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-300-version",
	Description:         "Fixes specs authored in OpenAPI 3.0.0 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS300Version,
}
View Source
var FixOAS301VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-301-version",
	Description:         "Fixes specs authored in OpenAPI 3.0.1 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS301Version,
}
View Source
var FixOAS302VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-302-version",
	Description:         "Fixes specs authored in OpenAPI 3.0.2 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS302Version,
}
View Source
var FixOAS303VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-303-version",
	Description:         "Fixes specs authored in OpenAPI 3.0.3 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS303Version,
}
View Source
var FixOAS304VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-304-version",
	Description:         "Fixes specs authored in OpenAPI 3.0.4 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS304Version,
}
View Source
var FixOAS310VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-310-version",
	Description:         "Fixes specs authored in OpenAPI 3.1.0 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS310Version,
}
View Source
var FixOAS311VersionPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-oas-311-version",
	Description:         "Fixes specs authored in OpenAPI 3.1.1 format but mistakenly labeled as a different version, without converting schema content.",
	PatchV3DocumentFunc: FixOAS311Version,
}
View Source
var FixOperationTagsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-operation-tags",
	Description:         "Ensures operation tags are documented in the document without forcing default tags",
	PatchV3DocumentFunc: FixOperationTags,
}
View Source
var FixRemoveCommonOperationIdPrefixPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "fix-remove-common-operation-id-prefix",
	Description:         "Removes common prefixes from operation IDs",
	PatchV3DocumentFunc: FixRemoveCommonOperationIdPrefix,
}
View Source
var FlattenComponentsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "flatten-components",
	Description:         "Flattens inline request bodies and response schemas into the components section of the document",
	PatchV3DocumentFunc: FlattenComponents,
}
View Source
var GenerateCodeSamplesRefsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "generate-code-samples-refs",
	Description:         "Generates x-codeSamples refs from operation slugs",
	PatchV3DocumentFunc: GenerateCodeSamplesRefs,
}
View Source
var GenerateMissingOperationIdsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "generate-missing-operation-id",
	Description:         "Generates operation IDs for all operations that are missing an ID (does not overwrite existing IDs)",
	PatchV3DocumentFunc: GenerateMissingOperationIds,
}
View Source
var GenerateOperationIdsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "generate-operation-id",
	Description:         "Generates operation IDs for all operations (overwrites existing IDs)",
	PatchV3DocumentFunc: GenerateOperationIds,
}
View Source
var GenerateTagFromDocTitlePatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "generate-tag-from-doc-title",
	Description:         "Removes all tags and createsone tag based on the document title, useful when merging multiple specs",
	PatchV3DocumentFunc: GenerateTagFromDocTitle,
}
View Source
var MergePolymorphicPropertiesPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-polymorphic-properties",
	Description:         "Merges polymorphic property values (anyOf, oneOf, allOf) into a single flat schema referenced by properties",
	PatchV3DocumentFunc: MergePolymorphicProperties,
}
View Source
var MergePolymorphicSchemasPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-polymorphic-schemas",
	Description:         "Merges polymorphic schemas (oneOf, anyOf, allOf) into a single schema",
	PatchV3DocumentFunc: MergePolymorphicSchemas,
}
View Source
var PruneDocumentTagsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-document-tags",
	Description:         "Removes all tags from the document",
	PatchV3DocumentFunc: PruneDocumentTags,
}
View Source
var PruneInvalidPathsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-invalid-paths",
	Description:         "Removes all paths that are invalid (e.g. empty path, path with invalid characters)",
	PatchV3DocumentFunc: PruneInvalidPaths,
}
View Source
var PruneOperationTagsExceptFirstPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-operation-tags-keep-first",
	Description:         "Removes all tags from operations except the first one",
	PatchV3DocumentFunc: PruneOperationTagsExceptFirst,
}
View Source
var PruneOperationTagsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-operation-tags",
	Description:         "Removes all tags from operations",
	PatchV3DocumentFunc: PruneOperationTags,
}
View Source
var PrunePathPrefixPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-path-prefix",
	Description:         "Prunes a prefix from all paths in the OpenAPI document",
	PatchV3DocumentFunc: PrunePathPrefix,
}
View Source
var PruneUnusualPathsPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "prune-unusual-paths",
	Description:         "Removes all paths that are unusual (e.g. path parameters with underscores, ...)",
	PatchV3DocumentFunc: PruneUnusualPaths,
}
View Source
var SetEndpointPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "set-endpoint",
	Description:         "Sets the server endpoint URL for the OpenAPI document",
	PatchV3DocumentFunc: SetEndpoint,
}
View Source
var SetOperationTagPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "set-operation-tag",
	Description:         "Sets a tag for all operations in the OpenAPI document",
	PatchV3DocumentFunc: SetOperationTag,
}
View Source
var SimplifyAllOfPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-all-of",
	Description:         "Merges allOf subschemas into the parent schema",
	PatchV3DocumentFunc: SimplifyAllOf,
}
View Source
var SimplifyAnyOfPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-any-of",
	Description:         "Merges anyOf subschemas into the parent schema to support non-polymorphic DTOs",
	PatchV3DocumentFunc: SimplifyAnyOf,
}
View Source
var SimplifyInlineAllOfPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-inline-all-of",
	Description:         "Merges allOf subschemas into the parent schema, but only for inline schemas (i.e. not $ref)",
	PatchV3DocumentFunc: SimplifyInlineAllOf,
}
View Source
var SimplifyPolymorphicBooleansPatch = BuiltInPatcher{
	Type:                "builtin",
	ID:                  "simplify-polymorphic-booleans",
	Description:         "Merges polymorphic boolean schemas (oneOf, anyOf, allOf) into a single boolean schema",
	PatchV3DocumentFunc: SimplifyPolymorphicBooleans,
}
View Source
var SpeakeasyCleanupPatch = BuiltInPatcher{
	Type:          "speakeasy",
	ID:            "cleanup",
	Description:   "Cleanup the formatting of a given OpenAPI document",
	PatchFileFunc: SpeakeasyCleanup,
}
View Source
var SpeakeasyFormatPatch = BuiltInPatcher{
	Type:          "speakeasy",
	ID:            "format",
	Description:   "Format an OpenAPI document to be more human-readable",
	PatchFileFunc: SpeakeasyFormat,
}
View Source
var SpeakeasyNormalizePatch = BuiltInPatcher{
	Type:          "speakeasy",
	ID:            "normalize",
	Description:   "Normalize an OpenAPI document to be more human-readable",
	PatchFileFunc: SpeakeasyNormalize,
}
View Source
var SpeakeasyRemoveUnusedPatch = BuiltInPatcher{
	Type:          "speakeasy",
	ID:            "remove-unused",
	Description:   "Given an OpenAPI file, remove all unused options",
	PatchFileFunc: SpeakeasyRemoveUnused,
}

Functions

func AddComponentSchemaPrefix

func AddComponentSchemaPrefix(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func AddIdempotencyKey

func AddIdempotencyKey(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

AddIdempotencyKey adds an idempotency key to all POST operations in the OpenAPI document - see https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/

func AddPathPrefix

func AddPathPrefix(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func ApplyPatches

func ApplyPatches(input []byte, patches []sharedpatch.SpecPatch) ([]byte, error)

func FixCommon

func FixCommon(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

FixCommon fixes various common issues

func FixInvalidMaxValue

func FixInvalidMaxValue(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

FixInvalidMaxValue fixes integers and longs, where the maximum value is out of bounds for the type

func FixMissingOneOfFromDiscriminator

func FixMissingOneOfFromDiscriminator(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixMissingSchemaTitle

func FixMissingSchemaTitle(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

FixMissingSchemaTitle fills in missing schema titles with the schema key

func FixOAS300Version

func FixOAS300Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS301Version

func FixOAS301Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS302Version

func FixOAS302Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS303Version

func FixOAS303Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS304Version

func FixOAS304Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS310Version

func FixOAS310Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOAS311Version

func FixOAS311Version(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func FixOperationTags

func FixOperationTags(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

FixOperationTags ensures operation tags are documented in the document. Operations without tags are intentionally left untagged.

func FixRemoveCommonOperationIdPrefix

func FixRemoveCommonOperationIdPrefix(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

FixRemoveCommonOperationIdPrefix sets the operation IDs of all operations and fixes some commonly seen issues.

func FlattenComponents

func FlattenComponents(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func GenerateCodeSamplesRefs

func GenerateCodeSamplesRefs(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func GenerateMissingOperationIds

func GenerateMissingOperationIds(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func GenerateOpenAPIOverlay

func GenerateOpenAPIOverlay(doc *libopenapi.DocumentModel[v3.Document], id string) ([]byte, error)

func GenerateOperationIds

func GenerateOperationIds(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func GenerateTagFromDocTitle

func GenerateTagFromDocTitle(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

GenerateTagFromDocTitle removes all tags and creates one new tag per API spec doc from document title setting it on each operation. Note: This patch must be applied before merging specs.

func LLMOperationIDPatch

func LLMOperationIDPatch(doc *libopenapi.DocumentModel[v3.Document]) ([]byte, error)

func MergePolymorphicProperties

func MergePolymorphicProperties(v3Model *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

MergePolymorphicProperties merges polymorphic property values (anyOf, oneOf, allOf) into a single flat schema referenced by resp. properties

func MergePolymorphicSchemas

func MergePolymorphicSchemas(v3Model *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

MergePolymorphicSchemas merges polymorphic schemas (anyOf, oneOf, allOf) into a single flat schema

func PruneDocumentTags

func PruneDocumentTags(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func PruneInvalidPaths

func PruneInvalidPaths(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func PruneOperationTags

func PruneOperationTags(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func PruneOperationTagsExceptFirst

func PruneOperationTagsExceptFirst(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func PrunePathPrefix

func PrunePathPrefix(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func PruneUnusualPaths

func PruneUnusualPaths(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func ResolvePatchSets

func ResolvePatchSets(patchSets []PatchSet) []sharedpatch.SpecPatch

func SetEndpoint

func SetEndpoint(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func SetOperationTag

func SetOperationTag(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func SimplifyAllOf

func SimplifyAllOf(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func SimplifyAnyOf

func SimplifyAnyOf(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func SimplifyInlineAllOf

func SimplifyInlineAllOf(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

func SimplifyPolymorphicBooleans

func SimplifyPolymorphicBooleans(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error

SimplifyPolymorphicBooleans looks for booleans defined as polymorphic types and simplifies them

func SpeakeasyCleanup

func SpeakeasyCleanup(inputFile string, config map[string]interface{}) ([]byte, error)

func SpeakeasyFormat

func SpeakeasyFormat(inputFile string, config map[string]interface{}) ([]byte, error)

func SpeakeasyNormalize

func SpeakeasyNormalize(inputFile string, config map[string]interface{}) ([]byte, error)

func SpeakeasyRemoveUnused

func SpeakeasyRemoveUnused(inputFile string, config map[string]interface{}) ([]byte, error)

Types

type BuiltInPatcher

type BuiltInPatcher struct {
	Type                string `yaml:"type"`
	ID                  string `yaml:"id,omitempty"`
	Description         string `yaml:"description,omitempty"`
	PatchV3DocumentFunc func(doc *libopenapi.DocumentModel[v3.Document], config map[string]interface{}) error
	PatchFileFunc       func(inputFile string, config map[string]interface{}) ([]byte, error)
}

func (BuiltInPatcher) ToSpecPatch

func (bip BuiltInPatcher) ToSpecPatch() sharedpatch.SpecPatch

type PatchPreset

type PatchPreset struct {
	Id      string                  `yaml:"id"`
	Patches []sharedpatch.SpecPatch `yaml:"patches"`
}

type PatchSet

type PatchSet struct {
	Id     string                            `yaml:"id"`
	Config map[string]map[string]interface{} `yaml:"config,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL