forked from oapi-codegen/oapi-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow
import-mapping
to the current package (oapi-codegen#1774)
To simplify working with large OpenAPI specs, a good option is to split this into multiple files. However, a long-standing issue with `oapi-codegen`, as noted in oapi-codegen#400, is that when using multiple files for your OpenAPI specifications, the Import Mapping functionality requires splitting each file into a separate package. To improve this experience, we can allow using a new "magic" package name, `-`, and omit the need to perform package imports. This also updates our existing `import-mapping` example, and adds a new example for this functionality, as well as clarifying this in the docs. We simplify the existing `import-mapping` example, as the duplicated `User` type causes compilation issues. To actually implement this, we need to tweak our `refPathToGoType` logic. Closes oapi-codegen#400. Co-authored-by: Dj Gilcrease <[email protected]>
- Loading branch information
1 parent
891a067
commit 3aa1efb
Showing
18 changed files
with
452 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/import-mapping/admin/generate.go → ...apping/multiplepackages/admin/generate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package admin | ||
|
||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml api.yaml | ||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml ../../admin/api.yaml |
4 changes: 0 additions & 4 deletions
4
examples/import-mapping/admin/server.gen.go → ...ping/multiplepackages/admin/server.gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/import-mapping/common/generate.go → ...pping/multiplepackages/common/generate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package common | ||
|
||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml api.yaml | ||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml ../../common/api.yaml |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# yaml-language-server: $schema=../../../configuration-schema.json | ||
package: samepackage | ||
output: server.gen.go | ||
generate: | ||
models: true | ||
chi-server: true | ||
strict-server: true | ||
output-options: | ||
# to make sure that all types are generated | ||
skip-prune: true | ||
import-mapping: | ||
../common/api.yaml: "-" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# yaml-language-server: $schema=../../../configuration-schema.json | ||
package: samepackage | ||
output: user.gen.go | ||
generate: | ||
models: true | ||
output-options: | ||
# to make sure that all types are generated | ||
skip-prune: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package samepackage | ||
|
||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg-api.yaml ../admin/api.yaml | ||
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg-user.yaml ../common/api.yaml |
Oops, something went wrong.