英文:
Swagger-codegen command project structure
问题
我正在使用Swagger来开发一个用Go编写的新API。这是我的第一个Swagger项目。我安装并使用了以下命令从swagger.yaml文件创建我的项目。我希望将我放入swagger.yaml文件中的重新配置作为我的流水线任务的一部分 - 通过在.swagger-codegen-ignore文件中设置忽略项,将一个任务放入以执行类似于swagger-codegen generate -i ./api/swagger.yaml -l go-server
的命令。有一件事我不太喜欢,但我不知道如何改变。有什么建议吗?我需要接受它吗?
生成的目录结构对于go-server
如下所示:
.
├── api
│ └──swagger.yaml
├── go #这个目录中的所有内容都属于"swagger"包
│ ├── a_handler_function_file.go
│ ├── logger.go
│ ├── model_struct_file.go
│ ├── routers.go
│ └── ...
├── Dockerfile
└── main.go
我对名为go
的目录或它生成的名为swagger
的包不太满意。我希望它们对项目更有意义。
重命名该目录是否违反了惯例?
是否有办法配置swagger-codegen以按我想要的方式重命名它们? - 我正在进行研究,看看是否有办法,但我找不到。
英文:
I am using swagger to develop a new api written in Go. This is my first swagger project. I installed and used this command to create my project from a swagger.yaml. I aim to make reconfigurations I put into the swagger.yaml file part of my pipeline tasks - putting a task in to execute something like swagger-codegen generate -i ./api/swagger.yaml -l go-server
by strategically setting up ignores in my .swagger-codegen-ignore
file. There is one thing I don't necessarily like but i can't figure out how to change. Any advice? Do i need to live with it?
the generated directory structure looks like this for go-server
.
├── api
│ └──swagger.yaml
├── go #everyting in this directory is part of the "swagger" package
│ ├── a_handler_function_file.go
│ ├── logger.go
│ ├── model_struct_file.go
│ ├── routers.go
│ └── ...
├── Dockerfile
└── main.go
I am not keen on the directory called go
or the package it produces called swagger
. I want something more meaningful to the project.
Does it go against conventions to rename the directory?
Is there a way to configure the swagger-codegen to rename these what I want? - I am doing research to see if there is a way but I can't find one.
答案1
得分: 0
似乎 SEO 魔法并没有真正地爬取到 swagger-codegen git 仓库中的这个页面 https://github.com/swagger-api/swagger-codegen#customizing-the-generator 。也许这个问答会有所帮助。
可以通过在生成命令中添加 -D<configParameterName>
或者创建一个 config.json 文件并使用 -c config.yaml
将其添加到生成命令中来实现。
对于 go-server,只有两个可用的参数,即 packageName 和 hideGenerationTimestamp。
所以我尝试了 swagger-codegen generate -i ./swagger.yaml -l go-server -DpackageName="myPackageName"
,它起作用了!
我还尝试创建了一个 config.json
文件,内容如下:
{
"packageName": "myPackageName"
}
然后生成命令如下:swagger-codegen generate -i ./swagger.yaml -l go-server -c config.json
这也起作用了。
至于更改 go
目录,看起来我只能接受它。
英文:
It seems that SEO magic has not really crawled in a way to effectively land on this page in the swagger-codegen git repo https://github.com/swagger-api/swagger-codegen#customizing-the-generator . maybe this Q and A will help.
One can either use add a -D<configParameterName>
to the generate command or one can create a config.json file and add it to the generate command using -c config.yaml.
for go-server there are only two parameters available, packageName and hideGenerationTimestamp.
So I tried swagger-codegen generate -i ./swagger.yaml -l go-server -DpackageName="myPackageName"
and it worked!!!
I also tried creating a config.json
file that looks like this
{
"packageName": "myPackageName"
}
and then generate command that looks like this swagger-codegen generate -i ./swagger.yaml -l go-server -c config.json
and that works too.
As far as changing the go
directory - it looks like I will have to live with it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论