Skip to content

Typeid support #2034

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

Le0Developer
Copy link
Contributor

See #2033

This is a very rough draft. I originally tried to use the x-typeid-type property I proposed in jetify-com/typeid#45. Then I noticed there's an IR involved and decided to temporarily extract the type name from the example field instead (which I also had to add to the parsers/IR).

I've tested this by modifying the openapi-ts-fetch example. I downloaded the openapi.yml file and modified the id property of Order to be a typeid like this:

        id:
          type: string
          format: typeid
          example: order_1111

And added typeids: true, to the openapi-ts.config.ts file.

This produced this output:

type TypeID<T extends string> = `${T}_${string}`;

export type Order = {
  complete?: boolean;
  id?: TypeID<'order'>;
  /* ... */
}

Nice 🎉

Currently the TypeID declaration is always added. Which means if you enable the config option but don't use typeids, you'll get an unused type warning.

Questions

  • I want to use x-typeid-type instead of parsing the example value, but I'm unsure given the current IR infrastructure. I don't believe adding arbitrary extensions to the parser is maintainable. One I had was: what if the IR had an extra field which simply contained the original object or just x-* properties? This feels more future-proof to me.
  • Should TypeID<T> be exported or should consumers do User["id"] instead of TypeID<"user"> if they want to access the type themselves?
  • Should there be a concrete type per ID (eg type UserID = "user_${string}") instead of the TypeID "overlord" (or maybe both)? This would require extending the "State" interface to keep track of already generated ID types

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented May 12, 2025

⚠️ No Changeset found

Latest commit: 31bdccd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented May 12, 2025

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

Name Status Preview Comments Updated (UTC)
hey-api-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 9:48am

Copy link

pkg-pr-new bot commented May 12, 2025

Open in StackBlitz

@hey-api/client-axios

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-axios@2034

@hey-api/client-fetch

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-fetch@2034

@hey-api/client-next

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-next@2034

@hey-api/client-nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-nuxt@2034

@hey-api/nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2034

@hey-api/openapi-ts

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2034

@hey-api/vite-plugin

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2034

commit: 31bdccd

Copy link

codecov bot commented May 12, 2025

Codecov Report

Attention: Patch coverage is 2.04082% with 48 lines in your changes missing coverage. Please review.

Project coverage is 22.59%. Comparing base (66f89a4) to head (31bdccd).

Files with missing lines Patch % Lines
...enapi-ts/src/plugins/@hey-api/typescript/plugin.ts 0.00% 39 Missing ⚠️
...ages/openapi-ts/src/openApi/2.0.x/parser/schema.ts 0.00% 3 Missing ⚠️
...ages/openapi-ts/src/openApi/3.0.x/parser/schema.ts 0.00% 3 Missing ⚠️
...ages/openapi-ts/src/openApi/3.1.x/parser/schema.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2034      +/-   ##
==========================================
- Coverage   22.64%   22.59%   -0.05%     
==========================================
  Files         252      252              
  Lines       21475    21524      +49     
  Branches      818      818              
==========================================
+ Hits         4862     4863       +1     
- Misses      16607    16655      +48     
  Partials        6        6              
Flag Coverage Δ
unittests 22.59% <2.04%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant