Help us shape the future of Go! Take the 2026 Go Developer Survey

openapi

package
v2.950.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildNonNavTagSet

func BuildNonNavTagSet(tags []*openapi.Tag) map[string]bool

BuildNonNavTagSet returns a set of tag names that have a non-nav kind (e.g., "badge", "audience"). Tags with these kinds should not create SubSDKs — they represent cross-cutting concerns rather than navigation groups. Tags without a kind are treated as nav by default.

func BuildTagPathMap

func BuildTagPathMap(tags []*openapi.Tag) map[string]string

BuildTagPathMap resolves OpenAPI 3.2 tag parent chains into dot-notation paths. For example, tag "books" with parent "products" resolves to "products.books". Multi-level: "books" → parent "products" → parent "catalog" → "catalog.products.books". Only tags that have a parent are included in the returned map.

func ClearRefForCircularReferences

func ClearRefForCircularReferences(schema *oas3.Schema)

func Copy

func Copy(s *oas3.Schema) oas3.Schema

These are already copied by the initial struct copy (c := *s) and don't need additional handling since they are either not modified in merge operations or are simple value types that are safe to share.

func GetLibOpenAPIExplodeDefault

func GetLibOpenAPIExplodeDefault(p *openapi.Parameter) bool

func GetResolvedType

func GetResolvedType(ctx context.Context, schema *oas3.JSONSchema[oas3.Concrete]) (string, []string, bool)

func GetTypePropertyNode

func GetTypePropertyNode(schema *oas3.JSONSchema[oas3.Concrete]) *yaml.Node

func HoistAllOfExtensions

func HoistAllOfExtensions(ctx context.Context, s *oas3.JSONSchema[oas3.Referenceable], docInfo *document.DocumentInfo, visited map[string]bool, childPredicate func(string) bool) *extensions.Extensions

HoistAllOfExtensions collects extensions from a schema and its allOf children. The schema's own extensions are always collected. The childPredicate filters which extensions are hoisted from allOf children (including through $refs).

func IsComplex

func IsComplex(ctx context.Context, schema *oas3.JSONSchema[oas3.Concrete], docInfo *document.DocumentInfo) (bool, error)

func IsEmpty

func IsEmpty(schema *oas3.Schema, onlyConsiderTypeModifyingFields bool, e speakeasyExtensions) bool

func IsReferenceForCircularReferences

func IsReferenceForCircularReferences(schema *oas3.JSONSchema[oas3.Referenceable]) bool

func Merge

func Merge(ctx context.Context, baseSchema *oas3.Schema, overridingSchema *oas3.Schema, mergeDescriptiveFields, allOfMerge bool, e speakeasyExtensions, allOfMergeStrategy config.AllOfMergeStrategy, docInfo *document.DocumentInfo) error

func PopulateFromDocument

func PopulateFromDocument(ctx context.Context, docInfo *document.DocumentInfo)

PopulateFromDocument walks through the OpenAPI document's component schemas and identifies PURE ALIAS schemas (schemas that are just a $ref to another schema).

The libopenapi bug specifically affects pure alias schemas like:

Schema1:
  $ref: "#/components/schemas/SchemaShared"  # Schema1 IS a pure $ref alias
Schema2:
  $ref: "#/components/schemas/SchemaShared"  # Schema2 IS a pure $ref alias

This is DIFFERENT from schemas that CONTAIN $refs in their properties:

WebhookRequestCreated:
  type: object       # This IS an object, NOT a pure $ref alias
  properties:
    data:
      $ref: ...      # Contains a $ref, but the schema itself is NOT an alias

Only pure alias schemas are tracked in the registry.

func RefForCircularReferences

func RefForCircularReferences(schema *oas3.JSONSchema[oas3.Referenceable]) string

func ResetGlobalNestedRefRegistry

func ResetGlobalNestedRefRegistry()

ResetGlobalNestedRefRegistry clears the global registry. This should be called between processing different OpenAPI documents.

func SortOperationsLikeLibOpenAPI

func SortOperationsLikeLibOpenAPI(pathItem *openapi.PathItem, config *configuration.Config) iter.Seq2[openapi.HTTPMethod, *openapi.Operation]

func TrackRefForCircularReferences

func TrackRefForCircularReferences(schema *oas3.Schema, ref string)

Types

type NestedReferenceRegistry

type NestedReferenceRegistry struct {
	// contains filtered or unexported fields
}

NestedReferenceRegistry tracks the first reference that discovered each shared nested schema.

