codegen

package
v3.63.5 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOperationNameEmpty                        = errors.New("operation name cannot be an empty string")
	ErrRequestPathEmpty                          = errors.New("request path cannot be an empty string")
	ErrMergingSchemasWithDifferentUniqueItems    = errors.New("merging two schemas with different UniqueItems")
	ErrMergingSchemasWithDifferentExclusiveMin   = errors.New("merging two schemas with different ExclusiveMin")
	ErrMergingSchemasWithDifferentExclusiveMax   = errors.New("merging two schemas with different ExclusiveMax")
	ErrMergingSchemasWithDifferentNullable       = errors.New("merging two schemas with different Nullable")
	ErrMergingSchemasWithDifferentReadOnly       = errors.New("merging two schemas with different ReadOnly")
	ErrMergingSchemasWithDifferentWriteOnly      = errors.New("merging two schemas with different WriteOnly")
	ErrTransitiveMergingAllOfSchema1             = errors.New("error transitive merging AllOf on schema 1")
	ErrTransitiveMergingAllOfSchema2             = errors.New("error transitive merging AllOf on schema 2")
	ErrMergingSchemasWithDifferentDefaults       = errors.New("merging two sets of defaults is undefined")
	ErrMergingSchemasWithDifferentFormats        = errors.New("can not merge incompatible formats")
	ErrMergingSchemasWithDifferentDiscriminators = errors.New("merging two schemas with discriminators is not supported")
	ErrMergingSchemasWithAdditionalProperties    = errors.New("merging two schemas with additional properties, this is unhandled")
	ErrAmbiguousDiscriminatorMapping             = errors.New("ambiguous discriminator.mapping: please replace inlined object with $ref")
	ErrDiscriminatorNotAllMapped                 = errors.New("discriminator: not all schemas were mapped")
	ErrEmptySchema                               = errors.New("empty schema")
	ErrEmptyReferencePath                        = errors.New("empty reference path")
)
View Source
var TemplateFunctions = template.FuncMap{
	"genTypeName":    nameNormalizer,
	"lcFirst":        lowercaseFirstCharacter,
	"ucFirst":        uppercaseFirstCharacter,
	"caps":           strings.ToUpper,
	"lower":          strings.ToLower,
	"snake":          strcase.ToSnake,
	"toGoComment":    stringToGoCommentWithPrefix,
	"ternary":        ternary,
	"join":           join,
	"fst":            fst,
	"hasPrefix":      strings.HasPrefix,
	"hasSuffix":      strings.HasSuffix,
	"str":            str,
	"dict":           dict,
	"slice":          func() []any { return []any{} },
	"escapeGoString": escapeGoString,
	"append": func(slice []any, val any) []any {
		return append(slice, val)
	},
	"filterOmitEmpty": filterOmitEmpty,
}

TemplateFunctions is passed to the template engine, and we can call each function here by keyName from the template code.

Functions

func CreateDocument

func CreateDocument(docContents []byte, cfg Configuration) (libopenapi.Document, error)

func FormatCode

func FormatCode(src string) (string, error)

FormatCode formats the provided Go code. It optimizes imports and formats the code using gofmt.

func LoadDocumentFromContents

func LoadDocumentFromContents(contents []byte) (libopenapi.Document, error)

func UppercaseFirstCharacter

func UppercaseFirstCharacter(str string) string

UppercaseFirstCharacter Uppercases the first character in a string. This assumes UTF-8, so we have to be careful with unicode, don't treat it as a byte array.

Types

type AdditionalImport

type AdditionalImport struct {
	Alias   string `yaml:"alias,omitempty"`
	Package string `yaml:"package"`
}

type Client

type Client struct {
	Name    string        `yaml:"name"`
	Timeout time.Duration `yaml:"timeout"`
}

type Configuration

type Configuration struct {
	PackageName     string  `yaml:"package"`
	CopyrightHeader string  `yaml:"copyright-header"`
	SkipPrune       bool    `yaml:"skip-prune"`
	Output          *Output `yaml:"output"`

	Generate *GenerateOptions `yaml:"generate"`
	Filter   FilterConfig     `yaml:"filter,omitempty"`

	AdditionalImports []AdditionalImport `yaml:"additional-imports,omitempty"`
	ErrorMapping      map[string]string  `yaml:"error-mapping,omitempty"`
	Client            *Client            `yaml:"client,omitempty"`

	UserTemplates map[string]string `yaml:"user-templates,omitempty"`
	UserContext   map[string]any    `yaml:"user-context,omitempty"`
}

