Introduce swagger-ui to REST API implemented in Spring Boot

Overview

--Assumption that REST API is implemented in Spring Boot --Introduce swagger-ui to generate API documentation --Just add ʻio.springfox: springfox-boot-starter: 3.0.0` to gradle

Sample project

--Create a new project by selecting Spring Web in Spring Initializr --Implemented REST API --Create src \ main \ java \ com \ example \ demo \ api \ DemoController.java with the following contents

package com.example.demo.api;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/demo")
public class DemoController {

    @GetMapping("/customers")
    public String[] customers() {
        return new String[] {
                "AIUEO",
                "Kakikukeko",
                "SA Shi Su Se So"
        };
    }

    @GetMapping("/customer/{id}")
    public Map<String, String> customer(@PathVariable String id) {
        return Map.of(
                "id", id,
                "name", "name",
                "address", "Tokyo");
    }
}

Introduced swagger-ui

--Added to build.gradle

build.gradle


    implementation "io.springfox:springfox-boot-starter:3.0.0"

--Application launch --Open http: // localhost: 8080 / swagger-ui / in your browser image.png

reference

Recommended Posts

Introduce swagger-ui to REST API implemented in Spring Boot
Implement REST API in Spring Boot
How to call and use API in Java (Spring Boot)
Change Spring Boot REST API request / response from CamelCase to SankeCase
Let's find out how to receive in Request Body with REST API of Spring Boot
How to add a classpath in Spring Boot
How to bind to property file in Spring Boot
How to implement optimistic locking in REST API
Automatically map DTOs to entities with Spring Boot API
Hello World (REST API) with Apache Camel + Spring Boot 2
[Spring Boot] Get user information with Rest API (beginner)
How to create a Spring Boot project in IntelliJ
Customize REST API error response with Spring Boot (Part 2)
How to use CommandLineRunner in Spring Batch of Spring Boot
Customize REST API error response with Spring Boot (Part 1)
Try Spring Boot from 0 to 100.
Spring Boot 2 multi-project in Gradle
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Introduction to EHRbase 2-REST API
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Introduction to Spring Boot Part 1
How to change application.properties settings at boot time in Spring boot
Implement REST API with Spring Boot and JPA (Application Layer)
Implement REST API with Spring Boot and JPA (Infrastructure layer)
Create API to send and receive Json data in Spring
Implement REST API with Spring Boot and JPA (domain layer)
Implement a simple Rest API with Spring Security & JWT with Spring Boot 2.0
Use @ControllerAdvice, @ExceptionHandler, HandlerExceptionResolver in Spring Boot to catch exceptions
How to control transactions in Spring Boot without using @Transactional
Implement a simple Web REST API server with Spring Boot + MySQL
How to use Lombok in Spring
Proxy and timeout settings when calling API in Spring Rest Template
Spring Boot Hello World in Eclipse
Spring Boot application development in Eclipse
Write test code in Spring Boot
02. I made an API to connect to MySQL (MyBatis) from Spring Boot
Spring Boot: Restful API sample project
How to set Spring Boot + PostgreSQL
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
How to use ModelMapper (Spring boot)
How to introduce jQuery in Rails 6
What I did in the migration from Spring Boot 1.5 series to 2.0 series
Upgrade spring boot from 1.5 series to 2.0 series
[Beginner] Let's write REST API of Todo application with Spring Boot
Thymeleaf usage notes in Spring Boot
Spring.messages.fallback-to-system-locale: false is required to default message.properties for i18n support in Spring boot
Procedure to make the value of the property file visible in Spring Boot
Workaround for Command Line Runner to work with JUnit in Spring Boot
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
How to not start Flyway when running unit tests in Spring Boot
[Introduction to Spring Boot] Form validation check
Launch (old) Spring Boot project in IntelliJ
Convert request parameter to Enum in Spring
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Create Java Spring Boot project in IntelliJ
Loosen Thymeleaf syntax checking in Spring Boot