oapi-codegen
oapi-codegen copied to clipboard
Code Generator for Strict Server works incorectly with external references to schemas and headers
Hello!
Please take a look to this repository with reproduction case https://github.com/excavador/deepmap-strict-server-external-ref
Run make
to observe the issue
➜ make
go mod tidy
go mod download
go build ./...
# github.com/excavador/deepmap-strict-server-external-ref/b
b/api.go:321:7: undefined: Etag
b/api.go:360:13: undefined: Problem
make: *** [Makefile:15: build] Error 1
how it should be
➜ git diff
diff --git a/b/api.go b/b/api.go
index f8c1c60..353cd3a 100644
--- a/b/api.go
+++ b/b/api.go
@@ -318,7 +318,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
type ConflictApplicationProblemPlusJSONResponse externalRef0.Problem
type ExampleResponseHeaders struct {
- Etag Etag
+ Etag externalRef0.Etag
}
type ExampleApplicationExamplePlusJSONResponse struct {
Body Example
@@ -357,7 +357,7 @@ func (response Example409ApplicationProblemPlusJSONResponse) VisitExampleRespons
}
type ExampledefaultApplicationProblemPlusJSONResponse struct {
- Body Problem
+ Body externalRef0.Problem
Headers externalRef0.ProblemResponseHeaders
StatusCode int
}
Also, from my point of view, we do not need at all this XXXdefaultYYY
data types for "default" responses
I guess you need to switch internally "strict server" from golang template to something like "recursive type generation" (like you did for regular components/schemas
).
Add in-memory some dummy ephemeral types (by using openapi3 golang library) and generate data-types "as usual" (like "models").
It will remove a lot of code on your side and will work correctly always
To confirm, what version of oapi-codegen is being used for this?
To confirm, what version of oapi-codegen is being used for this?
v2.1.0
go run github.com/deepmap/oapi-codegen/v2/cmd/[email protected] \
-config config.yaml -package "${NAME}" -o "$GOLANG" "$OPENAPI"
https://github.com/excavador/deepmap-strict-server-external-ref/blob/master/deepmap.sh#L23
To confirm, what version of oapi-codegen is being used for this?
@jamietanna answered in the previous comment. Just clone my repo and run "make" - all scripts configured to generate everything and illustrate the problem