This is an example usage of openapi-generator with typescript-fetch generator.
Requirements:
- node v12+
- yarn v1
- docker (for generating the api client)
Installation:
- Clone the repository
- Install dependencies
yarn --frozen-lockfile
- Generate the API client
yarn generate-api
- Run the application at http://localhost:3000
yarn dev
To (re-)generate the API client from schema, run:
yarn generate-api
It will read the schema.yml
file in the working directory and pass it into the generator.
It can be customized by passing the schema filename:
yarn generate-api custom-schema.yml
The generated output will be in the src/api/generated-api
directory.
OpenAPI Generator imports specified schema.yml
file and generates the API classes in src/api/generated-api
directory.
The application creates ready-for-use API client with helpers for authentication in src/api/index.ts
.
Components import API client methods and make API calls.
API calls are intercepted in development environment with Mock Service Worker and optionally served with mocked data on demand. In production environment the interceptor is disabled removed from the application bundle.