Use Case: Internal API Calls with OpenAPI Clients
About
In enterprise microservices, one service often calls another to fetch or process data. Using OpenFeign with OpenAPI-generated interfaces provides:
Type-safe HTTP client code
Automatic implementation generation
Integration with Spring Boot for dependency injection and configuration
Cleaner code compared to manually building RestTemplate or WebClient requests
This example demonstrates:
account-service: Implements an OpenAPI-defined endpoint for retrieving account details.payment-service: Uses an OpenAPI-generated Feign client to callaccount-service.
The Feign interface is generated from the OpenAPI spec (account.yaml) and automatically wired into the Spring Boot context.
Project Structure
Specs
account-api-spec Contains the OpenAPI definition (
account.yaml) for retrieving account details.payment-api-spec Contains
payment.yamldefining how to retrieve payment details.
Service
account-service Implements the account API (as per spec) using Spring Boot.
payment-service Depends on both API specs and uses OpenAPI-generated clients to call
account-service.
1. account-api-spec
Structure
api.xml
account.yaml
pom.xml
Build the package

2. payment-api-spec
Structure
api.xml
payment.yaml
pom.xml
Build the package

3. account-service
Structure
.openapi-generator-ignore
pom.xml
AccountController.java
AccountServiceApplication.java
application.yaml
Build the package


4. payment-service
Structure
.openapi-generator-ignore
pom.xml
AccountServiceRestClientConfig.java
PaymentController.java
PaymentService.java
PaymentServiceApplication.java
application.yaml
Build the package



Verification
Start both the services using mvn spring-boot:run
Test the API with Postman


Reference
Last updated