what is swagger in spring boot code example

Example 1: spring boot example with swagger

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html")
      .addResourceLocations("classpath:/META-INF/resources/");

    registry.addResourceHandler("/webjars/**")
      .addResourceLocations("classpath:/META-INF/resources/webjars/");
}

Example 2: swagger implementation in spring boot

package com.bhutanio.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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket bookHotelApi() {
        return new Docket( DocumentationType.SWAGGER_2)
                .select()
                .apis( RequestHandlerSelectors.any())
                .paths( PathSelectors.any())
                .build()
                .apiInfo(getApiInfo());
    }

    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger By Bhutan IO")
                .version("1.0")
                .description("Some description here..")
                .contact(new Contact("Bhutan IO", "http://www.bhutanio.com", "[email protected]"))
                .license("Apache License Version 2.0")
                .build();
    }
}Code language: JavaScript (javascript)

Example 3: what is swagger ui

The Swagger UI is an open source project to visually render documentation for 
an API defined with the OpenAPI (Swagger) Specification

Example 4: what is swagger

Swagger is an open-source software framework backed by a large
ecosystem of tools that helps developers design, build, document,
and consume RESTful Web services.
Swagger allows you to describe the structure of your APIs so that
machines can read them.
The ability of APIs to describe their own structure is the root of
all awesomeness in Swagger
similar to xml schema but for Json

Do you have API documentation website for your API?
Yes, we use swagger for our api documentation, and this is where
the description and guidelines of API endpoints are 

Where do you keep API reference documentation in
your Project?
We use SWAGGER to keep API endpoints and descriptions. I
normally go there and learn about API methods and how they
work.

Tags: