Files
medusa-store/packages/oas
Patrick 1c40346e9e feat(codegen): openapi-typescript-codegen fork (#3272)
## What

Allow `medusa-oas` CLI to generate API client code from an OAS json file.

## Why

Manually maintaining API clients is time consuming and error prone. We wish to automate the process by using code generation strategies.

We also wish to eliminate direct import from `@medusajs/medusa` in clients which can lead to unwanted side effects like importing unnecessary dependencies.

## How

Fork and customize an OAS code generator library that is TypeScript friendly.

Attempt to match the interface and signature of our current client packages: `@medusajs/medusa-js`, `medusa-react`

Add a new `client` command to the `medusa-oas` CLI as the main interface to interact with the code generation tooling.

## Test

### Prerequisites 
* From the root of the monorepo:
* `yarn install`
* `yarn build`

### Case - all in one build
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-store --type store`
* Expect `~/tmp/client-store` to contain the following files and directories:
```
core/
hooks/
models/
services/
index.ts
MedusaStore.ts
useMedusaStore.tsx
```

### Case - types only
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-types --type store --component types`
* Expect `~/tmp/client-types` to contain the following files and directories:
```
models/
index.ts
```

### Case - client only
* From the root of the monorepo:
* Run `yarn medusa-oas oas --out-dir ~/tmp/oas --type store`
* Run `yarn medusa-oas client --src-file ~/tmp/oas/store.oas.json --out-dir ~/tmp/client-only --type store --component client --types-package @medusajs/client-types`
* Expect `~/tmp/client-only` to contain the following files and directories:
```
core/
services/
index.ts
MedusaStore.ts
```
2023-02-20 20:50:39 +00:00
..