27132

Change the default package name in Swagger Editor for java project

Question:

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 <a href="https://swagger.io/docs/swagger-tools/#swagger-editor" rel="nofollow">swagger-editor</a> and run it using code snipped from Contribute section. In my folder files I can't find a .jar file from suggested post.

Answer1:

Swagger Editor uses <a href="https://github.com/swagger-api/swagger-codegen" rel="nofollow">Swagger Codegen</a> (specifically, its online version at <a href="http://generator.swagger.io" rel="nofollow noreferrer">http://generator.swagger.io</a>) 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.

<h3>Use Swagger Codegen CLI</h3>

Swagger Codegen has a command-line version, swagger-codegen-cli.jar. There are <a href="https://github.com/swagger-api/swagger-codegen#prerequisites" rel="nofollow">several ways to install it</a> depending on your operating system. One way is to download the JAR file from Maven Central: <a href="http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/" rel="nofollow">http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/</a>

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 <a href="https://github.com/swagger-api/swagger-codegen#customizing-the-generator" rel="nofollow">here</a>.

To list all options a specific generator supports, use:

java -jar swagger-codegen-cli.jar config-help -l jaxrs <h3>Use SwaggerHub</h3>

<em>Disclosure: I work for the company that develops SwaggerHub.</em>

If you use <a href="https://swaggerhub.com" rel="nofollow noreferrer">SwaggerHub</a> instead of Swagger Editor to write and store your API definitions, it lets you customize Codegen options before you download the code.

<img alt="SwaggerHub > Edit Codegen Options" class="b-lazy" data-src="https://i.stack.imgur.com/Kxmfo.png" data-original="https://i.stack.imgur.com/Kxmfo.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

<img alt="SwaggerHub > Codegen Options > jaxrs > package name" class="b-lazy" data-src="https://i.stack.imgur.com/KHbEX.png" data-original="https://i.stack.imgur.com/KHbEX.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Recommend

  • What is the cleanest way to add a directory of third-party packages to the beginning of the Python p
  • use object name in a loop
  • Select previous row mysql?
  • How to access properties of object created and returned from a function
  • JavaCC: You must either use ReInit() or set the JavaCC option STATIC to false
  • SMS are duplicated as Calls(Samsung galaxy S II)
  • jquery: Enter to Tab trigger in specific parts
  • WKWebView gives SecurityError when bundling html and javascript with app
  • complex db2/sql query with time-sampling, group, map, join and csv export
  • What is this vertical transparent line appearing only on Safari Mac?
  • What is the proper way to handle menu items in a master/detail flow?
  • Java - add a button in a cell in a Jtable
  • PHP: preg_match() not correct
  • How to access a service in a kubernetes cluster using the service name .
  • How to compute daily average for 15 years?
  • How does Chrome get device orientation information?
  • ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context : while initializing Chrome bro
  • Getting ORA-01861 - Literal does not match format string on SQLPlus Only
  • Xcode Color picker automatically changing HSB color
  • How do I embed a custom user-control in MS Word?
  • gulp.watch running same task multiple times when saving many files
  • CKeditor stripping font tags instead of converting to span
  • How can I add div content to a new page in jspdf?
  • Cuda Clang and OS X Mavericks
  • Aptana 3 remove bundle (jquery)
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Uncaught TypeError: $(…).select2 is not a function
  • Test if a set exists before trying to drop it
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Fetching methods from BroadcastReceiver to update UI
  • SSO with signing and signature validation doesn't work
  • Symfony2: How to get request parameter
  • GridView Sorting works once only
  • Transpose CSV data with awk (pivot transformation)
  • WPF Applying a trigger on binding failure
  • Acquiring multiple attributes from .xml file in c#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal