在Swagger Editor中为java项目更改默认包名称 [英] Change the default package name in Swagger Editor for java project

查看:573
本文介绍了在Swagger Editor中为java项目更改默认包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已下载 Swagger编辑器并从 localhost:3001 本地运行。我从本地系统导入了我的 .yaml 文件。然后我点击生成服务器,然后选择 jaxrs 。当我打开一个随机的java文件时,我可以看到:

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;

我有30多个java类,我不想手动更改它,因为我的 .yaml 将来可能会改变。有没有可能改变它,例如:

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;

//编辑:

我已下载来自 swagger-的 Swagger编辑编辑器并使用从 Contribute 部分剪切的代码运行它。在我的文件夹文件中,我找不到建议帖子中的 .jar 文件。

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.

推荐答案

Swagger编辑使用 Swagger Codegen (具体来说,它的在线版本为 http://generator.swagger.io )生成客户端和服务器代码。它使用默认设置运行Codegen。如果要自定义代码生成,则需要直接运行Codegen。

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.

Swagger Codegen有一个命令行版本, swagger-codegen-cli.jar 。根据您的操作系统,有几种安装方式。一种方法是从Maven Central下载JAR文件: http:/ /central.maven.org/maven2/io/swagger/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/

您可以按如下方式运行codegen:

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

可以使用 -D {optionName} = {optionValue} (如上所示),或使用配置文件,如此处

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



使用SwaggerHub



披露:我的工作是开发SwaggerHub的公司。

如果您使用 SwaggerHub 而不是Swagger Editor来编写和存储您的API定义,它允许您在下载代码之前自定义Codegen选项。

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.

这篇关于在Swagger Editor中为java项目更改默认包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