Configuration defines code generation customizations. PackageName to generate the code under. CopyrightHeader is the header to add to the generated code. Use without //. SkipPrune indicates whether to skip pruning unused components on the generated code. Output specifies the output options for the generated code.

Filter is the configuration for filtering the paths and operations to be parsed.

AdditionalImports defines any additional Go imports to add to the generated code. ErrorMapping is the configuration for mapping the OpenAPI error responses to Go types.

The key is the spec error type name
and the value is the dotted json path to the string result.

UserTemplates is the map of user-provided templates overriding the default ones. UserContext is the map of user-provided context values to be used in templates user overrides.

func NewDefaultConfiguration

func NewDefaultConfiguration() Configuration

NewDefaultConfiguration creates a new default Configuration.

func (Configuration) Merge deprecated

func (o Configuration) Merge(other Configuration) Configuration

Merge combines two configurations, with the receiver (o) taking priority. Empty fields in o are filled with values from other. This operation is not commutative: a.Merge(b) != b.Merge(a).

Deprecated: Use WithDefaults() instead for clearer intent.

func (Configuration) OverwriteWith

func (o Configuration) OverwriteWith(other Configuration) Configuration

OverwriteWith overwrites fields in the configuration with non-empty values from other. The parameter takes priority - non-empty fields from other overwrite the receiver.

func (Configuration) WithDefaults

func (o Configuration) WithDefaults() Configuration

WithDefaults fills empty fields in the configuration with sensible defaults. The receiver takes priority - only empty/nil fields are filled with defaults from NewDefaultConfiguration().

type Constraints

type Constraints struct {
	Required       *bool
	Nullable       *bool
	ReadOnly       *bool
	WriteOnly      *bool
	MinLength      *int64
	MaxLength      *int64
	Pattern        *string
	Min            *float64
	Max            *float64
	MinItems       *int64
	MaxItems       *int64
	MinProperties  *int64
	MaxProperties  *int64
	ValidationTags []string
}

func (Constraints) Count

func (c Constraints) Count() int

Count returns the number of validation constraints. This is useful for determining which schema is "stricter" when deduplicating union elements.

func (Constraints) IsEqual

func (c Constraints) IsEqual(other Constraints) bool

type ConstraintsContext

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

type Discriminator

type Discriminator struct {
	// maps discriminator value to go type
	Mapping map[string]string

	// JSON property name that holds the discriminator
	Property string
}

func (*Discriminator) JSONTag

func (d *Discriminator) JSONTag() string

func (*Discriminator) PropertyName

func (d *Discriminator) PropertyName() string

type EnumContext

type EnumContext struct {
	Enums        []EnumDefinition
	Imports      []string
	Config       Configuration
	WithHeader   bool
	TypeRegistry TypeRegistry
}

type EnumDefinition

type EnumDefinition struct {
	Name           string
	ValueWrapper   string
	PrefixTypeName bool
	Schema         GoSchema
}

EnumDefinition holds type information for enum Schema is the scheme of a type which has a list of enum values, eg, the "container" of the enum. Name is the name of the enum's type, usually aliased from something. ValueWrapper wraps the value. It's used to conditionally apply quotes around strings. PrefixTypeName determines if the enum value is prefixed with its TypeName.

func (*EnumDefinition) GetValues

func (e *EnumDefinition) GetValues() map[string]string

GetValues generates enum names in a way to minimize global conflicts

type FieldDescriptor

type FieldDescriptor struct {
	Required bool   // Is the schema required? If not, we'll pass by pointer
	GoType   string // The Go type needed to represent the json type.
	GoName   string // The Go compatible type name for the type
	JsonName string // The json type name for the type
	IsRef    bool   // Is this schema a reference to predefined object?
}

type FilterConfig

type FilterConfig struct {
	Include FilterParamsConfig `yaml:"include"`
	Exclude FilterParamsConfig `yaml:"exclude"`
}

FilterConfig is the configuration for filtering the paths and operations to be parsed.

func (FilterConfig) IsEmpty

func (o FilterConfig) IsEmpty() bool

IsEmpty returns true if the filter is empty.

type FilterParamsConfig

