## What Alter generated types base on `x-expanded-relations` OAS extension declared on schemaObjects. ## Why Often, API endpoints will automatically expand a model relations by default. They can also decorate a model with calculated totals. In order to more accurately represent the API, we wish to alter the generated types based on the expanded relations information. ## How - Follow the relation declaration signature as the backend controllers and the `expand` query param, i.e.: `items.variant.product`. - Introduce a custom `x-expended-relations` OAS extension. - Allow for organizing declared relations to help their maintenance. - Use traversal algorithms in codegen to support deeply nested relationships. - Use [type-fest](https://www.npmjs.com/package/type-fest)'s `Merge` and `SetRequired` to efficiently alter the types while enabling great intellisense for IDEs. Extra scope: * Added convenience yarn script to interact with the `medisa-oas` CLI within the monorepo. ## Test Include in the PR are two implementations of the x-expanded-relations on OAS schema, a simple and a complex one. ### Step 1 * Run `yarn install` * Run `yarn build` * Run `yarn medusa-oas oas --type combined --out-dir ~/tmp/oas` * Run `yarn medusa-oas client --type combined --component types --src-file ~/tmp/oas/combined.osa.json --out-dir ~/tmp/types` * Open `~/tmp/types/models/StoreRegionsRes` * Expect relations to be declared as required ### Step 2 * Open `~/tmp/types/models/StoreCartsRes` * Expect relations to be declared as required * Expect nested relations to have relations as required. ### Step 3 (optional) * Open `~/tmp/types` in an intellisense capable IDE * Within the `index.ts` file, attempt to declare a `const storeRegionRes: StoreRegionRes = {}` * Expect IDE to highlight that `countries` is a required field of `StoreRegionRes`
105 lines
4.2 KiB
JSON
105 lines
4.2 KiB
JSON
{
|
|
"name": "root",
|
|
"private": true,
|
|
"workspaces": {
|
|
"packages": [
|
|
"packages/*",
|
|
"packages/generated/*",
|
|
"packages/oas/*",
|
|
"integration-tests/**/*"
|
|
]
|
|
},
|
|
"devDependencies": {
|
|
"@babel/core": "^7.12.7",
|
|
"@babel/eslint-parser": "^7.15.8",
|
|
"@babel/node": "^7.12.6",
|
|
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
"@babel/plugin-transform-classes": "^7.10.4",
|
|
"@babel/plugin-transform-instanceof": "^7.10.4",
|
|
"@babel/plugin-transform-runtime": "^7.11.5",
|
|
"@babel/preset-env": "^7.11.5",
|
|
"@babel/preset-react": "^7.18.6",
|
|
"@babel/register": "^7.11.5",
|
|
"@babel/runtime": "^7.11.2",
|
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
"@typescript-eslint/parser": "^5.53.0",
|
|
"axios": "^0.21.4",
|
|
"axios-mock-adapter": "^1.19.0",
|
|
"babel-jest": "^26.6.3",
|
|
"babel-preset-medusa-package": "^1.0.0",
|
|
"cross-env": "^7.0.3",
|
|
"eslint": "^8.23.0",
|
|
"eslint-config-google": "^0.14.0",
|
|
"eslint-config-prettier": "^8.5.0",
|
|
"eslint-plugin-markdown": "^3.0.0",
|
|
"eslint-plugin-prettier": "^4.2.1",
|
|
"eslint-plugin-react": "^7.31.11",
|
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
"express": "^4.17.1",
|
|
"get-port": "^5.1.1",
|
|
"husky": "^7.0.4",
|
|
"import-from": "^3.0.0",
|
|
"jest": "^26.6.3",
|
|
"lint-staged": "^11.2.6",
|
|
"microbundle": "^0.13.3",
|
|
"pg-god": "^1.0.12",
|
|
"prettier": "^2.7.1",
|
|
"prettier-plugin-tailwindcss": "^0.2.3",
|
|
"resolve-cwd": "^3.0.0",
|
|
"ts-jest": "^26.5.6",
|
|
"ts-node": "^10.9.1",
|
|
"turbo": "^1.6.3",
|
|
"typedoc": "0.23.10",
|
|
"typedoc-frontmatter-plugin": "link:docs-util/typedoc-plugins/typedoc-frontmatter-plugin",
|
|
"typedoc-monorepo-link-types": "^0.0.2",
|
|
"typedoc-plugin-markdown": "^3.13.4",
|
|
"typedoc-plugin-merge-modules": "^4.0.1",
|
|
"typedoc-plugin-reference-excluder": "^1.0.0",
|
|
"typeorm": "^0.3.11"
|
|
},
|
|
"lint-staged": {
|
|
"*.{js,jsx,ts,tsx}": "yarn run lint",
|
|
"*.{md,yaml,yml}": "prettier --write"
|
|
},
|
|
"scripts": {
|
|
"hooks:install": "husky install",
|
|
"hooks:uninstall": "husky uninstall",
|
|
"build": "turbo run build --no-daemon",
|
|
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts,.tsx .",
|
|
"lint:docs": "eslint -c docs/.eslintrc.js --ignore-path docs/.eslintignore docs/content",
|
|
"prettier": "prettier",
|
|
"jest": "jest",
|
|
"test": "turbo run test --no-daemon --filter=!integration-tests-api --filter=!integration-tests-plugins --filter=!integration-tests-repositories",
|
|
"test:integration": "turbo run test --no-daemon --filter=integration-tests-api --filter=integration-tests-plugins --filter=integration-tests-repositories",
|
|
"test:integration:api": "turbo run test --no-daemon --filter=integration-tests-api",
|
|
"test:integration:plugins": "turbo run test --no-daemon --filter=integration-tests-plugins",
|
|
"test:integration:repositories": "turbo run test --no-daemon --filter=integration-tests-repositories",
|
|
"openapi:generate": "yarn ./packages/oas/oas-github-ci run ci",
|
|
"medusa-oas": "yarn ./packages/oas/medusa-oas-cli run medusa-oas",
|
|
"generate:services": "typedoc --options typedoc.services.js",
|
|
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
|
"generate:entities": "typedoc --options typedoc.entities.js",
|
|
"release:snapshot": "changeset publish --no-git-tags --snapshot --tag snapshot",
|
|
"generate:announcement": "node ./scripts/doc-change-release.js",
|
|
"develop": "ts-node --transpile-only ./integration-tests/development/server.js",
|
|
"develop:create:db": "ts-node --transpile-only ./integration-tests/development/create-database.js",
|
|
"release:next": "changeset publish --no-git-tags --snapshot --tag next",
|
|
"version:next": "changeset version --snapshot next",
|
|
"check:freshness": "node ./scripts/freshness-check.js"
|
|
},
|
|
"dependencies": {
|
|
"@changesets/changelog-github": "^0.4.8",
|
|
"@changesets/cli": "^2.26.0",
|
|
"@linear/sdk": "^1.22.0",
|
|
"@octokit/core": "^4.0.5",
|
|
"global": "^4.4.0",
|
|
"import-from": "^3.0.0"
|
|
},
|
|
"packageManager": "yarn@3.2.1",
|
|
"resolutions": {
|
|
"@redocly/cli/react": "^17.0.1",
|
|
"@redocly/cli/react-dom": "^17.0.1"
|
|
}
|
|
}
|