Problem
Starting in v2.6.0, oapi-codegen generates simple string schemas as type aliases (type X = string) instead of named types (type X string).
This is a breaking change: you cannot define methods on a type alias in Go. Any project that attaches methods to a generated string type (e.g. validation, enum helpers) will fail to compile after regenerating with @latest.
Reproduction
OpenAPI schema:
components:
schemas:
EventType:
type: string
maxLength: 64
pattern: "^(\\$[a-z][a-z0-9_:]*|[a-z][a-z0-9_:]*)$"
v2.5.x output:
v2.6.0 output:
Adding a method in the same package:
func (e EventType) Valid() bool { ... }
Fails with:
cannot define new methods on non-local type EventType
Workaround
Exclude the schema from generation and define the type manually:
output-options:
exclude-schemas:
- EventType
Expected behavior
Simple string schemas with constraints (pattern, maxLength, enum) should generate named types, not aliases, since these are the schemas most likely to have user-defined methods. At minimum, this should be opt-in via a config flag rather than the default behavior.
Problem
Starting in v2.6.0,
oapi-codegengenerates simple string schemas as type aliases (type X = string) instead of named types (type X string).This is a breaking change: you cannot define methods on a type alias in Go. Any project that attaches methods to a generated string type (e.g. validation, enum helpers) will fail to compile after regenerating with
@latest.Reproduction
OpenAPI schema:
v2.5.x output:
v2.6.0 output:
Adding a method in the same package:
Fails with:
Workaround
Exclude the schema from generation and define the type manually:
Expected behavior
Simple string schemas with constraints (pattern, maxLength, enum) should generate named types, not aliases, since these are the schemas most likely to have user-defined methods. At minimum, this should be opt-in via a config flag rather than the default behavior.