Skip to content

Instantly share code, notes, and snippets.

@PhyrexTsai
Last active May 24, 2016 06:22
Show Gist options
  • Save PhyrexTsai/eed43b4f8943c2e193dd17def86ba462 to your computer and use it in GitHub Desktop.
Save PhyrexTsai/eed43b4f8943c2e193dd17def86ba462 to your computer and use it in GitHub Desktop.

Swagger

Swagger is the world's most popular framework for APIs.
[Swagger] (http://swagger.io/)

Intellij plugin install

Install plugin on Intellij.
Under Intellij Preferences->Plugin->Browse repositories...
Search keyword : Swagger Install it and restart Intellij.

Swagger reference

[Swagger RESTEasy] (https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5#adding-the-dependencies-to-your-application)

  • Add dependency on pom.xml
<dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-jaxrs</artifactId>
  <version>1.5.0</version>
</dependency>
  • Add configuration on Application
//add class for swagger
this.classes.add(io.swagger.jaxrs.listing.ApiListingResource.class);
this.classes.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);

//add config for swagger
BeanConfig beanConfig = new BeanConfig();
beanConfig.setTitle("Migme Backend API Explorer");
beanConfig.setDescription("Migme Backend API Explorer");
beanConfig.setVersion("1.0.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/");
beanConfig.setResourcePackage("com.projectgoth.migbo.datasvc.service");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
  • Add @Api on each REST class
@Api(value = "/test", description = "Operations about tests")

Run application

Find out json from the url :

http://localhost:8080/{path}/swagger.json

Using swagger editor

[http://editor.swagger.io/] (http://editor.swagger.io/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment