DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service
  • Leveraging Salesforce Using Spring Boot
  • Spring Microservices RESTFul API Documentation With Swagger Part 1
  • Node.js Http Module to Consume Spring RESTful Web Application

Trending

  • Teradata Performance and Skew Prevention Tips
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Rust and WebAssembly: Unlocking High-Performance Web Apps
  • Debugging Core Dump Files on Linux - A Detailed Guide
  1. DZone
  2. Coding
  3. Frameworks
  4. How to configure Swagger to generate Restful API Doc for your Spring Boot Web Application

How to configure Swagger to generate Restful API Doc for your Spring Boot Web Application

Learn How to Enable Swagger in your Spring Boot Web Application

By 
Saurabh Chhajed user avatar
Saurabh Chhajed
·
Aug. 26, 14 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
128.2K Views

Join the DZone community and get the full member experience.

Join For Free

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
– Martin Fowler

What is Swagger?

Swagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services. The goal of Swagger is to enable client and documentation systems to update at the same pace as the server. The documentation of methods, parameters, and models are tightly integrated into the server code, allowing APIs to always stay in sync.

Why is Swagger useful?

The Swagger framework simultaneously solves server, client, and documentation/sandbox needs.

With Swagger’s declarative resource specification, clients can understand and consume services without knowledge of server implementation or access to the server code. The Swagger UI framework allows both developers and non-developers to interact with the API in a sandbox UI that gives clear insight into how the API responds to parameters and options.

Swagger happily speaks both JSON and XML, with additional formats in the works.

How to Enable Swagger in your Spring Boot Web Application ?

Step 1 : Include Swagger Spring MVC dependency in Maven

<dependency>
    <groupId>com.mangofactory</groupId>
    <artifactId>swagger-springmvc</artifactId>
    <version>0.8.8</version>
</dependency>

Step 2 : Create Swagger Java Configuration

  • Use the @EnableSwagger annotation.
  • Autowire SpringSwaggerConfig.
  • Define one or more SwaggerSpringMvcPlugin instances using springs @Bean annotation.
@Configuration
@EnableSwagger
public class SwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
// Don't forget the @Bean annotation
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(
apiInfo()).includePatterns("/saurzcode/.*");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("SaurzCode API", "API for Saurzcode",
"Saurzcode API terms of service", "mail2saurzcode@gmail.com",
"Saurzcode API Licence Type", "Saurzcode API License URL");
return apiInfo;
}
}

Step 3 : Create Swagger UI using WebJar

<repository>
 <id>oss-jfrog-artifactory</id>
 <name>oss-jfrog-artifactory-releases</name>
 <url>http://oss.jfrog.org/artifactory/oss-release-local</url>
 </repository>
<dependency>
 <groupId>org.ajar</groupId>
 <artifactId>swagger-spring-mvc-ui</artifactId>
 <version>0.1</version>
 <scope>compile</scope>
 </dependency>

Verify the API Configuration at  – http://localhost:8080/api-docs

You can see the Swagger API Docs at  http://localhost:8080/index.html

Swagger API Doc


Complete project is available at GitHub.

https://github.com/saurzcode/saurzcode-swagger-spring/

References :

  • https://github.com/martypitt/swagger-springmvc
  • https://helloreverb.com/developers/swagger/

Originally Shared at : 

http://saurzcode.in/2014/08/19/how-to-configure-swagger-to-generate-restful-api-doc-for-your-spring-boot-web-application/  

API Spring Framework Spring Boot Web application application Web Service REST Doc (computing) Web Protocols

Published at DZone with permission of Saurabh Chhajed, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service
  • Leveraging Salesforce Using Spring Boot
  • Spring Microservices RESTFul API Documentation With Swagger Part 1
  • Node.js Http Module to Consume Spring RESTful Web Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!