Home > Back-end >  Swagger-codegen command project structure
Swagger-codegen command project structure

Time:09-17

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.

CodePudding user response:

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

  • Related