{"modulePath":"github.com/uptrace/oapi-codegen-dd/v3","version":"v3.75.7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package codegen\n\n## Variables\n\n```go\nvar (\n\tErrOperationNameEmpty                        = errors.New(\"operation name cannot be an empty string\")\n\tErrRequestPathEmpty                          = errors.New(\"request path cannot be an empty string\")\n\tErrMergingSchemasWithDifferentUniqueItems    = errors.New(\"merging two schemas with different UniqueItems\")\n\tErrMergingSchemasWithDifferentExclusiveMin   = errors.New(\"merging two schemas with different ExclusiveMin\")\n\tErrMergingSchemasWithDifferentExclusiveMax   = errors.New(\"merging two schemas with different ExclusiveMax\")\n\tErrMergingSchemasWithDifferentNullable       = errors.New(\"merging two schemas with different Nullable\")\n\tErrMergingSchemasWithDifferentReadOnly       = errors.New(\"merging two schemas with different ReadOnly\")\n\tErrMergingSchemasWithDifferentWriteOnly      = errors.New(\"merging two schemas with different WriteOnly\")\n\tErrTransitiveMergingAllOfSchema1             = errors.New(\"error transitive merging AllOf on schema 1\")\n\tErrTransitiveMergingAllOfSchema2             = errors.New(\"error transitive merging AllOf on schema 2\")\n\tErrMergingSchemasWithDifferentDefaults       = errors.New(\"merging two sets of defaults is undefined\")\n\tErrMergingSchemasWithDifferentFormats        = errors.New(\"can not merge incompatible formats\")\n\tErrMergingSchemasWithDifferentDiscriminators = errors.New(\"merging two schemas with discriminators is not supported\")\n\tErrMergingSchemasWithAdditionalProperties    = errors.New(\"merging two schemas with additional properties, this is unhandled\")\n\tErrAmbiguousDiscriminatorMapping             = errors.New(\"ambiguous discriminator.mapping: please replace inlined object with $ref\")\n\tErrDiscriminatorNotAllMapped                 = errors.New(\"discriminator: not all schemas were mapped\")\n\tErrEmptySchema                               = errors.New(\"empty schema\")\n\tErrEmptyReferencePath                        = errors.New(\"empty reference path\")\n\tErrHandlerKindRequired                       = errors.New(\"handler kind is required\")\n\tErrHandlerKindUnsupported                    = errors.New(\"unsupported handler kind\")\n\tErrServerHandlerPackageRequired              = errors.New(\"server handler-package is required when server generation is enabled\")\n\tErrServerRequiresService                     = errors.New(\"server generation requires service generation: add 'service: {}' to handler config\")\n\tErrInvalidAdditionalTag                      = errors.New(\"invalid additional tag name: must not be empty or contain spaces, quotes, or colons\")\n)\n```\n\n```go\nvar TemplateFunctions = template.FuncMap{\n\t\"genTypeName\":    nameNormalizer,\n\t\"lcFirst\":        lowercaseFirstCharacter,\n\t\"ucFirst\":        uppercaseFirstCharacter,\n\t\"caps\":           strings.ToUpper,\n\t\"lower\":          strings.ToLower,\n\t\"snake\":          strcase.ToSnake,\n\t\"toGoComment\":    stringToGoCommentWithPrefix,\n\t\"ternary\":        ternary,\n\t\"join\":           join,\n\t\"fst\":            fst,\n\t\"hasPrefix\":      strings.HasPrefix,\n\t\"hasSuffix\":      strings.HasSuffix,\n\t\"contains\":       strings.Contains,\n\t\"str\":            str,\n\t\"dict\":           dict,\n\t\"slice\":          func() []any { return []any{} },\n\t\"escapeGoString\": escapeGoString,\n\t\"append\": func(slice []any, val any) []any {\n\t\treturn append(slice, val)\n\t},\n\t\"filterOmitEmpty\": filterOmitEmpty,\n\t\"deref\":           derefBool,\n\t\"replace\":         strings.ReplaceAll,\n}\n```\nTemplateFunctions is passed to the template engine, and we can call each function here by keyName from the template code.\n\n## Functions\n\n```go\nfunc CreateDocument(docContents []byte, cfg Configuration) (libopenapi.Document, error)\n```\n\n```go\nfunc CreateOperationID(method, path, initial string) (string, error)\n```\nCreateOperationID generates a unique operation ID based on the HTTP method and path. If the initial value is provided, it will be used. The resulting operation ID is a camel-cased string.\n\n```go\nfunc FormatCode(src string) (string, error)\n```\nFormatCode formats the provided Go code by optimizing imports and running gofmt.\n\n```go\nfunc IsScaffoldFile(name string) bool\n```\nIsScaffoldFile returns true if the file name indicates a scaffold file.\n\n```go\nfunc LoadDocumentFromContents(contents []byte, basePath ...string) (libopenapi.Document, error)\n```\nLoadDocumentFromContents creates a libopenapi Document from raw bytes. An optional basePath can be provided to resolve relative $ref file references. If provided, basePath should be an absolute path to the directory containing the spec file.\n\n```go\nfunc ScaffoldFileName(name string) string\n```\nScaffoldFileName returns the actual file name without the scaffold prefix.\n\n```go\nfunc UppercaseFirstCharacter(str string) string\n```\nUppercaseFirstCharacter 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.\n\n## Types\n\n```go\ntype AdditionalImport struct {\n\tAlias   string `yaml:\"alias,omitempty\"`\n\tPackage string `yaml:\"package\"`\n}\n```\n\n```go\ntype Client struct {\n\tName    string        `yaml:\"name\"`\n\tTimeout time.Duration `yaml:\"timeout\"`\n}\n```\n\n```go\ntype Configuration struct {\n\tPackageName     string  `yaml:\"package\"`\n\tCopyrightHeader string  `yaml:\"copyright-header\"`\n\tSkipPrune       bool    `yaml:\"skip-prune\"`\n\tOutput          *Output `yaml:\"output\"`\n\n\tGenerate *GenerateOptions `yaml:\"generate\"`\n\tFilter   FilterConfig     `yaml:\"filter,omitempty\"`\n\tOverlay  *OverlayOptions  `yaml:\"overlay,omitempty\"`\n\n\tAdditionalImports []AdditionalImport `yaml:\"additional-imports,omitempty\"`\n\tErrorMapping      map[string]string  `yaml:\"error-mapping,omitempty\"`\n\tClient            *Client            `yaml:\"client,omitempty\"`\n\n\tUserTemplates map[string]string `yaml:\"user-templates,omitempty\"`\n\tUserContext   map[string]any    `yaml:\"user-context,omitempty\"`\n\n\t// BasePath is the directory used to resolve relative $ref file references.\n\t// When set, external file references like './common.yaml#/...' will be resolved\n\t// relative to this directory. Typically set to the directory containing the spec file.\n\tBasePath string `yaml:\"base-path,omitempty\"`\n}\n```\nConfiguration 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.\n\nFilter is the configuration for filtering the paths and operations to be parsed.\n\nAdditionalImports defines any additional Go imports to add to the generated code. ErrorMapping is the configuration for mapping the OpenAPI error responses to Go types.\n\n\tThe key is the spec error type name\n\tand the value is the dotted json path to the string result.\n\nUserTemplates 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.\n\n```go\nfunc NewDefaultConfiguration() Configuration\n```\nNewDefaultConfiguration creates a new default Configuration.\n\n```go\nfunc (o Configuration) Merge(other Configuration) Configuration\n```\nMerge 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).\n\nDeprecated: Use WithDefaults() instead for clearer intent.\n\n```go\nfunc (o Configuration) OverwriteWith(other Configuration) Configuration\n```\nOverwriteWith overwrites fields in the configuration with non-empty values from other. The parameter takes priority - non-empty fields from other overwrite the receiver.\n\n```go\nfunc (o Configuration) WithDefaults() Configuration\n```\nWithDefaults fills empty fields in the configuration with sensible defaults. The receiver takes priority - only empty/nil fields are filled with defaults from NewDefaultConfiguration().\n\n```go\ntype Constraints struct {\n\tRequired       *bool\n\tNullable       *bool\n\tReadOnly       *bool\n\tWriteOnly      *bool\n\tMinLength      *int64\n\tMaxLength      *int64\n\tPattern        *string\n\tMin            *float64\n\tMax            *float64\n\tMinItems       *int64\n\tMaxItems       *int64\n\tMinProperties  *int64\n\tMaxProperties  *int64\n\tValidationTags []string\n}\n```\n\n```go\nfunc (c Constraints) Count() int\n```\nCount returns the number of validation constraints. This is useful for determining which schema is \"stricter\" when deduplicating union elements.\n\n```go\nfunc (c Constraints) IsEqual(other Constraints) bool\n```\n\n```go\ntype ConstraintsContext struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype Discriminator struct {\n\t// maps discriminator value to go type\n\tMapping map[string]string\n\n\t// JSON property name that holds the discriminator\n\tProperty string\n}\n```\n\n```go\nfunc (d *Discriminator) JSONTag() string\n```\n\n```go\nfunc (d *Discriminator) PropertyName() string\n```\n\n```go\ntype EnumContext struct {\n\tEnums       []EnumDefinition\n\tImports     []string\n\tConfig      Configuration\n\tWithHeader  bool\n\tTypeTracker *TypeTracker\n}\n```\n\n```go\ntype EnumDefinition struct {\n\tName           string\n\tValueWrapper   string\n\tPrefixTypeName bool\n\tSchema         GoSchema\n\tValues         []EnumValue\n\tSpecLocation   SpecLocation\n}\n```\nEnumDefinition 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. EnumDefinition represents an enum type. ValueWrapper wraps the value. It's used to conditionally apply quotes around strings. PrefixTypeName determines if the enum value is prefixed with its TypeName. Values contains the final constant names mapped to their values (computed in filterOutEnums). SpecLocation indicates where in the OpenAPI spec this enum was defined.\n\n```go\ntype EnumValue struct {\n\tName  string\n\tValue string\n}\n```\nEnumValue represents a single enum constant.\n\n```go\ntype FieldDescriptor struct {\n\tRequired bool   // Is the schema required? If not, we'll pass by pointer\n\tGoType   string // The Go type needed to represent the json type.\n\tGoName   string // The Go compatible type name for the type\n\tJsonName string // The json type name for the type\n\tIsRef    bool   // Is this schema a reference to predefined object?\n}\n```\n\n```go\ntype FilterConfig struct {\n\tInclude FilterParamsConfig `yaml:\"include\"`\n\tExclude FilterParamsConfig `yaml:\"exclude\"`\n}\n```\nFilterConfig is the configuration for filtering the paths and operations to be parsed.\n\n```go\nfunc (o FilterConfig) IsEmpty() bool\n```\nIsEmpty returns true if the filter is empty.\n\n```go\ntype FilterParamsConfig struct {\n\tPaths            []string            `yaml:\"paths\"`\n\tTags             []string            `yaml:\"tags\"`\n\tOperationIDs     []string            `yaml:\"operation-ids\"`\n\tWebhooks         []string            `yaml:\"webhooks\"`\n\tSchemaProperties map[string][]string `yaml:\"schema-properties\"`\n\tExtensions       []string            `yaml:\"extensions\"`\n}\n```\nFilterParamsConfig is the configuration for filtering the paths to be parsed.\n\n```go\nfunc (o FilterParamsConfig) IsEmpty() bool\n```\nIsEmpty returns true if the filter is empty.\n\n```go\ntype GenerateOptions struct {\n\t// Client specifies whether to generate the classic client - one method\n\t// per operation that returns the picked 2xx body type directly (e.g.\n\t// `func (c *Client) UploadDocument(...) (*DocumentStored, error)`).\n\t// Use this when callers only need the response body and the operation\n\t// has a single documented success status. Headers and non-picked 2xx\n\t// bodies are not exposed by this style; for that, use\n\t// ClientWithResponse instead, or both together.\n\t//\n\t// Combinations with ClientWithResponse:\n\t//   - client: true, client-with-response: false → classic only\n\t//   - client: false, client-with-response: true → envelope only\n\t//   - client: true, client-with-response: true  → both styles, combined\n\t//                                                 into a single ClientInterface\n\t//\n\t// Defaults to false.\n\tClient bool `yaml:\"client\"`\n\n\t// ClientWithResponse specifies whether to generate `\u003cOp\u003eWithResponse`\n\t// sibling functions that return a typed envelope: one `JSON\u003cstatus\u003e`\n\t// field per documented response, one `Headers\u003cstatus\u003e` typed struct per\n\t// status that declares headers, plus `HTTPResponse *http.Response` for\n\t// raw access (undocumented headers, status string, etc.). Use this when\n\t// an operation has multiple 2xx statuses with different bodies (e.g.\n\t// 201 sync + 202 queued), or when callers need typed access to headers\n\t// like Location or Retry-After.\n\t//\n\t// Additive to Client: when both flags are true, the generated\n\t// ClientInterface lists both `\u003cOp\u003e` and `\u003cOp\u003eWithResponse` methods so a\n\t// single mock or test double covers both shapes.\n\t//\n\t// Defaults to false.\n\tClientWithResponse bool `yaml:\"client-with-response\"`\n\n\t// Models specifies whether to generate model types. Defaults to true.\n\t// Set to false when models are generated in a separate package.\n\tModels *bool `yaml:\"models,omitempty\"`\n\n\t// Handler specifies options for handler/server code generation.\n\t// If nil, no handler code is generated.\n\tHandler *HandlerOptions `yaml:\"handler,omitempty\"`\n\n\t// MCPServer specifies options for MCP (Model Context Protocol) server generation.\n\t// If set, generates MCP tools that wrap the generated client for AI assistant integration.\n\t// Requires client generation to be enabled.\n\tMCPServer *MCPServerOptions `yaml:\"mcp-server,omitempty\"`\n\n\t// AutoExtraTags specifies automatic tag generation from OpenAPI schema fields.\n\t// Key is the Go struct tag name, value is the OpenAPI schema field to extract.\n\t// Example: {\"jsonschema\": \"description\", \"validate\": \"x-validation\"}\n\tAutoExtraTags map[string]string `yaml:\"auto-extra-tags,omitempty\"`\n\n\t// OmitDescription specifies whether to omit schema description from the spec in the generated code. Defaults to false.\n\tOmitDescription bool `yaml:\"omit-description\"`\n\n\t// DefaultIntType specifies the default integer type to use. Defaults to \"int\".\n\tDefaultIntType string `yaml:\"default-int-type\"`\n\n\t// AlwaysPrefixEnumValues specifies whether to always prefix enum values with the schema name. Defaults to true.\n\tAlwaysPrefixEnumValues bool `yaml:\"always-prefix-enum-values\"`\n\n\t// AdditionalTags specifies additional struct tags to emit on generated fields,\n\t// mirroring the json tag value. For example, [\"yaml\"] emits yaml:\"field_name,omitempty\"\n\t// alongside the json tag. Per-property x-oapi-codegen-extra-tags take priority.\n\tAdditionalTags []string `yaml:\"additional-tags\"`\n\n\t// Validation specifies options for Validate() method generation.\n\tValidation ValidationOptions `yaml:\"validation\"`\n}\n```\n\n```go\nfunc (o GenerateOptions) Validate() error\n```\nValidate returns an error if any generate options are invalid.\n\n```go\ntype GeneratedCode map[string]string\n```\nGeneratedCode is a map of file names to generated code content. Scaffold files (service, middleware, server/main) are prefixed with \"scaffold:\" in the key.\n\n```go\nfunc Generate(docContents []byte, cfg Configuration) (GeneratedCode, error)\n```\nGenerate creates Go code from an OpenAPI document and a configuration in single file output.\n\n```go\nfunc (g GeneratedCode) GetCombined() string\n```\nGetCombined returns the combined single-file output (the \"all\" key).\n\n```go\ntype GoSchema struct {\n\tGoType                   string\n\tRefType                  string\n\tArrayType                *GoSchema\n\tEnumValues               map[string]string\n\tProperties               []Property\n\tHasAdditionalProperties  bool\n\tAdditionalPropertiesType *GoSchema\n\tAdditionalTypes          []TypeDefinition\n\tSkipOptionalPointer      bool\n\tDescription              string\n\tConstraints              Constraints\n\n\tUnionElements []UnionElement\n\tDiscriminator *Discriminator\n\t// True if this schema is a struct wrapper around a union (embedded Either or union field)\n\tIsUnionWrapper bool\n\n\t// True if this union was generated from an if/then/else schema.\n\t// Uses runtime.Conditional instead of runtime.Either.\n\tIsConditional bool\n\n\tDefineViaAlias   bool\n\tIsPrimitiveAlias bool\n\tOpenAPISchema    *base.Schema\n}\n```\nGoSchema 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.\n\n```go\nfunc GenerateGoSchema(schemaProxy *base.SchemaProxy, options ParseOptions) (GoSchema, error)\n```\n\n```go\nfunc (s GoSchema) ContainsUnions() bool\n```\nContainsUnions 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.\n\n```go\nfunc (s GoSchema) Format() string\n```\nFormat returns the OpenAPI format of the schema (e.g., \"uuid\", \"date-time\", \"date\"). Returns empty string if no format is specified.\n\n```go\nfunc (s GoSchema) GetAdditionalTypeDefs() []TypeDefinition\n```\n\n```go\nfunc (s GoSchema) IsAnyType() bool\n```\nIsAnyType 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.\n\n```go\nfunc (s GoSchema) IsExternalRef() bool\n```\n\n```go\nfunc (s GoSchema) IsRef() bool\n```\n\n```go\nfunc (s GoSchema) IsZero() bool\n```\n\n```go\nfunc (s GoSchema) NeedsValidation() bool\n```\nNeedsValidation 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\n\n```go\nfunc (s GoSchema) TypeDecl() string\n```\n\n```go\nfunc (s GoSchema) TypeDeclWithNullable() string\n```\nTypeDeclWithNullable returns the type declaration with a pointer prefix if the schema is explicitly nullable (via nullable: true or type includes \"null\"). This is used for additionalProperties value types where we need to represent null values.\n\n```go\nfunc (s GoSchema) ValidateDecl(alias string, validatorVar string) string\n```\nValidateDecl 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\").\n\n```go\nfunc (s GoSchema) ValidateDeclWithOptions(alias string, validatorVar string, forceSimple bool) string\n```\nValidateDeclWithOptions 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.\n\n```go\ntype HandlerKind string\n```\nHandlerKind specifies the router/framework to generate handler code for.\n\n```go\nconst (\n\tHandlerKindBeego      HandlerKind = \"beego\"\n\tHandlerKindChi        HandlerKind = \"chi\"\n\tHandlerKindEcho       HandlerKind = \"echo\"\n\tHandlerKindEchoV5     HandlerKind = \"echo-v5\"\n\tHandlerKindFastHTTP   HandlerKind = \"fasthttp\"\n\tHandlerKindFiber      HandlerKind = \"fiber\"\n\tHandlerKindGin        HandlerKind = \"gin\"\n\tHandlerKindGoFrame    HandlerKind = \"goframe\"\n\tHandlerKindGoZero     HandlerKind = \"go-zero\"\n\tHandlerKindGorillaMux HandlerKind = \"gorilla-mux\"\n\tHandlerKindHertz      HandlerKind = \"hertz\"\n\tHandlerKindIris       HandlerKind = \"iris\"\n\tHandlerKindKratos     HandlerKind = \"kratos\"\n\tHandlerKindStdHTTP    HandlerKind = \"std-http\"\n)\n```\n\n```go\nfunc (k HandlerKind) IsValid() bool\n```\nIsValid returns true if the handler kind is a supported value.\n\n```go\ntype HandlerOptions struct {\n\t// Name is the name of the service interface. Defaults to \"Service\".\n\tName string `yaml:\"name\"`\n\n\t// Kind specifies the router/framework to generate for. Defaults to \"chi\".\n\t// Supported values: \"chi\"\n\tKind HandlerKind `yaml:\"kind\"`\n\n\t// Validation specifies options for request/response validation in handlers.\n\tValidation HandlerValidation `yaml:\"validation\"`\n\n\t// ModelsPackageAlias is the package alias to prefix model types with.\n\t// Used when models are generated separately (generate.models: false).\n\t// Example: \"types\" will generate \"types.User\" instead of \"User\".\n\tModelsPackageAlias string `yaml:\"models-package-alias\"`\n\n\t// MultipartMaxMemory is the maximum memory in MB for multipart form parsing.\n\t// Defaults to 32MB (matching Go stdlib). Files exceeding this are stored in temp files.\n\tMultipartMaxMemory int `yaml:\"multipart-max-memory\"`\n\n\t// Output specifies output for scaffolded handler files (service.go, middleware.go).\n\t// Falls back to root output if nil.\n\tOutput *ScaffoldOutput `yaml:\"output\"`\n\n\t// Service specifies options for generating service.go scaffold.\n\t// If nil, no service scaffold is generated.\n\tService *ServiceOptions `yaml:\"service\"`\n\n\t// Middleware specifies options for generating middleware.go.\n\t// If nil, no middleware is generated.\n\tMiddleware *MiddlewareOptions `yaml:\"middleware\"`\n\n\t// Server specifies options for generating a runnable server main.go.\n\t// If nil, no server is generated.\n\tServer *ServerOptions `yaml:\"server\"`\n}\n```\nHandlerOptions specifies options for handler/server code generation.\n\n```go\nfunc (o HandlerOptions) ResolveScaffoldOutput(rootOutput *Output) ScaffoldOutput\n```\nResolveScaffoldOutput returns the output config for scaffold files (service.go, middleware.go). Uses handler.output if set, otherwise falls back to root output.\n\n```go\nfunc (o HandlerOptions) ResolveServerOutput() ScaffoldOutput\n```\nResolveServerOutput returns the output config for server/main.go. Uses server.directory if set, otherwise defaults to \"server\". Package is always \"main\" for server.\n\n```go\nfunc (o HandlerOptions) Validate() error\n```\nValidate returns an error if the handler options are invalid.\n\n```go\ntype HandlerValidation struct {\n\t// Request enables validation of incoming requests. Defaults to false.\n\tRequest bool `yaml:\"request\"`\n\n\t// Response enables validation of outgoing responses. Defaults to false.\n\t// Useful for contract testing.\n\tResponse bool `yaml:\"response\"`\n}\n```\nHandlerValidation specifies validation options for handlers.\n\n```go\ntype MCPExtension struct {\n\t// Skip excludes this operation from MCP tool generation.\n\t// nil means not set (use default behavior), true means skip, false means include.\n\tSkip *bool `json:\"skip,omitempty\" yaml:\"skip,omitempty\"`\n\n\t// Name overrides the MCP tool name (default: operationId)\n\tName string `json:\"name,omitempty\" yaml:\"name,omitempty\"`\n\n\t// Description overrides the MCP tool description (default: operation summary)\n\tDescription string `json:\"description,omitempty\" yaml:\"description,omitempty\"`\n}\n```\nMCPExtension configures MCP tool generation for an operation.\n\n```go\nfunc (e *MCPExtension) ShouldSkip(defaultSkip bool) bool\n```\nShouldSkip returns whether this operation should be skipped based on the extension and the default-skip configuration.\n\n```go\ntype MCPServerOptions struct {\n\t// DefaultSkip specifies whether operations are skipped by default.\n\t// If true, operations are excluded unless x-mcp.skip is explicitly false.\n\t// If false (default), operations are included unless x-mcp.skip is true.\n\tDefaultSkip bool `yaml:\"default-skip\"`\n}\n```\nMCPServerOptions specifies options for MCP (Model Context Protocol) server generation. MCP servers expose API operations as tools that AI assistants (Claude, Cursor, etc.) can invoke. The generated code wraps the generated client to make real API calls.\n\n```go\ntype MiddlewareOptions struct {\n}\n```\nMiddlewareOptions specifies options for generating middleware.go. Currently empty but allows for future extensibility.\n\n```go\ntype OperationDefinition struct {\n\tID          string\n\tSummary     string\n\tDescription string\n\tMethod      string\n\tPath        string\n\tPathParams  *TypeDefinition\n\tHeader      *RequestParametersDefinition\n\tQuery       *RequestParametersDefinition\n\n\tTypeDefinitions []TypeDefinition\n\t// TODO: check if can be removed\n\tBodyRequired bool\n\n\tBody     *RequestBodyDefinition\n\tResponse ResponseDefinition\n\n\t// MCP contains x-mcp extension configuration for MCP tool generation\n\tMCP *MCPExtension\n\n\t// WithResponseTypeName is the name of the envelope wrapper struct emitted\n\t// when generate.client-with-response is true (e.g. \"UploadDocumentResp\").\n\t// Empty when the feature is disabled.\n\tWithResponseTypeName string\n\n\t// HeaderTypeNames maps each documented status code to the name of the\n\t// per-status typed header struct emitted alongside the envelope (e.g.\n\t// 201 -\u003e \"UploadDocumentResp201Headers\"). Only populated for statuses\n\t// that declare at least one header in the spec.\n\tHeaderTypeNames map[int]string\n}\n```\nOperationDefinition 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.\n\n```go\nfunc (o OperationDefinition) GetSuccessResponse() string\n```\n\n```go\nfunc (o OperationDefinition) HasRequestOptions() bool\n```\n\n```go\nfunc (o OperationDefinition) RequiresParamObject() bool\n```\nRequiresParamObject 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.\n\n```go\nfunc (o OperationDefinition) SummaryAsComment() string\n```\nSummaryAsComment returns the Operations summary as a multi line comment\n\n```go\ntype Output struct {\n\tUseSingleFile bool   `yaml:\"use-single-file\"`\n\tDirectory     string `yaml:\"directory\"`\n\tFilename      string `yaml:\"filename\"`\n\tSkipFmt       bool   `yaml:\"skip-fmt\"`\n}\n```\n\n```go\ntype OverlayOptions struct {\n\t// Sources is a list of overlay files to apply to the OpenAPI spec.\n\t// Each source can be a file path or URL. Overlays are applied in order.\n\tSources []string `yaml:\"sources\"`\n}\n```\nOverlayOptions specifies OpenAPI Overlay files to apply to the spec before generation. See [https://spec.openapis.org/overlay/v1.0.0.html](https://spec.openapis.org/overlay/v1.0.0.html) for the Overlay specification.\n\n```go\ntype ParameterDefinition struct {\n\tParamName string\n\tIn        string\n\tRequired  bool\n\tSpec      *v3high.Parameter\n\tSchema    GoSchema\n\t// contains filtered or unexported fields\n}\n```\nParameterDefinition 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\n\n```go\nfunc (pd ParameterDefinition) Explode() bool\n```\n\n```go\nfunc (pd ParameterDefinition) GoName() string\n```\n\n```go\nfunc (pd ParameterDefinition) GoVariableName() string\n```\n\n```go\nfunc (pd ParameterDefinition) IsJson() bool\n```\n\n```go\nfunc (pd ParameterDefinition) IsPassThrough() bool\n```\n\n```go\nfunc (pd ParameterDefinition) IsPointerType() bool\n```\nIsPointerType returns true if this parameter's field in the generated struct is a pointer. This matches the logic used in generateParamsTypes() when creating Property objects.\n\n```go\nfunc (pd ParameterDefinition) IsStyled() bool\n```\n\n```go\nfunc (pd ParameterDefinition) TypeDef() string\n```\nTypeDef 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.\n\n```go\ntype ParameterDefinitions []ParameterDefinition\n```\n\n```go\nfunc (p ParameterDefinitions) FindByName(name string) *ParameterDefinition\n```\n\n```go\ntype ParameterEncoding struct {\n\tStyle         string\n\tExplode       *bool\n\tRequired      bool\n\tAllowReserved bool\n}\n```\nParameterEncoding describes the encoding options for a request body. @see [https://spec.openapis.org/oas/v3.1.0#style-examples](https://spec.openapis.org/oas/v3.1.0#style-examples)\n\n```go\ntype ParseContext struct {\n\tOperations      []OperationDefinition\n\tTypeDefinitions map[SpecLocation][]TypeDefinition\n\tEnums           []EnumDefinition\n\tUnionTypes      []TypeDefinition\n\tImports         []string\n\tResponseErrors  []string\n\tTypeTracker     *TypeTracker\n}\n```\nParseContext holds the OpenAPI models.\n\n```go\nfunc CreateParseContext(docContents []byte, cfg Configuration) (*ParseContext, []error)\n```\nCreateParseContext creates a ParseContext from an OpenAPI contents and a ParseConfig.\n\n```go\nfunc CreateParseContextFromDocument(doc libopenapi.Document, cfg Configuration) (*ParseContext, error)\n```\n\n```go\nfunc CreateParseContextFromModel(model *v3high.Document, cfg Configuration) (*ParseContext, error)\n```\nCreateParseContextFromModel creates a ParseContext from an already-built OpenAPI v3 model. This is useful when the model has been modified in-place, and you want to avoid rebuilding it from the document.\n\n```go\ntype ParseOptions struct {\n\tOmitDescription        bool\n\tDefaultIntType         string\n\tAlwaysPrefixEnumValues bool\n\tAdditionalTags         []string\n\tSkipValidation         bool\n\n\t// ErrorMapping maps response type names to the field that should be used\n\t// for the Error() method. When a response type has error mapping configured,\n\t// it cannot be an alias (aliases don't support methods).\n\tErrorMapping map[string]string\n\n\t// AutoExtraTags specifies automatic tag generation from OpenAPI schema fields.\n\t// Key is the Go struct tag name, value is the OpenAPI schema field to extract.\n\tAutoExtraTags map[string]string\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (o ParseOptions) WithPath(path []string) ParseOptions\n```\n\n```go\nfunc (o ParseOptions) WithReference(reference string) ParseOptions\n```\n\n```go\nfunc (o ParseOptions) WithSpecLocation(specLocation SpecLocation) ParseOptions\n```\n\n```go\ntype Parser struct {\n\t// contains filtered or unexported fields\n}\n```\nParser uses the provided ParseContext to generate Go code for the API.\n\n```go\nfunc NewParser(cfg Configuration, ctx *ParseContext) (*Parser, error)\n```\nNewParser creates a new Parser with the provided ParseConfig and ParseContext.\n\n```go\nfunc (p *Parser) Parse() (GeneratedCode, error)\n```\nParse generates Go code for the API using the provided ParseContext. It returns a map of generated code for each type of definition.\n\n```go\nfunc (p *Parser) ParseTemplates(templates []string, data any) (string, error)\n```\nParseTemplates parses provided templates with the given data and returns the generated code.\n\n```go\ntype Property struct {\n\tGoName        string\n\tDescription   string\n\tJsonFieldName string\n\tSchema        GoSchema\n\tExtensions    map[string]any\n\tDeprecated    bool\n\tConstraints   Constraints\n\tSensitiveData *runtime.SensitiveDataConfig\n\tParentType    string // Name of the parent type (for detecting recursive references)\n}\n```\n\n```go\nfunc (p Property) GoTypeDef() string\n```\n\n```go\nfunc (p Property) GoVariableName() string\n```\nGoVariableName returns a safe Go variable name for this property. It handles Go keywords by prefixing with \"p\" and numbers by prefixing with \"n\". It also avoids reserved template variable names.\n\n```go\nfunc (p Property) IsEqual(other Property) bool\n```\n\n```go\nfunc (p Property) IsFile() bool\n```\nIsFile returns true if this property is a file type (format: binary).\n\n```go\nfunc (p Property) IsPointerType() bool\n```\nIsPointerType returns true if this property's Go type is a pointer.\n\n```go\ntype RequestBodyDefinition struct {\n\tName        string\n\tRequired    bool\n\tSchema      GoSchema\n\tNameTag     string\n\tContentType string\n\tDefault     bool\n\tEncoding    map[string]RequestBodyEncoding\n}\n```\nRequestBodyDefinition 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.\n\n```go\nfunc (r RequestBodyDefinition) IsOptional() bool\n```\n\n```go\nfunc (r RequestBodyDefinition) TypeDef(opID string) TypeDefinition\n```\nTypeDef returns the Go type definition for a request body\n\n```go\ntype RequestBodyEncoding struct {\n\tContentType string\n\tStyle       string\n\tExplode     *bool\n}\n```\nRequestBodyEncoding describes the encoding options for a request body. @see [https://spec.openapis.org/oas/v3.1.0#fixed-fields-12](https://spec.openapis.org/oas/v3.1.0#fixed-fields-12)\n\n```go\ntype RequestParametersDefinition struct {\n\tName     string\n\tEncoding map[string]ParameterEncoding\n\tParams   []ParameterDefinition\n\tTypeDef  TypeDefinition\n}\n```\n\n```go\ntype ResponseContentDefinition struct {\n\tSchema      GoSchema\n\tContentType string\n\tNameTag     string\n\n\tResponseName string\n\tDescription  string\n\tRef          string\n\tIsSuccess    bool\n\tStatusCode   int\n\tHeaders      map[string]GoSchema\n\t// IsRaw is true for unsupported content types (XML, form-urlencoded, etc.)\n\t// that require the user to handle marshaling manually.\n\tIsRaw bool\n}\n```\nResponseContentDefinition 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.\n\n```go\ntype ResponseDefinition struct {\n\tSuccessStatusCode int\n\tSuccess           *ResponseContentDefinition\n\tError             *ResponseContentDefinition\n\tAll               map[int]*ResponseContentDefinition\n\n\t// Successes lists every 2xx response in ascending status order. Drives\n\t// `client-with-response` envelope generation, which needs a deterministic\n\t// per-status iteration.\n\tSuccesses []*ResponseContentDefinition\n\n\t// Errors lists every non-2xx response in ascending status order. Same\n\t// motivation as Successes - the envelope populates `JSON4xx`/`JSON5xx`\n\t// fields per documented status.\n\tErrors []*ResponseContentDefinition\n}\n```\nResponseDefinition describes a response.\n\n```go\ntype ScaffoldOutput struct {\n\t// Directory is the output directory, relative to the spec/config file location.\n\tDirectory string `yaml:\"directory\"`\n\n\t// Package is the package name for the generated file.\n\tPackage string `yaml:\"package\"`\n\n\t// Overwrite forces regeneration of scaffold-once files (e.g., service.go, middleware.go).\n\t// Normally these files are only generated if they don't exist. Defaults to false.\n\tOverwrite bool `yaml:\"overwrite\"`\n}\n```\nScaffoldOutput specifies output options for scaffolded files. Scaffold files are always generated as separate files (not merged).\n\n```go\ntype SchemaDescriptor struct {\n\tFields                   []FieldDescriptor\n\tHasAdditionalProperties  bool\n\tAdditionalPropertiesType string\n}\n```\nSchemaDescriptor describes a GoSchema, a type definition.\n\n```go\ntype ServerOptions struct {\n\t// Directory is the output directory for server/main.go.\n\t// Defaults to \"server\".\n\tDirectory string `yaml:\"directory\"`\n\n\t// Port is the port the server listens on. Defaults to 8080.\n\tPort int `yaml:\"port\"`\n\n\t// Timeout is the request timeout in seconds. Defaults to 30.\n\tTimeout int `yaml:\"timeout\"`\n\n\t// HandlerPackage is the full import path of the handler package.\n\t// Required when server generation is enabled.\n\tHandlerPackage string `yaml:\"handler-package\"`\n}\n```\nServerOptions specifies options for generating a runnable server main.go.\n\n```go\nfunc (o ServerOptions) Validate() error\n```\nValidate returns an error if the server options are invalid.\n\n```go\nfunc (o ServerOptions) WithDefaults() ServerOptions\n```\nWithDefaults returns a copy of ServerOptions with default values applied.\n\n```go\ntype ServiceOptions struct {\n}\n```\nServiceOptions specifies options for generating service.go scaffold. Currently empty but allows for future extensibility.\n\n```go\ntype SpecLocation string\n```\n\n```go\nconst (\n\tSpecLocationPath     SpecLocation = \"path\"\n\tSpecLocationQuery    SpecLocation = \"query\"\n\tSpecLocationHeader   SpecLocation = \"header\"\n\tSpecLocationBody     SpecLocation = \"body\"\n\tSpecLocationResponse SpecLocation = \"response\"\n\tSpecLocationSchema   SpecLocation = \"schema\"\n\tSpecLocationUnion    SpecLocation = \"union\"\n\tSpecLocationWebhook  SpecLocation = \"webhook\"\n)\n```\n\n```go\ntype TplOperationsContext struct {\n\tOperations    []OperationDefinition\n\tImports       []string\n\tConfig        Configuration\n\tWithHeader    bool\n\tServerOptions *ServerOptions\n\tPackageName   string\n}\n```\nTplOperationsContext is the context passed to templates to generate client code.\n\n```go\ntype TplTypeContext struct {\n\tTypes []TypeDefinition\n\n\t// Map of type names to schemas for cross-referencing\n\tTypeSchemaMap  map[string]GoSchema\n\tImports        []string\n\tSpecLocation   string\n\tConfig         Configuration\n\tWithHeader     bool\n\tResponseErrors map[string]bool\n\tTypeTracker    *TypeTracker\n}\n```\nTplTypeContext is the context passed to templates to generate code for type definitions.\n\n```go\ntype TypeDefinition struct {\n\tName             string\n\tJsonName         string\n\tSchema           GoSchema\n\tSpecLocation     SpecLocation\n\tNeedsMarshaler   bool\n\tHasSensitiveData bool\n}\n```\nTypeDefinition describes a Go type definition in generated code. Name is the name of the type in the schema, eg, type \\\u003c...\u003e 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.\n\n```go\nfunc (t TypeDefinition) GetErrorConstructor(errTypes map[string]string, typeSchemaMap map[string]GoSchema) string\n```\nGetErrorConstructor generates a Go constructor function for an error type. It creates nested struct literals based on the error-mapping path. If no error-mapping is configured, it returns a simple constructor.\n\n```go\nfunc (t TypeDefinition) GetErrorResponse(errTypes map[string]string, alias string, typeSchemaMap map[string]GoSchema) string\n```\nGetErrorResponse generates a Go code snippet that returns an error response based on the predefined spec error path. The path supports array access with \\[] suffix, e.g., \"data\\[].message\\[]\" will access the first element of each array.\n\n```go\nfunc (t TypeDefinition) IsAlias() bool\n```\n\n```go\nfunc (t TypeDefinition) IsOptional() bool\n```\n\n```go\ntype TypeTracker struct {\n\t// contains filtered or unexported fields\n}\n```\nTypeTracker tracks type definitions and provides lookup by name or reference. It handles name conflicts by generating unique names and maintains a mapping from original OpenAPI references to Go type names.\n\n```go\nfunc (r *TypeTracker) AsMap() map[string]*TypeDefinition\n```\nAsMap returns the internal map of type definitions.\n\n```go\nfunc (r *TypeTracker) Exists(name string) bool\n```\nExists checks if a type with the given name already exists.\n\n```go\nfunc (r *TypeTracker) LookupByName(name string) (*TypeDefinition, bool)\n```\nLookupByName returns the TypeDefinition pointer for the given Go type name.\n\n```go\nfunc (r *TypeTracker) LookupByRef(ref string) (string, bool)\n```\nLookupByRef returns the Go type name for the given OpenAPI reference path.\n\n```go\nfunc (r *TypeTracker) MarkNeedsErrorMethod(name string)\n```\nMarkNeedsErrorMethod marks a type as needing an Error() method. If the type is an alias, it follows the alias chain to find the actual non-alias type that should get the Error() method. Types that are 'any' or '\\[]any' are skipped since methods can't be added to them.\n\n```go\nfunc (r *TypeTracker) NeedsErrorMethod(name string) bool\n```\nNeedsErrorMethod returns true if the type needs an Error() method.\n\n```go\nfunc (r *TypeTracker) Size() int\n```\nSize returns the number of registered types.\n\n```go\ntype UnionElement struct {\n\t// TypeName is the Go type name (e.g., \"User\", \"string\", \"int\")\n\tTypeName string\n\n\t// Schema contains the full schema including constraints (minLength, minimum, etc.)\n\tSchema GoSchema\n}\n```\nUnionElement describes a union element with its type and schema (including constraints).\n\n```go\nfunc (u UnionElement) Method() string\n```\nMethod generates union method name for template functions \\`As/From\\`.\n\n```go\nfunc (u UnionElement) String() string\n```\nString returns the type name for backward compatibility with templates\n\n```go\ntype ValidationOptions struct {\n\t// Skip specifies whether to skip Validation method generation. Defaults to false.\n\tSkip bool `yaml:\"skip\"`\n\n\t// Simple specifies whether to use the simple validation approach. Defaults to false.\n\t// Simple validation uses validate.Struct() for all types, whereas complex validation generates custom Validate() methods.\n\tSimple bool `yaml:\"simple\"`\n\n\t// Response specifies whether to generate Validate() methods for response types.\n\t// Useful for contract testing to ensure responses match the OpenAPI spec. Defaults to false.\n\tResponse bool `yaml:\"response\"`\n}\n```\n\n","path":"github.com/uptrace/oapi-codegen-dd/v3/pkg/codegen","name":"codegen","synopsis":"","isRedistributable":true}
