Skip to content

Commit

Permalink
Chore: automatically fetch CGW schema (#4834)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Jan 27, 2025
1 parent 3bf6ab7 commit 44e8c1e
Show file tree
Hide file tree
Showing 11 changed files with 1,980 additions and 1,784 deletions.
2 changes: 2 additions & 0 deletions apps/mobile/src/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export const mockSwapTransfer: SwapTransferTransactionInfo = {
buyAmount: '50000000000000000',
executedSellAmount: '50000000000000000',
executedBuyAmount: '50000000000000000',
executedFee: '1000000000000000',
executedFeeToken: fakeToken,
sellToken: fakeToken2,
buyToken: fakeToken,
explorerUrl: 'http://google.com',
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/utils/transaction-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import type {
ModuleExecutionInfo,
TransactionDetails,
TransactionInfo,
SwapTransferTransactionInfo,
TwapOrderTransactionInfo,
ConflictHeaderQueuedItem,
Expand All @@ -32,6 +31,8 @@ import type {

import { HistoryTransactionItems, PendingTransactionItems } from '@safe-global/store/gateway/types'

type TransactionInfo = Transaction['txInfo']

const TransactionStatus = {
AWAITING_CONFIRMATIONS: 'AWAITING_CONFIRMATIONS',
AWAITING_EXECUTION: 'AWAITING_EXECUTION',
Expand Down
24 changes: 14 additions & 10 deletions packages/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@ import { setBaseUrl } from '@safe-global/store'
setBaseUrl('YOUR_API_BASE_URL')
```

## Automatic code generation from the Client's Gateway OpenAPI
## Automatic code generation from the Client Gateway's OpenAPI

This package includes a script to generate the necessary boilerplate API code from the Client-Gateway(CGW)'s OpenAPI specification using @rtk-query/codegen-openapi.
This package includes a script to generate the necessary boilerplate API code from the Client Gateway (CGW)'s OpenAPI specification using **@rtk-query/codegen-openapi**.

## Prerequisites

1. You've initialized the monorepo and installed all dependencies.
2. The openapi-config.ts file is correctly configured in this package with your OpenAPI specification details.
3. You've updated the scripts/api-schema/schema.json file with the latest OpenAPI specification.

> [!NOTE]
> To get the latest OpenAPI schema look at the output from the `/api-json` endpoint of the CGW.
2. The `openapi-config.ts` file is correctly configured in this package with your OpenAPI specification details.
3. If you're running your own CGW service, set the `PRODUCTION_CGW_API_URL` env variable.

## Running the Code Generation Script

From the mono-repo root directory, run the following command:

```bash
yarn workspace @safe-global/store generate-api
yarn workspace @safe-global/store build
```

or, for staging API:

```bash
yarn workspace @safe-global/store build:dev
```

This will:

- Use the configuration provided in the openapi-config.ts file.
- Gerate the API code using @rtk-query/codegen-openapi.
- Fetch the OpenAPI schema.
- Use the configuration provided in the `openapi-config.ts` file.
- Gerate the API code using **@rtk-query/codegen-openapi**.
6 changes: 5 additions & 1 deletion packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"version": "1.0.0",
"scripts": {
"test": "jest",
"generate-api": " npx @rtk-query/codegen-openapi scripts/openapi-config.ts"
"fetch-schema": "ts-node ./scripts/fetch-schema.ts > scripts/api-schema/schema.json",
"generate-api": "npx @rtk-query/codegen-openapi scripts/openapi-config.ts",
"build": "yarn fetch-schema && yarn generate-api",
"build:dev": "NODE_ENV=dev yarn fetch-schema && yarn generate-api",
"build:local": "NODE_ENV=local yarn fetch-schema && yarn generate-api"
},
"devDependencies": {
"@types/jest": "^29.5.14",
Expand Down
Loading

0 comments on commit 44e8c1e

Please sign in to comment.