HATEOAS
Spring Boot 2.2.x
Swagger 2.x
Startup Issues
API Documentation

Why HATEOAS starts creating issue for spring-boot version 2.2.x during startup with Swagger 2.x?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Hypermedia as the Engine of Application State (HATEOAS) is a pivotal component of RESTful web services, providing clients with the ability to navigate APIs dynamically by including hypermedia links with responses. Spring Boot, one of the most popular frameworks for building microservices and REST API applications, offers robust support for HATEOAS. However, starting with version 2.2.x, developers started encountering issues integrating Spring Boot's HATEOAS functionality with Swagger 2.x for API documentation. This article delves into the reasons behind these conflicts and provides technical insights.

Background

Spring Boot and HATEOAS

Spring Boot simplifies creating production-grade applications, and with its support for Spring HATEOAS, it enables the creation of RESTful APIs that are not only clean but also self-descriptive. HATEOAS provides links in responses to define available operations on a resource, allowing clients to navigate the API without prior knowledge of its structure.

Swagger 2.x and API Documentation

Swagger 2.x (now part of the OpenAPI specification) has been widely used to automatically generate API documentation. It parses web services and produces a conventional and human-readable format, typically in JSON or YAML, accompanied by a user-friendly UI.

Issue Overview

With the release of Spring Boot 2.2.x, developers started to experience compatibility problems between HATEOAS and Swagger 2.x. These issues often manifest during application startup, resulting from deep-rooted incompatibilities between the Spring HATEOAS changes and the outdated Swagger 2.x version.

Technical Explanation

Dependency Updates and Conflicts

  • Spring HATEOAS 1.0: Released close to Spring Boot 2.2.x, it included updates that were not fully backward compatible. One major change was the shift to `RepresentationModel` from `ResourceSupport` and `Resource`. This revised design improved HATEOAS capabilities but required code that interacts with HATEOAS models to adapt.
  • Swagger 2.x Stagnation: Swagger 2.x did not receive regular updates to align with the latest Spring HATEOAS modifications. The stagnation in Swagger 2.x development caused it to rely on older HATEOAS representations, leading to misalignments during the application's startup phase.

Typical Startup Error

A common error developers encounter is a `BeanCreationException`, often related to missing or incompatible types required by Swagger to parse API controllers augmented by Spring HATEOAS components.


Course illustration
Course illustration

All Rights Reserved.