This project demonstrates how to use OpenAPI Generator with Spring Boot 3, to build a simple REST API for managing TODOs.
It uses the delegate pattern to separate generated code from custom business logic.
- OpenAPI 3.0 specification-driven development
- Automatic Spring Boot controller & DTO generation
- Delegate pattern for business logic separation
- JPA & H2 in-memory database integration
- Swagger UI for API exploration
- Unit and integration tests with JUnit 5
- Minimal frontend for showcasing API usage
The project comes with a Spring Boot backend to showcase the usage of the OpenAPI Generator. It is located in the root
and src
directory.
- Java 21+
- Maven 3.9+
Run the application:
# Generate code from OpenAPI spec and build the application
mvn clean compile
# Run the application
mvn spring-boot:run
The application is available at http://localhost:8080.
Method | Path | Description |
---|---|---|
GET | /api/todos |
List all todos |
POST | /api/todos |
Create a todo |
GET | /api/todos/{id} |
Get a todo by ID |
PUT | /api/todos/{id} |
Update a todo |
PATCH | /api/todos/{id} |
Patch a todo |
DELETE | /api/todos/{id} |
Delete a todo |
Name | Path | Description | Credentials |
---|---|---|---|
Swagger UI | /swagger-ui | API testing UI | None |
OpenAPI Spec | /v3/api-docs | OpenAPI specification | None |
H2 Console | /h2-console | In-memory database UI | Username: sa Password: <empty> |
The project comes with a minimal Angular frontend to showcase the API usage. It is located in the frontend directory.
If you are actively developing the frontend, you can run it alongside the Spring Boot backend. This setup supports hot reloading when modifying Angular code.
- Frontend
- Node.js 20+
- Angular CLI 20+ (optional)
- Backend (if needed)
- Java 21+
- Maven 3.9+
# Install frontend dependencies
cd frontend
npm install
Run backend and frontend separately:
# Generate code from OpenAPI spec and build the application
mvn clean compile
# Run the backend
mvn spring-boot:run
# In another terminal, run the frontend development server
npm --prefix ./frontend start
Type | Mode | URL | Notes |
---|---|---|---|
Frontend | Direct | http://localhost:4200 | Hot reload enabled |
Backend (API) | Direct | http://localhost:8080/api | URL root is reserved for Spring Boot Mode |
Backend (API) | Proxy | http://localhost:4200/api | Proxy via proxy.conf.json |
The Angular dev server is configured with a proxy to forward /api
requests to the backend.
If the frontend is not actively being developed, it will be served directly by the Spring Boot backend. This setup does not support hot reloading when modifying Angular code.
- Java 21+
- Maven 3.9+
Run backend and frontend together:
# Build the application
mvn clean compile
# Run the application
mvn spring-boot:run
Type | Mode | URL | Notes |
---|---|---|---|
Frontend | Direct | http://localhost:8080 | Hot reload disabled |
Backend (API) | Direct | http://localhost:8080/api | URL is the same as in Development Mode |
- Spring Boot Mode is always active when running the application (even if the frontend is in Development Mode).
- It uses the frontend-maven-plugin to install Node.js, run Angular builds, and integrate the frontend with the backend.
- During the Maven build (
mvn clean compile
), the Angular app is compiled (npm run build
) and copied into Spring Boot’sstatic/
resources directory:
frontend/dist/openapi-generator-example-frontend/browser
→target/classes/static
- This allows the packaged Spring Boot application to serve the frontend directly without needing a separate Node.js process in production mode.
This project is licensed under the MIT License.