Skip to content

Commit

Permalink
Streamline the OpenAPI client generation step
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Muehlberger <[email protected]>
  • Loading branch information
t-muehlberger committed Dec 20, 2024
1 parent 73f5a80 commit 7efc694
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,27 @@ npm install

### Generating the API Client

Before building the frontend, generate the API client:
Before building the frontend, it is required generate the API client code. This step ensures that the frontend is able to communicate with the backend API.

1. Retrieve the current OpenAPI specification from the backend as described in [Retrieving the OpenAPI specification](../server/README.md#retrieving-the-openapi-specification).
2. Save the specification as `openapi.json` in the root directory.
3. Run:
> **Note:** Regenerate the client whenever there are API changes to avoid build errors.
```bash
npm run generate-client
```
**Using the Latest OpenAPI Specification**

> **Note:** Regenerate the client whenever there are API changes to avoid build errors.
The easiest way to generate the API client is by running the following command. This will use the latest OpenAPI specification based on the `main` branch, available [hrer](https://akvorrat.github.io/dearmep/openapi.json).

npm run generate-client:remote

**Using a Locally Running Server**

In case the server is running locally, it is possible to generate the API client with the following command. This method is recommended because it guarantees that the generated client matches the API version of the local server:

npm run generate-client:local

**Using a Custom OpenAPI Specification**

Alternatively, it is possible to generate the API client using a custom OpenAPI specification. Save the specification file as `openapi.json` in the root directory of the repository. For guidance on generating this file, refer to [Retrieving the OpenAPI specification](../server/README.md#retrieving-the-openapi-specification).

npm run generate-client

### Running the Development Server

Expand Down
4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"format": "prettier --write .",
"lint": "ng lint",
"lint:fix": "ng lint --fix",
"generate-client": "ng-openapi-gen --input ../openapi.json --output src/app/api",
"generate-client": "ng-openapi-gen --input '../openapi.json' --output src/app/api",
"generate-client:local": "ng-openapi-gen --input 'http://localhost:8000/openapi.json' --output src/app/api",
"generate-client:remote": "ng-openapi-gen --input 'https://akvorrat.github.io/dearmep/openapi.json' --output src/app/api",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
Expand Down

0 comments on commit 7efc694

Please sign in to comment.