Skip to content

Files

Latest commit

e11e3e7 · Aug 21, 2024

History

History
68 lines (44 loc) · 1.92 KB

README.md

File metadata and controls

68 lines (44 loc) · 1.92 KB

OpenApi Generated Code Example

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.

Generation

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:

Java

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).

TypeScript

Note: This should be configured to publish an npm library ideally, but working with local files for the purposes of this demo.

Run

Pre-requisites

  • Maven
  • Java 17
  • node >= 18.17.0

Backend

From the backend directory:

# Build and publish generated code
mvn clean install
# Run the app
mvn spring-boot:run

Testing

See BooksControllerIT.java for a demonstrative integration test.

Frontend

From the frontend directory:

# Install dependencies
npm install
# Run the app
npm run dev