You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Separate packages for models and server part aren't resolved #2078
I am trying to place my server generated part in one package and models that it has to use in another package. But when my api has a query parameter, server part's code is not importing model's package, thus can't resolve it, giving an error.
oapi-codegen version: v2.5.0
go version: 1.24.5
os: windows
This is working as designed, though the config needed is a bit different from what you have:
import-mapping keys are external document paths, not JSON pointers — "#/components/schemas": ... never matches anything, because internal $refs always resolve within the current package. To put schemas in a separate Go package, split the spec into two files: move shared schemas into e.g. models.yaml and reference them from your API spec as $ref: "./models.yaml#/components/schemas/Foo". Then in the server config: import-mapping: {"./models.yaml": "yourmodule/internal/application/dto"}. See examples/import-mapping/multiplepackages/ for a complete working setup.
The specific error you're seeing is different, though: GetPaymentSessionParams is generated from your inline query parameter — it's an operation-scoped type, not a component schema, so it always belongs to the server's package. Add models: true to your server config (alongside fiber-server: true) and it will be declared there. Component schemas you've $ref'd into models.yaml will still come from the dto package via the import mapping; only operation-derived types (Params structs, request/response bodies) stay with the server.
If you don't actually need separate Go packages — just separate files — the simpler pattern is generating both outputs into the same package (see examples/import-mapping/samepackage/, which uses the special mapping value "-").
Closing as working-as-intended — happy to reopen if the suggested config doesn't resolve it.
Activity
mromaszewicz commentedon Jul 13, 2026
This is working as designed, though the config needed is a bit different from what you have:
import-mappingkeys are external document paths, not JSON pointers —"#/components/schemas": ...never matches anything, because internal$refs always resolve within the current package. To put schemas in a separate Go package, split the spec into two files: move shared schemas into e.g.models.yamland reference them from your API spec as$ref: "./models.yaml#/components/schemas/Foo". Then in the server config:import-mapping: {"./models.yaml": "yourmodule/internal/application/dto"}. Seeexamples/import-mapping/multiplepackages/for a complete working setup.The specific error you're seeing is different, though:
GetPaymentSessionParamsis generated from your inline query parameter — it's an operation-scoped type, not a component schema, so it always belongs to the server's package. Addmodels: trueto your server config (alongsidefiber-server: true) and it will be declared there. Component schemas you've$ref'd intomodels.yamlwill still come from thedtopackage via the import mapping; only operation-derived types (Params structs, request/response bodies) stay with the server.If you don't actually need separate Go packages — just separate files — the simpler pattern is generating both outputs into the same package (see
examples/import-mapping/samepackage/, which uses the special mapping value"-").Closing as working-as-intended — happy to reopen if the suggested config doesn't resolve it.
Reject import-mapping keys that are JSON pointers (#2461)