Backend: A SpringBoot application configured to generate both Java code and TypeScript client code from an OpenApi specification.
Frontend: A Next.js using the generated client to call the backend API.
The openapi spec is defined in backend/src/main/resources/api/books.yaml.
Maven OpenAPI Generator is configured in pom.xml to generate the following:
- Controller Interface, which is implemented in BooksController.
- DTOs including validation annotations.
- This generated code can be found in backend/target/generated-sources/openapi/java
- Postman collection backend/postman
Note: This can be configured to build and publish a separate jar rather than local files (e.g. if required by another Java client service).
- A default client that can be used to call the API. Currently configured to use fetch, but other generators are available for axios etc.
- DTOs
- This generated code can be found in frontend/lib/generated/openapi and is consumed in frontend/src/app/page.tsx
Note: This should be configured to publish an npm library ideally, but working with local files for the purposes of this demo.
- Maven
- Java 17
- node >= 18.17.0
From the backend directory:
# Build and publish generated code
mvn clean install
# Run the app
mvn spring-boot:run
See BooksControllerIT.java for a demonstrative integration test.
From the frontend directory:
# Install dependencies
npm install
# Run the app
npm run dev