generator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Title       string
	Version     string
	Description string
	Servers     []string // server URLs; empty -> a single relative-root "/"
	License     *License
	// DisableTenantSecurity omits the X-Tenant-ID security scheme + root security
	// (for single-tenant services).
	DisableTenantSecurity bool
	// TenantHeader overrides the header name in the tenant security scheme
	// (default X-Tenant-ID; go-bricks header resolvers are configurable).
	TenantHeader string
}

Config configures a generator's document-level metadata. Zero values fall back to sensible defaults (title/version from the analyzer or the built-in default, a relative-root server, tenant security on).

type License

type License struct {
	Name string
	URL  string
}

License is the optional info.license block.

type OpenAPIGenerator

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

OpenAPIGenerator creates OpenAPI specifications from project models

func New

func New(title, version, description string) *OpenAPIGenerator

New creates a new OpenAPI generator with default servers/security (tenant auth on). Retained for callers that only need title/version/description.

func NewWithConfig

func NewWithConfig(cfg *Config) *OpenAPIGenerator

NewWithConfig creates a generator from a full Config (CLI-driven metadata). A nil cfg is treated as the zero Config. Reference-typed fields (Servers, License) are copied so the generator is immutable after construction: a caller mutating its Config later cannot alter output or race with a concurrent Generate.

func (*OpenAPIGenerator) Generate

func (g *OpenAPIGenerator) Generate(project *models.Project) (string, error)

Generate creates an OpenAPI YAML specification from a project

type OpenAPIInfo

type OpenAPIInfo struct {
	Title       string          `yaml:"title"`
	Version     string          `yaml:"version"`
	Description string          `yaml:"description"`
	License     *openAPILicense `yaml:"license,omitempty"`
}

OpenAPIInfo represents the info section of an OpenAPI specification

type OpenAPIMediaType

type OpenAPIMediaType struct {
	Schema *OpenAPIProperty `yaml:"schema"`
}

OpenAPIMediaType is a Media Type Object (the value under a content-type key).

type OpenAPIOperation

type OpenAPIOperation struct {
	OperationID string                      `yaml:"operationId"`
	Summary     string                      `yaml:"summary"`
	Description string                      `yaml:"description,omitempty"`
	Tags        []string                    `yaml:"tags,omitempty"`
	Parameters  []Parameter                 `yaml:"parameters,omitempty"`
	RequestBody *OpenAPIRequestBody         `yaml:"requestBody,omitempty"`
	Responses   map[string]*OpenAPIResponse `yaml:"responses"`
	// Security overrides the root security requirement for this operation.
	// nil => inherit the document-level security; a non-nil empty slice =>
	// emit `security: []` (no auth), used for tenant-agnostic routes.
	Security *[]map[string][]string `yaml:"security,omitempty"`
}

OpenAPIOperation is a single HTTP operation. Field order matches the emitted document: operationId, summary, description, tags, parameters, requestBody, responses.

type OpenAPIPathItem

type OpenAPIPathItem struct {
	Get     *OpenAPIOperation `yaml:"get,omitempty"`
	Put     *OpenAPIOperation `yaml:"put,omitempty"`
	Post    *OpenAPIOperation `yaml:"post,omitempty"`
	Delete  *OpenAPIOperation `yaml:"delete,omitempty"`
	Patch   *OpenAPIOperation `yaml:"patch,omitempty"`
	Head    *OpenAPIOperation `yaml:"head,omitempty"`
	Options *OpenAPIOperation `yaml:"options,omitempty"`
}

OpenAPIPathItem holds the operations registered under one path. Method fields are declared in canonical order so yaml.Marshal emits them deterministically; omitempty drops the methods a path does not use.

type OpenAPIProperty

type OpenAPIProperty struct {
	Type string `yaml:"type,omitempty"`
	// AllOf wraps a $ref that must also carry sibling keywords (e.g. nullable):
	// in OpenAPI 3.0 a $ref ignores its siblings, so `allOf: [{$ref}]` plus the
	// sibling keyword is the encoding that actually applies.
	AllOf                []*OpenAPIProperty          `yaml:"allOf,omitempty"`
	Properties           map[string]*OpenAPIProperty `yaml:"properties,omitempty"`           // For inline objects (e.g. the data/meta envelope)
	AdditionalProperties *OpenAPIProperty            `yaml:"additionalProperties,omitempty"` // For maps (the value schema)
	Format               string                      `yaml:"format,omitempty"`
	Description          string                      `yaml:"description,omitempty"`
	Example              any                         `yaml:"example,omitempty"`
	Ref                  string                      `yaml:"$ref,omitempty"`
	Items                *OpenAPIProperty            `yaml:"items,omitempty"` // For arrays
	MinLength            *int                        `yaml:"minLength,omitempty"`
	MaxLength            *int                        `yaml:"maxLength,omitempty"`
	MinItems             *int                        `yaml:"minItems,omitempty"` // For arrays (slice cardinality)
	MaxItems             *int                        `yaml:"maxItems,omitempty"`
	MinProperties        *int                        `yaml:"minProperties,omitempty"` // For maps (entry-count cardinality)
	MaxProperties        *int                        `yaml:"maxProperties,omitempty"`
	Minimum              *float64                    `yaml:"minimum,omitempty"`
	Maximum              *float64                    `yaml:"maximum,omitempty"`
	ExclusiveMinimum     *bool                       `yaml:"exclusiveMinimum,omitempty"`
	ExclusiveMaximum     *bool                       `yaml:"exclusiveMaximum,omitempty"`
	Pattern              string                      `yaml:"pattern,omitempty"`
	Enum                 []any                       `yaml:"enum,omitempty"`
	Nullable             bool                        `yaml:"nullable,omitempty"`
}

OpenAPIProperty represents a schema property

type OpenAPIRequestBody

type OpenAPIRequestBody struct {
	Required    bool                         `yaml:"required"`
	Description string                       `yaml:"description,omitempty"`
	Content     map[string]*OpenAPIMediaType `yaml:"content"`
}

OpenAPIRequestBody is a Request Body Object. Description carries the JOSE compact-serialization note when the request type is jose-tagged.

type OpenAPIResponse

type OpenAPIResponse struct {
	Description string                       `yaml:"description"`
	Content     map[string]*OpenAPIMediaType `yaml:"content,omitempty"`
}

OpenAPIResponse is a Response Object.

type OpenAPISchema

type OpenAPISchema struct {
	Type        string                      `yaml:"type"`
	Properties  map[string]*OpenAPIProperty `yaml:"properties,omitempty"`
	Required    []string                    `yaml:"required,omitempty"`
	Description string                      `yaml:"description,omitempty"`
}

OpenAPISchema represents a schema definition

type Parameter

type Parameter struct {
	Name        string           `yaml:"name"`
	In          string           `yaml:"in"` // "path", "query", "header"
	Required    bool             `yaml:"required"`
	Description string           `yaml:"description,omitempty"`
	Schema      *OpenAPIProperty `yaml:"schema"`
	Example     any              `yaml:"example,omitempty"`
}

Parameter represents an OpenAPI parameter (path, query, or header). Field order matches the emitted document; Schema is always present, description and example are omitted when empty.

Jump to

Keyboard shortcuts

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