How to change the API name in the class created by swagger-codegen

I use swagger-springmvc and swagger-codegen to create a Java client library for the RESTful web service. I wrote my own extension BasicJavaGenerator (see below) to override package names and can successfully generate client library files. "Basic" created files:

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 not find is setting the name of my API to force the code generator to rename ApiApi.java to MyProjectApi.java (for example), as is done in the examples included in swagger-codegen, I tried to look at the code of the code generator to override the api name, and also tried to look at both the swagger json specification and the springmvc swagger function on the option to set the name.

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") } 
+5
source share
2 answers

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 is located at https://github.com/swagger-api/swagger-codegen/tree/develop_2.0

+8
source

In addition to the accepted answer - to qualify for capital letters, you can use:

 override def toApiName(name: String) = "MyProject" + name.capitalize 
+3
source

Source: https://habr.com/ru/post/1212982/


All Articles