I am using swagger-springmvc and swagger-codegen to generate a Java client library for a RESTful webservice. I have written my own extension of the BasicJavaGenerator (see below) to override the package names, and can successfully generate the client library files. The "main" files generated are:
swagger-codegen/generated-code/java/pom.xml
swagger-codegen/generated-code/java/src/main/java/com/example/ApiApi.java
swagger-codegen/generated-code/java/src/main/java/com/example/model/*.java
What I can't find is how to set the name of my API to get the code generator to rename ApiApi.java to MyProjectApi.java (for example) as seems to be done in the samples included in with swagger-codegen. I have tried looking at the code generator code to override the api name, and have also tried looking both at the swagger json spec and swagger springmvc functionality to an option to set the name.
The code generator:
package com.wordnik.swagger.codegen
import com.wordnik.swagger.codegen.BasicJavaGenerator
object MyJavaGenerator extends BasicJavaGenerator {
def main(args: Array[String]) = generateClient(args)
// api invoker package
override def invokerPackage = Some("com.example.api")
// package for models
override def modelPackage = Some("com.example.api.model")
// package for api classes
override def apiPackage = Some("com.example.api")
}
The Swagger Codegen is an open source code-generator to build server stubs and client SDKs directly from a Swagger defined RESTful API. The source code for the Swagger Codegen can be found in GitHub.
# Swagger Codegen Ignore. # Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen. # Use this file to prevent files from being overwritten by the generator.
Swagger has a tool called the swagger-code-generator which allows you to generate Server or Client code for the API specification that you defined. By using this tool developers can save time by not having to manually set up the structure of the API involving the different web frameworks.
you can override this behavior as such:
override def toApiName(name: String) = "MyProject" + name
as you see fit. Please note that you should consider upgrading to 2.1.0-SNAPSHOT, which lives in https://github.com/swagger-api/swagger-codegen/tree/develop_2.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With