Files
medusa-store/packages/oas/medusa-oas-cli/package.json
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

44 lines
1.0 KiB
JSON

{
"name": "@medusajs/medusa-oas-cli",
"version": "0.1.0",
"description": "OAS CLI",
"main": "dist/index.js",
"bin": {
"medusa-oas": "./dist/index.js"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/oas/medusa-oas-cli"
},
"publishConfig": {
"access": "public"
},
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"ts-node": "^10.9.1",
"typescript": "4.9.5"
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"build": "tsc --build",
"cli": "ts-node src/index.ts",
"test": "jest --passWithNoTests",
"test:unit": "jest --passWithNoTests"
},
"dependencies": {
"@medusajs/medusa": "*",
"@medusajs/openapi-typescript-codegen": "*",
"@readme/openapi-parser": "^2.4.0",
"@types/lodash": "^4.14.191",
"commander": "^10.0.0",
"lodash": "^4.17.21",
"openapi3-ts": "^3.1.2",
"swagger-inline": "^6.1.0"
}
}