Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,9 @@ output: server.gen.go
> [!NOTE]
> This doesn't include [validation of incoming requests](#requestresponse-validation-middleware).

> [!IMPORTANT]
> When a strict-server spec uses `$ref` to point at a `components/responses/...` (or `components/requestBodies/...`) defined in another spec via `import-mapping`, the destination spec **must also be generated with `strict-server: true`**. The strict envelope embeds the `<Name>JSONResponse` type from the destination package; that type only exists when the destination generates a strict server. Without it the generated code will fail to compile with an "undefined" error. See [issue #2010](https://github.com/oapi-codegen/oapi-codegen/issues/2010).

## Generating API clients

As well as generating the server-side boilerplate, `oapi-codegen` can also generate API clients.
Expand Down
10 changes: 10 additions & 0 deletions internal/test/issues/issue-2010/config.base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# yaml-language-server: $schema=../../../../configuration-schema.json
package: spec_base
generate:
chi-server: true
strict-server: true
models: true
output: gen/spec_base/issue.gen.go
output-options:
skip-prune: true
12 changes: 12 additions & 0 deletions internal/test/issues/issue-2010/config.other.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# yaml-language-server: $schema=../../../../configuration-schema.json
package: spec_other
generate:
chi-server: true
strict-server: true
models: true
import-mapping:
./spec-base.yaml: "github.com/oapi-codegen/oapi-codegen/v2/internal/test/issues/issue-2010/gen/spec_base"
output: gen/spec_other/issue.gen.go
output-options:
skip-prune: true
10 changes: 10 additions & 0 deletions internal/test/issues/issue-2010/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression fixture for https://github.com/oapi-codegen/oapi-codegen/issues/2010.
//
// The base spec defines components/responses/400 with a JSON body. The "other"
// spec references that response via an external $ref. With strict-server
// enabled in both packages, the embedded response field name must agree across
// packages so cross-package response casts compile.
package issue_2010

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.base.yaml spec-base.yaml
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.other.yaml spec-other.yaml
Empty file.
271 changes: 271 additions & 0 deletions internal/test/issues/issue-2010/gen/spec_base/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Loading
Loading