Change the default package name in Swagger Editor for java project

非 Y 不嫁゛ 提交于 2019-12-08 06:18:59

问题


I have downloaded the Swagger Editor and run it locally from localhost:3001. I imported my .yaml file from local system. Then I clicked on Generate Server and I choose a jaxrs. When I opened a random java file I can see:

package io.swagger.model;

I have more then 30 java classes and I don't want to change it manually, because my .yamlmaybe change in future. Is there any possibility to change it, to be for example:

package my.funny.package.model;

//Edit:

I downloaded Swagger Editor from this swagger-editor and run it using code snipped from Contribute section. In my folder files I can't find a .jar file from suggested post.


回答1:


Swagger Editor uses Swagger Codegen (specifically, its online version at http://generator.swagger.io) to generate the client and server code. It runs the Codegen with the default settings. If you want to customize code generation, you'll need to run the Codegen directly.

Use Swagger Codegen CLI

Swagger Codegen has a command-line version, swagger-codegen-cli.jar. There are several ways to install it depending on your operating system. One way is to download the JAR file from Maven Central: http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/

You can run the codegen as follows:

java -jar swagger-codegen-cli.jar generate
     -i http://petstore.swagger.io/v2/swagger.json
     -l jaxrs
     -o Petstore-Jaxrs
     -DapiPackage=my.funny.package.model

Custom options, such as the package name, can be specified directly in the command line using -D{optionName}={optionValue} (as shown above), or using a config file as explained here.

To list all options a specific generator supports, use:

java -jar swagger-codegen-cli.jar config-help -l jaxrs

Use SwaggerHub

Disclosure: I work for the company that develops SwaggerHub.

If you use SwaggerHub instead of Swagger Editor to write and store your API definitions, it lets you customize Codegen options before you download the code.



来源:https://stackoverflow.com/questions/49514341/change-the-default-package-name-in-swagger-editor-for-java-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!