在使用Go进行OpenAPI生成器时,如何指定模块路径?

huangapple go评论84阅读模式
英文:

How do you specify the module path when using go for openapi generator?

问题

生成go模块时,使用以下命令:

openapi-generator-cli generate \
    --input-spec ../spec/myapi.yml \
    --generator-name go \
    --output ./generated/go \
    --package-name myapi \
    --global-property models,supportingFiles

生成的go.mod文件将指定模块为:

module github.com/GIT_USER_ID/GIT_REPO_ID

go 1.18

require (
)

如何将github.com/GIT_USER_ID/GIT_REPO_ID覆盖为github.com/myrepo/somedir/myapi

我已经查看了OpenAPI Generator文档和Go Generator文档,但似乎都没有说明如何实现。

有人有任何想法吗?

英文:

When generating a go module with

openapi-generator-cli generate \
    --input-spec ../spec/myapi.yml \
    --generator-name go \
    --output ./generated/go \
    --package-name myapi \
    --global-property models,supportingFiles

the genrated go.mod file specifies the module as

module github.com/GIT_USER_ID/GIT_REPO_ID

go 1.18

require (
)

How does one override the github.com/GIT_USER_ID/GIT_REPO_ID to be something like: github.com/myrepo/somedir/myapi?

I've checked the OpenAPI Generator docs and the Go Generator docs and neither seem to indicate how to do so.

Does anyone have any ideas?

答案1

得分: 3

当然,我发帖后立即进行了一次搜索,并在这里找到了答案,其中提到可以使用--git-user-id--git-repo-id标志。

openapi-generator-cli generate \
    --input-spec ../spec/myapi.yml \
    --generator-name go \
    --output ./generated/go \
    --package-name myapi \
    --git-user-id myuser \
    --git-repo-id myrepo/somedir/myapi/generated/go \    
    --global-property models,supportingFiles

这将生成一个mod.go文件,内容如下:

module github.com/myuser/myrepo/somedir/myapi/generated/go

go 1.18

require (
)

英文:

Of course as soon as I post I do one more search and find the answer here stating one can use the flags --git-user-id and --git-repo-id.

openapi-generator-cli generate \
    --input-spec ../spec/myapi.yml \
    --generator-name go \
    --output ./generated/go \
    --package-name myapi \
    --git-user-id myuser \
    --git-repo-id myrepo/somedir/myapi/generated/go \    
    --global-property models,supportingFiles

which results in a mod.go file of:

module github.com/myuser/myrepo/somedir/myapi/generated/go

go 1.18

require (
)

huangapple
  • 本文由 发表于 2023年3月22日 07:34:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75807238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定