## 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`
Medusa
Documentation | Medusa Admin Demo | Website
An open source composable commerce engine built for developers.
Getting Started
Follow our quickstart guide to learn how to set up a Medusa server.
Requirements
You can check out this documentation for details about setting up your environment.
What is Medusa
Medusa is an open source composable commerce engine built with Node.js. Medusa enables developers to build scalable and sophisticated commerce setups with low effort and great developer experience.
You can learn more about Medusa’s architecture in our documentation.
Features
You can learn about all of the ecommerce features that Medusa provides in our documentation.
Roadmap
You can view our roadmap with features that are planned, started, and completed on the Roadmap discussion category.
Plugins
Check out our available plugins that you can install and use instantly on your Medusa server.
Contributions
Please check our contribution guide for details about how to contribute to both our codebase and our documentation.
Upgrade Guides
Follow our upgrade guides on the documentation to keep your Medusa project up-to-date.
Community & Support
Use these channels to be part of the community, ask for help while using Medusa, or just learn more about Medusa:
- Discord: This is the main channel to join the community. You can ask for help, showcase your work with Medusa, and stay up to date with everything Medusa.
- GitHub Issues: for sending in any issues you face or bugs you find while using Medusa.
- GitHub Discussions: for joining discussions and submitting your ideas.
- Medusa Blog: find diverse tutorials and company news.
License
Licensed under the MIT License