Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codegen): commit generated client types to codebase #3492

Merged
merged 11 commits into from
Mar 16, 2023

Conversation

patrick-medusajs
Copy link
Contributor

@patrick-medusajs patrick-medusajs commented Mar 16, 2023

What

Commit generated client types to codebase.

Why

As a developer, it will provides better visibility on the impact of OAS changes to the generated type. Also allow to browse the types on GitHub.

How

  • Remove /lib from .gitignore
  • Add a non-blocking github action check validating if the latest generated build has been committed.
    • Runs yarn build --force --no-cache on GitHub. Caching was creating false positives.
    • Use git status and filter the output to target only packages/generated directory.

Test

Proof of a failing check:
https:/medusajs/medusa/actions/runs/4432323763/jobs/7776235128

UPDATE: Failing check after updating branch with latest develop
https:/medusajs/medusa/actions/runs/4436707954/jobs/7785472045

@patrick-medusajs patrick-medusajs self-assigned this Mar 16, 2023
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2023

🦋 Changeset detected

Latest commit: e70545e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/client-types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
medusa-docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 16, 2023 at 4:09PM (UTC)

Copy link
Contributor Author

@patrick-medusajs patrick-medusajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review: highlighting noteworthy code changes

Comment on lines +14 to +15
FILE_CHANGES=$(git status --porcelain=v1 | grep 'packages/generated')
FILE_CHANGES_COUNT=$(git status --porcelain=v1 | grep 'packages/generated' | wc -l)
Copy link
Contributor Author

@patrick-medusajs patrick-medusajs Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +36 to +37
- name: Build Packages - Force
run: yarn build --force --no-cache
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force build

/* tslint:disable */
/* eslint-disable */

export * from "./models"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Would it make sense in the end if we have multiple export from here, to namespace them like export * as Models so that when you import a type you now what it reference e.g Models.Address. It would avoid any collision as well if it happen that we attribute the same name in a different place. wdyt? This would be more of a convention like I am suggesting for medusa/types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tenants for this initiative was to be a drop-in replacement of the current type imports from @medusajs/medusa in client code. I would not impose a namespace on end users. import * as Models can be used if need be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we export something else than the models later, the user will not be able to do as Models as it would also includes the rest. I agree that it is a drop in replacement so let’s not take this comment into account for now 👍

/* eslint-disable */
import { SetRelation, Merge } from "../core/ModelUtils"

export interface AdminDeleteDiscountsDiscountConditionsConditionParams {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: All those interface shouldn't extends FindParams instead? Maybe not since it is regenerated if we change something. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, FindParams does not exist in our OAS realm. Parameter definition in OAS does not have the same composition capabilities as TS. That is why we have a lot of repetition of fields and expand in our OAS. As an example.

In order to achieve bundling of query Params into a type, we had to customize the codegen lib by introducing our own x-codegen.queryParams OAS extension. You can find the code here.

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - love the GitHub Action 💯

@kodiakhq kodiakhq bot merged commit e6e5291 into develop Mar 16, 2023
@kodiakhq kodiakhq bot deleted the feat/codegen-build-commit branch March 16, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants