feat(codegen): x-expanded-relations #3442
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
expand
query param, i.e.:items.variant.product
.x-expended-relations
OAS extension.Merge
andSetRequired
to efficiently alter the types while enabling great intellisense for IDEs.Extra scope:
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
yarn install
yarn build
yarn medusa-oas oas --type combined --out-dir ~/tmp/oas
yarn medusa-oas client --type combined --component types --src-file ~/tmp/oas/combined.osa.json --out-dir ~/tmp/types
~/tmp/types/models/StoreRegionsRes
Step 2
~/tmp/types/models/StoreCartsRes
Step 3 (optional)
~/tmp/types
in an intellisense capable IDEindex.ts
file, attempt to declare aconst storeRegionRes: StoreRegionRes = {}
countries
is a required field ofStoreRegionRes