builder

package
v0.0.0-...-5ddcf64 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 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

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	Name    string
	Comment string
}

type Builder

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

Builder is an SDK builder. Builder works in two steps: First, it loads the OpenAPI specs and pre-processes them for code generation by transforming the specs into intermediary representation. Secondly, it generates and writes the SDK to desired destination.

func New

func New(cfg Config, opts ...Option) *Builder

New creates a new Builder. Call [Build.Load] to load in OpenAPI specs and [Build.Build] to generate SDK based on provided config.

func (*Builder) Build

func (b *Builder) Build() error

Build the SDK and write it to designated output directory. The OpenAPI specs first need to be loaded using Builder.Load.

func (*Builder) Load

func (b *Builder) Load(spec *v3.Document) error

Load loads OpenAPI specs into the builder. To generated the SDK, call Builder.Build.

func (*Builder) Samples

func (b *Builder) Samples(sdkVersion string) (*SampleCatalog, error)

Samples builds a deterministic catalog of compilable Go examples.

type Config

type Config struct {
	// Out is the output directory that the SDK will be written to.
	Out string
	// Name is the name of the product / service.
	Name string
}

Config is builder configuration which configures output options.

type EnumDeclaration

type EnumDeclaration[E cmp.Ordered] struct {
	Type   TypeDeclaration
	Values []EnumOption[E]
}

EnumDeclaration holds the information for enum types

func (*EnumDeclaration[E]) String

func (et *EnumDeclaration[E]) String() string

type EnumOption

type EnumOption[E cmp.Ordered] struct {
	Name  string
	Value E
}

type Method

type Method struct {
	Description    string
	HTTPMethod     string
	FunctionName   string
	ResponseType   *ResponseType
	Path           string
	PathParams     []Parameter
	RequestParams  *Parameter
	HasQueries     bool
	HasHeaders     bool
	OptionalParams bool
	HasBody        bool
	Responses      []Response
}

Method describes a client method. Methods map one-to-one to OpenAPI operations.

func (Method) ParamsString

func (mt Method) ParamsString() string

type NamedSchema

type NamedSchema struct {
	Ref    string
	Schema *base.SchemaProxy
}

type OneOfDeclaration

type OneOfDeclaration struct {
	Name    string
	Options []string
}

func (*OneOfDeclaration) String

func (o *OneOfDeclaration) String() string

type Option

type Option func(b *Builder)

type Parameter

type Parameter struct {
	Name string
	Type string
}

Parameter is a method parameter.

type Response

type Response struct {
	IsErr          bool
	IsDefault      bool
	IsUnexpected   bool
	Type           string
	Code           int
	ErrDescription string
}

type ResponseType

type ResponseType struct {
	Type    string
	IsOneOf bool
}

type SDK

type SDK struct {
	Module  string `json:"module"`
	Version string `json:"version"`
}

SDK identifies the package used by every generated sample.

type Sample

type Sample struct {
	ID          string `json:"id"`
	OperationID string `json:"operationId"`
	Example     string `json:"example,omitempty"`
	Summary     string `json:"summary,omitempty"`
	Description string `json:"description,omitempty"`
	HTTPMethod  string `json:"httpMethod"`
	Path        string `json:"path"`
	Source      string `json:"sample"`
}

Sample is a complete, formatted Go program for one OpenAPI operation example.

type SampleCatalog

type SampleCatalog struct {
	SchemaVersion  int      `json:"schemaVersion"`
	Language       string   `json:"language"`
	SDK            SDK      `json:"sdk"`
	OpenAPIVersion string   `json:"openAPIVersion"`
	Samples        []Sample `json:"samples"`
}

SampleCatalog is the versioned JSON contract consumed by documentation sites.

type StructField

type StructField struct {
	// Name of the field
	Name string
	// Type of the field, either primitive type (e.g. string) or if the field
	// is a schema reference then the type of the schema.
	Type string
	// Tags to apply to the field, this would usually be json serialization
	// information.
	Tags map[string][]string
	// Optional field.
	Optional bool
	// Pointer indicates whether the field should be a pointer in the generated struct.
	Pointer bool

	Comment string

	Parameter *v3.Parameter
	Schema    *base.SchemaProxy
}

StructField holds the information for StructField of a type.

func (*StructField) String

func (f *StructField) String() string

type TypeDeclaration

type TypeDeclaration struct {
	// Name of the type
	Name string
	// Type describes the type of the type (e.g. struct, int64, string)
	Type string
	// Alias indicates whether the declaration aliases Type instead of defining a new type.
	Alias bool
	// Fields holds the information for the field
	Fields []StructField
	// Comment holds the description of the type
	Comment string

	Response  *v3.Response
	Operation *v3.Operation
	Schema    *base.Schema
}

TypeDeclaration holds the information for generating a type. TODO: split into struct, alias, etc.

func (*TypeDeclaration) String

func (tt *TypeDeclaration) String() string

type Writable

type Writable interface {
	String() string
}

Jump to

Keyboard shortcuts

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