Swagger – Spring Boot

Step #1: Add maven dependency

                <dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.6.1</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.6.1</version>
		</dependency>

Step #2: Create a SwaggerConfig.java in com.janani.config

package com.revature.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket api() {
		// @formatter:off
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("lms-api")
				.apiInfo(apiInfo())
				.select()
				.paths(PathSelectors.any()).build();
	}

	// @formatter:on
	// private Predicate<String> fetchPaths() {
	// return or(regex("/holidays.*"), regex("/roles.*"),
	// regex("/employees.*"));
	// }

	private ApiInfo apiInfo() {
		// @formatter:off
		return new ApiInfoBuilder()
				.title("LMS API")
				.description("Leave Management System")
				.license("LMS License")
				.contact("jananise@gmail.com")
				.licenseUrl("https://github.com/JananiVelmurugan")
				.version("1.0").build();
	}

}

Step #3: http://localhost:5000/swagger-ui.html#/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s