How to Create a Node REST Stub with Swagger Codegen
Generating Swagger Specification document

In this section, we will use a Spring boot application to generate the Swagger specification document which consists of the REST API specification. This document can then be used to share with the API consumers so that a Node JS client can be created using Swagger codegen utility.

To generate the Swagger Specification, we have created a sample Spring boot project. It can be downloaded from this Github link. This project is about book management service and exposes following REST endpoints:

GET v1/books/: List all books

POST v1/books/: Create a new book

GET v1/books/{book_id}: Get a book resource

DELETE v1/books/{book_id}: Remove a book

Download this project and set up in your favorite IDE. To generate the swagger document, we will update the pom.xml file with the springfox-swagger2 and springfox-swagger-ui maven dependencies as shown below:

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger2</artifactId>

<version>2.9.2</version>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger-ui</artifactId>

<version>2.9.2</version>

</dependency>

Following this, we will add the below Swagger configuration. This configuration let Swagger detect the REST endpoints as well as adds some metadata about the API owner (API Name, email, website and so on)

SwaggerConfiguration

Start the application and head over to the http://localhost:8080/v2/api-docs. This shows the Swagger OpenAPI specification document. Save this JSON file as swagger-book-api.json. Alternatively, we can also view the REST endpoint information at http://localhost:8080/swagger-ui.html.
['Somnath Musib']
['Technology', 'Software Development', 'Java', 'Software Engineering', 'Programming']