Support shared "types" package
Sorry if this feature (or work around) is already available, I didn't find anything in the documentation.
I'd like to be able to generate the types in one package and then use that package for client/server (that also reside in different packages)...
oapi-codegen -package types -generate types my.yaml > types/types.gen.go oapi-codegen -package client -generate client -type-package types my.yaml > client/client.gen.go oapi-codegen -package server -generate server -type-package types my.yaml > server/server.gen.go
The generate client/server code would use the types in the "types" package.
That's a must have feature. In other case typical cyclic deps arose:
-
serverpkg contains implementation that importstoolspkg; -
toolspkg has to importserverin order to process arbitrary types. Separatetypespackage could break that vicious circle.
https://github.com/deepmap/oapi-codegen/pull/389
I've adapted #389 to the latest version of oapi-codegen in #558
The difference from origin patch is you have to specify full Golang package name like:
oapi-codegen -package types -generate types my.yaml > types/types.gen.go
oapi-codegen -package client -generate client -type-package a.com/b/c/types my.yaml > client/client.gen.go
oapi-codegen -package server -generate server -type-package a.com/b/c/types my.yaml > server/server.gen.go
@tuxofil I also ran into this issue - thanks for your PR, I used your fork of this package and was able to generate code into a separate types package.
I ran into an issue when generating an API client - the types in the client package didn't properly reference my types package (a.com/b/c/types in your example above). I've created a new PR based on yours with an additional commit to fix this. Just a heads up in case you run into a similar issue.
This is now possible. An example is provided in one of the original PRs for this: https://github.com/deepmap/oapi-codegen/pull/389#issuecomment-1243080859
Is there a way to provide additional-imports via cli?