type FilterParamsConfig struct {
	Paths            []string            `yaml:"paths"`
	Tags             []string            `yaml:"tags"`
	OperationIDs     []string            `yaml:"operation-ids"`
	SchemaProperties map[string][]string `yaml:"schema-properties"`
	Extensions       []string            `yaml:"extensions"`
}

FilterParamsConfig is the configuration for filtering the paths to be parsed.

func (FilterParamsConfig) IsEmpty

func (o FilterParamsConfig) IsEmpty() bool

IsEmpty returns true if the filter is empty.

type GenerateOptions

type GenerateOptions struct {
	// Client specifies whether to generate a client. Defaults to false.
	Client bool `yaml:"client"`

	// OmitDescription specifies whether to omit schema description from the spec in the generated code. Defaults to false.
	OmitDescription bool `yaml:"omit-description"`

	// DefaultIntType specifies the default integer type to use. Defaults to "int".
	DefaultIntType string `yaml:"default-int-type"`

	// AlwaysPrefixEnumValues specifies whether to always prefix enum values with the schema name. Defaults to true.
	AlwaysPrefixEnumValues bool `yaml:"always-prefix-enum-values"`

	// Validation specifies options for Validate() method generation.
	Validation ValidationOptions `yaml:"validation"`
}

type GeneratedCode

type GeneratedCode map[string]string

func Generate

func Generate(docContents []byte, cfg Configuration) (GeneratedCode, error)

Generate creates Go code from an OpenAPI document and a configuration in single file output.

func (GeneratedCode) GetCombined

func (g GeneratedCode) GetCombined() string

type GoSchema

type GoSchema struct {
	GoType                   string
	RefType                  string
	ArrayType                *GoSchema
	EnumValues               map[string]string
	Properties               []Property
	HasAdditionalProperties  bool
	AdditionalPropertiesType *GoSchema
	AdditionalTypes          []TypeDefinition
	SkipOptionalPointer      bool
	Description              string
	Constraints              Constraints

	UnionElements []UnionElement
	Discriminator *Discriminator

	DefineViaAlias   bool
	IsPrimitiveAlias bool
	OpenAPISchema    *base.Schema
}

GoSchema describes an OpenAPI schema, with lots of helper fields to use in the templating engine. GoType is the Go type that represents the schema. RefType is the type name of the schema, if it has one. ArrayType is the schema of the array element, if it's an array. EnumValues is a map of enum values. Properties is a list of fields for an object. HasAdditionalProperties is true if the object has additional properties. AdditionalPropertiesType is the type of additional properties. AdditionalTypes is a list of auxiliary types that may be needed. SkipOptionalPointer is true if the type doesn't need a * in front when it's optional. Description is the description of the element. Constraints is a struct that holds constraints for the schema. UnionElements is a list of possible elements in a oneOf/anyOf union. Discriminator describes which value is stored in a union. DefineViaAlias is true if the schema should be declared via alias.

func GenerateGoSchema

func GenerateGoSchema(schemaProxy *base.SchemaProxy, options ParseOptions) (GoSchema, error)

func (GoSchema) ContainsUnions

func (s GoSchema) ContainsUnions() bool

ContainsUnions returns true if this schema or any of its nested schemas contain union types. This is used to determine if we can use simple validate.Struct() or need custom validation logic.

func (GoSchema) GetAdditionalTypeDefs

func (s GoSchema) GetAdditionalTypeDefs() []TypeDefinition

func (GoSchema) IsAnyType

func (s GoSchema) IsAnyType() bool

IsAnyType returns true if the schema represents the 'any' type or an array of 'any'. These types don't need validation methods since they accept any value.

func (GoSchema) IsExternalRef

func (s GoSchema) IsExternalRef() bool

func (GoSchema) IsRef

func (s GoSchema) IsRef() bool

func (GoSchema) IsZero

func (s GoSchema) IsZero() bool

func (GoSchema) NeedsValidation

func (s GoSchema) NeedsValidation() bool

NeedsValidation returns true if this schema represents a type that might have a Validate() method. This includes: - Types with RefType set (references to other types, inline types) - Component references (GoType is set but not a primitive type and not a primitive alias) - Struct types (has properties) - Union types (has union elements) - Types with validation constraints

func (GoSchema) TypeDecl

func (s GoSchema) TypeDecl() string

func (GoSchema) ValidateDecl