This registry is populated by walking ALL schemas in the document (not just component schemas). When we ENCOUNTER a $ref during the walk and resolve it, if the target is itself a $ref (creating a nested reference chain), we record the mapping.

Key insight: We only record schemas that are FOUND via $ref somewhere in the document. If a component schema is a $ref but nothing references it, it won't be recorded.

Example 1 - Nested references via paths:

paths:
  /get:
    get:
      responses:
        200:
          schema:
            $ref: "#/components/schemas/Schema1"  <- We FIND Schema1 via $ref
  /post:
    post:
      responses:
        200:
          schema:
            $ref: "#/components/schemas/Schema2"  <- We FIND Schema2 via $ref
components:
  schemas:
    Schema1:
      $ref: "#/components/schemas/SchemaShared"  <- Schema1 IS a $ref (nested)
    Schema2:
      $ref: "#/components/schemas/SchemaShared"  <- Schema2 IS a $ref (nested)
    SchemaShared:
      type: object

When we walk and encounter $ref to Schema1, we resolve it and see: - Chain: Schema1 -> SchemaShared (nested!) - Record: SchemaShared -> Schema1

When we encounter $ref to Schema2, we resolve it and see: - Chain: Schema2 -> SchemaShared (nested!) - SchemaShared already recorded with Schema1 (first wins)

Example 2 - Direct access (no $ref):

components:
  schemas:
    TestSchema:
      $ref: "#/components/schemas/StatusEnum"
    StatusEnum:
      type: string
      enum: [active, inactive]

If the code directly accesses TestSchema (not via $ref resolution), TestSchema is never FOUND via $ref, so nothing is recorded. When we process TestSchema, it should resolve to "StatusEnum".

func GlobalNestedRefRegistry

func GlobalNestedRefRegistry() *NestedReferenceRegistry

GlobalNestedRefRegistry returns the global nested reference registry.

func NewNestedReferenceRegistry

func NewNestedReferenceRegistry() *NestedReferenceRegistry

NewNestedReferenceRegistry creates a new NestedReferenceRegistry.

func (*NestedReferenceRegistry) All

func (r *NestedReferenceRegistry) All() map[string]string

All returns a copy of all tracked references. The returned map is safe to modify without affecting the registry.

func (*NestedReferenceRegistry) Clear

func (r *NestedReferenceRegistry) Clear()

Clear removes all tracked references. This is useful for resetting state between documents.

func (*NestedReferenceRegistry) GetAliasCount

func (r *NestedReferenceRegistry) GetAliasCount(targetRef string) int

GetAliasCount returns the number of aliases that point to the given target reference. Returns 0 if the target has no aliases tracked.

func (*NestedReferenceRegistry) GetOriginalRef

func (r *NestedReferenceRegistry) GetOriginalRef(sharedRef string) string

GetOriginalRef returns the first intermediate reference that discovered the given shared reference. Returns empty string if the shared reference has not been tracked.

func (*NestedReferenceRegistry) HasMultipleAliases

func (r *NestedReferenceRegistry) HasMultipleAliases(targetRef string) bool

HasMultipleAliases returns true if the target has 2 or more aliases pointing to it. This is important for the libopenapi bug behavior: - 2+ aliases: direct target access transforms to first alias name - 1 alias: direct target access stays as target name

func (*NestedReferenceRegistry) IsTracked

func (r *NestedReferenceRegistry) IsTracked(sharedRef string) bool

IsTracked returns true if the given shared reference has been tracked.

func (*NestedReferenceRegistry) Len

func (r *NestedReferenceRegistry) Len() int

Len returns the number of tracked shared references.

func (*NestedReferenceRegistry) Track

func (r *NestedReferenceRegistry) Track(sharedRef, intermediateRef string) bool

Track records that a shared reference was first discovered via a particular intermediate reference. If the shared reference has already been tracked for first alias, the first wins. However, alias count is always incremented.

Parameters:

  • sharedRef: The final resolved reference (e.g., "#/components/schemas/SchemaShared")
  • intermediateRef: The intermediate reference in the chain (e.g., "#/components/schemas/Schema1")

Returns true if this is the first time tracking this shared reference, false if it was already tracked.

type Version

type Version string
const (
	Version2  Version = "2"
	Version3  Version = "3"
	Version31 Version = "3.1"
)

func DetermineOpenAPIVersion

func DetermineOpenAPIVersion(version string) Version

Jump to

Keyboard shortcuts

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