ptitbob / swagger-ui-integration

Swagger core and Swagger UI integration effortless for Java EE application
GNU Lesser General Public License v3.0
4 stars 2 forks source link

swagger-ui-integration

Swagger core and Swagger UI integration effortless for Java EE application


Build Status Maven Central


swagger-ui-integration ?

swagger-ui-integration is a library that allows you to turn at the same time exposing the description of the REST API of the application via the swagger and offer access a UI (swagger-UI) using descriptive swagger thereof.

swagger lib linked :

demo : examples how to use swagger-ui-integration lib on github

Since version 0.8, you can reach the library from maven central repository.

Use Swagger core and Swagger UI in your project.

The library provides a number of default values and get 3 levels of configuration.

Configurations path - order of configuration items reading :

  1. Annotation @SwaggerUIConfiguration
  2. resource Configuration file swagger-project.properties allow set configuration during package building.
  3. system configuration file store in system property. The system property'name must be set in systemPropertyForExternalConfigurationFilename

annotation properties and default values :

configuration files properties and default values :

All property must used prefixe swagger. (i.e. swagger.apiDocPath). You can store your swagger properties in overall project configuration file.

how use it

First add dependency to your JavaEE project :

    <dependencies>
        ...
        <dependency>
            <groupId>org.shipstone</groupId>
            <artifactId>swagger-ui-integration</artifactId>
            <version>1.0</version>
        </dependency>
        ...
    </dependencies>

Add empty class with the annotation @SwaggerUIConfiguration.

@SwaggerUIConfiguration
public class SwaggerURLRewriter  {
}

Your API REST Application class, no need to do anything else :)

@ApplicationPath("api")
public class RestApplication extends Application {
}

And finally, on all your endpoints you want to view in swagger documentation, add specific swagger annotation. Most important is @Api ;)

@Path("person")
@Api(value = "Personne")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
public class PersonEndpoint {

  @GET
  @ApiOperation(value = "Liste des personnes")
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public List<Person> getPersonList() {
    ...
    some stuff
    ...
  }

}

Use

If you use only default configuration, the library give you two url (i.e. use previous exemple and context (project final name) as customer in localhost server :

Activation or desactivation by system configuration file need to relaunch application.

have fun !


ToDo