func (s GoSchema) ValidateDecl(alias string, validatorVar string) string

ValidateDecl generates the body of the Validate() method for this schema. It returns the Go code that should appear inside the Validate() method. The alias parameter is the receiver variable name (e.g., "p" for "func (p Person) Validate()"). The validatorVar parameter is the name of the validator variable to use (e.g., "bodyTypesValidate").

func (GoSchema) ValidateDeclWithOptions

func (s GoSchema) ValidateDeclWithOptions(alias string, validatorVar string, forceSimple bool) string

ValidateDeclWithOptions generates the body of the Validate() method for this schema with options. The forceSimple parameter forces the use of simple validation (validate.Struct()) even for complex types.

type OperationDefinition

type OperationDefinition struct {
	ID          string
	Summary     string
	Description string
	Method      string
	Path        string
	PathParams  *TypeDefinition
	Header      *TypeDefinition
	Query       *RequestParametersDefinition

	TypeDefinitions []TypeDefinition
	// TODO: check if can be removed
	BodyRequired bool

	Body     *RequestBodyDefinition
	Response ResponseDefinition
}

OperationDefinition describes an Operation. ID The operation_id description from Swagger, used to generate function names. Summary string from OpenAPI spec, used to generate a comment. Description string from OpenAPI spec. Method The HTTP method for this operation. Path The path for this operation. PathParams Parameters in the path Header HTTP headers. Query Query TypeDefinitions These are all the types we need to define for this operation. BodyRequired Whether the body is required for this operation.

func (OperationDefinition) GetSuccessResponse

func (o OperationDefinition) GetSuccessResponse() string

func (OperationDefinition) HasRequestOptions

func (o OperationDefinition) HasRequestOptions() bool

func (OperationDefinition) RequiresParamObject

func (o OperationDefinition) RequiresParamObject() bool

RequiresParamObject indicates If we have parameters other than path parameters, they're bundled into an object. Returns true if we have any of those. This is used from the template engine.

func (OperationDefinition) SummaryAsComment

func (o OperationDefinition) SummaryAsComment() string

SummaryAsComment returns the Operations summary as a multi line comment

type Output

type Output struct {
	UseSingleFile bool   `yaml:"use-single-file"`
	Directory     string `yaml:"directory"`
	Filename      string `yaml:"filename"`
}

type ParameterDefinition

type ParameterDefinition struct {
	ParamName string
	In        string
	Required  bool
	Spec      *v3high.Parameter
	Schema    GoSchema
}

ParameterDefinition is a struct that represents a parameter in an operation. Name is the original json parameter name, eg param_name In is where the parameter is defined - path, header, cookie, query Required is whether the parameter is required Spec is the parsed openapi3.Parameter object GoSchema is the GoSchema object

func (ParameterDefinition) Explode

func (pd ParameterDefinition) Explode() bool

func (ParameterDefinition) GoName

func (pd ParameterDefinition) GoName() string

func (ParameterDefinition) GoVariableName

func (pd ParameterDefinition) GoVariableName() string

func (ParameterDefinition) IndirectOptional

func (pd ParameterDefinition) IndirectOptional() bool

func (ParameterDefinition) IsJson

func (pd ParameterDefinition) IsJson() bool

func (ParameterDefinition) IsPassThrough

func (pd ParameterDefinition) IsPassThrough() bool

func (ParameterDefinition) IsStyled

func (pd ParameterDefinition) IsStyled() bool

func (ParameterDefinition) TypeDef

func (pd ParameterDefinition) TypeDef() string

TypeDef is here as an adapter after a large refactoring so that I don't have to update all the templates. It returns the type definition for a parameter, without the leading '*' for optional ones.

type ParameterDefinitions

type ParameterDefinitions []ParameterDefinition

func (ParameterDefinitions) FindByName

func (p ParameterDefinitions) FindByName(name string) *ParameterDefinition

type ParameterEncoding

type ParameterEncoding struct {
	Style         string
	Explode       *bool
	Required      bool
	AllowReserved bool
}

ParameterEncoding describes the encoding options for a request body. @see https://spec.openapis.org/oas/v3.1.0#style-examples

type ParseContext

type ParseContext struct {
	Operations      []OperationDefinition
	TypeDefinitions map[SpecLocation][]TypeDefinition
	Enums           []EnumDefinition
	UnionTypes      []TypeDefinition
	Imports         []string
	ResponseErrors  []string
	TypeRegistry    TypeRegistry
}

ParseContext holds the OpenAPI models.

func CreateParseContext

func CreateParseContext(docContents []byte, cfg Configuration) (*ParseContext, []error)

CreateParseContext creates a ParseContext from an OpenAPI contents and a ParseConfig.

func CreateParseContextFromDocument

func CreateParseContextFromDocument(doc libopenapi.Document, cfg Configuration) (*ParseContext, error)

type ParseOptions

type ParseOptions struct {
	OmitDescription        bool
	DefaultIntType         string
	AlwaysPrefixEnumValues bool
	SkipValidation         bool
	// contains filtered or unexported fields
}

func (ParseOptions) AddType

func (ParseOptions) WithBaseName

func (o ParseOptions) WithBaseName(baseName string) ParseOptions

func (ParseOptions) WithCurrentTypes

func (o ParseOptions) WithCurrentTypes(currentTypes map[string]TypeDefinition) ParseOptions

func (ParseOptions) WithModel

func (o ParseOptions) WithModel(model *v3high.Document) ParseOptions

func (ParseOptions) WithNameSuffixes

func (o ParseOptions) WithNameSuffixes(suffixes []string) ParseOptions

func (ParseOptions) WithPath

func (o ParseOptions) WithPath(path []string) ParseOptions

func (ParseOptions) WithReference

func (o ParseOptions) WithReference(reference string) ParseOptions

func (ParseOptions) WithSpecLocation

func (o ParseOptions) WithSpecLocation(specLocation SpecLocation) ParseOptions

type Parser

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

Parser uses the provided ParseContext to generate Go code for the API.

func NewParser

func NewParser(cfg Configuration, ctx *ParseContext) (*Parser, error)

NewParser creates a new Parser with the provided ParseConfig and ParseContext.

func (*Parser) Parse

func (p *Parser) Parse() (GeneratedCode, error)

Parse generates Go code for the API using the provided ParseContext. It returns a map of generated code for each type of definition.

func (*Parser) ParseTemplates

func (p *Parser) ParseTemplates(templates []string, data any) (string, error)

ParseTemplates parses provided templates with the given data and returns the generated code.

type Property

type Property struct {
	GoName        string
	Description   string
	JsonFieldName string
	Schema        GoSchema
	Extensions    map[string]any
	Deprecated    bool
	Constraints   Constraints
	SensitiveData *runtime.SensitiveDataConfig
	ParentType    string // Name of the parent type (for detecting recursive references)
}

func (Property) GoTypeDef

func (p Property) GoTypeDef() string

func (Property) IsEqual

func (p Property) IsEqual(other Property) bool

func (Property) IsPointerType

func (p Property) IsPointerType() bool

IsPointerType returns true if this property's Go type is a pointer.

type RequestBodyDefinition

type RequestBodyDefinition struct {
	Name        string
	Required    bool
	Schema      GoSchema
	NameTag     string
	ContentType string
	Default     bool
	Encoding    map[string]RequestBodyEncoding
}

RequestBodyDefinition describes a request body. Name is the name of the body. Required is whether the body is required. GoSchema is the GoSchema object describing the body. NameTag is the tag used to generate the type name, i.e. JSON, in which case we will produce "JSONBody". ContentType is the content type of the body. Default is whether this is the default body type. Encoding is the encoding options for formdata.

func (RequestBodyDefinition) IsOptional

func (r RequestBodyDefinition) IsOptional() bool

func (RequestBodyDefinition) TypeDef

TypeDef returns the Go type definition for a request body

type RequestBodyEncoding

type RequestBodyEncoding struct {
	ContentType string
	Style       string
	Explode     *bool
}

RequestBodyEncoding describes the encoding options for a request body. @see https://spec.openapis.org/oas/v3.1.0#fixed-fields-12

type RequestParametersDefinition

type RequestParametersDefinition struct {
	Name     string
	Encoding map[string]ParameterEncoding
	Params   []ParameterDefinition
	TypeDef  TypeDefinition
}

type ResponseContentDefinition

type ResponseContentDefinition struct {
	Schema      GoSchema
	ContentType string
	NameTag     string

	ResponseName string
	Description  string
	Ref          string
	IsSuccess    bool
	StatusCode   int
	Headers      map[string]GoSchema
}

ResponseContentDefinition describes Operation response. GoSchema is the schema describing this content. ContentType is the content type corresponding to the body, eg, application/json. NameTag is the tag for the type name, such as JSON, in which case we will produce "Response200JSONContent". ResponseName is the name of the response. Description is the description of the response. Ref is the reference to the response. IsSuccess is true if the response is a success response.

type ResponseDefinition

type ResponseDefinition struct {
	SuccessStatusCode int
	Success           *ResponseContentDefinition
	Error             *ResponseContentDefinition
	All               map[int]*ResponseContentDefinition
}

ResponseDefinition describes a response.

type SchemaDescriptor

type SchemaDescriptor struct {
	Fields                   []FieldDescriptor
	HasAdditionalProperties  bool
	AdditionalPropertiesType string
}

SchemaDescriptor describes a GoSchema, a type definition.

type SpecLocation

type SpecLocation string
const (
	SpecLocationPath     SpecLocation = "path"
	SpecLocationQuery    SpecLocation = "query"
	SpecLocationHeader   SpecLocation = "header"
	SpecLocationBody     SpecLocation = "body"
	SpecLocationResponse SpecLocation = "response"
	SpecLocationSchema   SpecLocation = "schema"
	SpecLocationUnion    SpecLocation = "union"
)

type TplOperationsContext

type TplOperationsContext struct {
	Operations []OperationDefinition
	Imports    []string
	Config     Configuration
	WithHeader bool
}

TplOperationsContext is the context passed to templates to generate client code.

type TplTypeContext

type TplTypeContext struct {
	Types []TypeDefinition

	// Map of type names to schemas for cross-referencing
	TypeSchemaMap  map[string]GoSchema
	Imports        []string
	SpecLocation   string
	Config         Configuration
	WithHeader     bool
	ResponseErrors map[string]bool
}

TplTypeContext is the context passed to templates to generate code for type definitions.

type TypeDefinition

type TypeDefinition struct {
	Name             string
	JsonName         string
	Schema           GoSchema
	SpecLocation     SpecLocation
	NeedsMarshaler   bool
	HasSensitiveData bool
}

TypeDefinition describes a Go type definition in generated code. Name is the name of the type in the schema, eg, type <...> Person. JsonName is the name of the corresponding JSON description, as it will sometimes differ due to invalid characters. Schema is the GoSchema object used to populate the type description. SpecLocation indicates where in the OpenAPI spec this type was defined. NeedsMarshaler indicates whether this type needs a custom marshaler/unmarshaler. HasSensitiveData indicates whether this type has any properties marked as sensitive.

func (TypeDefinition) GetErrorResponse

func (t TypeDefinition) GetErrorResponse(errTypes map[string]string, alias string, typeSchemaMap map[string]GoSchema) string

GetErrorResponse generates a Go code snippet that returns an error response based on the predefined spec error path.

func (TypeDefinition) IsAlias

func (t TypeDefinition) IsAlias() bool

func (TypeDefinition) IsOptional

func (t TypeDefinition) IsOptional() bool

type TypeRegistry

type TypeRegistry map[string]int

TypeRegistry is a registry of type names.

func (TypeRegistry) GetName

func (tr TypeRegistry) GetName(name string) string

GetName returns a unique name for the given type name.

type UnionElement

type UnionElement struct {
	// TypeName is the Go type name (e.g., "User", "string", "int")
	TypeName string

	// Schema contains the full schema including constraints (minLength, minimum, etc.)
	Schema GoSchema
}

UnionElement describes a union element with its type and schema (including constraints).

func (UnionElement) Method

func (u UnionElement) Method() string

Method generates union method name for template functions `As/From`.

func (UnionElement) String

func (u UnionElement) String() string

String returns the type name for backward compatibility with templates

type ValidationOptions

type ValidationOptions struct {
	// Skip specifies whether to skip Validation method generation. Defaults to false.
	Skip bool `yaml:"skip"`

	// Simple specifies whether to use the simple validation approach. Defaults to false.
	// Simple validation uses validate.Struct() for all types, whereas complex validation generates custom Validate() methods.
	Simple bool `yaml:"simple"`

	// Response specifies whether to generate Validate() methods for response types.
	// Useful for contract testing to ensure responses match the OpenAPI spec. Defaults to false.
	Response bool `yaml:"response"`
}

Jump to

Keyboard shortcuts

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