swagger-codegen, when you define an API in a particular format, It spits out a library for hitting it in various languages.
It goes well with Rails' Grape, and if I try to hit an API server made with Rails from python, it's the main subject.
As you can see by reading the swagger-codegen code,
When creating a file, the file name should be ʻapi_v1_name, but it is generated as ʻapi :: v1:: name
, and the file name and the path specified by import mesh well. Is not ... Therefore, I get an Import Error.
It's a small mistake, so I think it will be fixed soon, but I want to be able to communicate right away.
So let's override the function and solve it. Regarding override, "So easy! Customize Swagger Codegen" was very helpful.
custom-script.groovy
@Grab('io.swagger:swagger-codegen-cli:2.1.4')
import io.swagger.codegen.*;
import io.swagger.codegen.languages.*;
class MyPythonClientGen extends PythonClientCodegen {
@Override
public String toModelFilename(String name){
return toVarName(name)
}
//Kick to CLI
public static main(String[] args) {
SwaggerCodegen.main(args)
}
}
groovy custom-script.groovy generate -i http://example.com/api/v1/swagger_doc -l MyPythonClientGen -o ./api/
with this,
Files are now generated with ʻapi_v1_name instead of ʻapi :: v1 :: name
. If you find it bothersome, you may want to manually rename the file.
Recommended Posts