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: add @pinia-colada/sdk plugin #1680

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

josh-hemphill
Copy link

@josh-hemphill josh-hemphill commented Feb 7, 2025

There's some room for improvement, and people may want a different sdk style or abstracted, but I thought this was a good starting point to share and get some feedback on.

Right now it tries to detect whether to wrap endpoints in createQuery or createMutation based on first overrides if they exist, then if it's a GET or DELETE endpoint it'll assume createQuery, and finally if there's no body schema it will fall back to createQuery; there's OpenAPI extension that seems like it'd be a good indicator (x-readonly), but the extensions don't seem to be available yet, so I just commented that out with a ToDo.

Maybe closes #1242
closes #1159

Copy link

stackblitz bot commented Feb 7, 2025

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

Copy link

changeset-bot bot commented Feb 7, 2025

🦋 Changeset detected

Latest commit: 9e4cc3d

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

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Minor

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

Copy link

vercel bot commented Feb 7, 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 Apr 9, 2025 9:32am

Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

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

@josh-hemphill this is amazing! Let's figure out the details, but I'll be more than happy to merge this. I sent you a request on LinkedIn if you'd like to connect and talk about your experience writing this plugin + the details above

_handler: handler,
exportFromIndex: true,
name: '@pinia-colada/sdk',
output: 'queries',
Copy link
Member

Choose a reason for hiding this comment

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

This file would then also be named colada if you agree with the change above. We might allow users to rename it one day, but for now I'd prefer consistency over customisation

* Group queries by tag into separate files?
* @default false
*/
groupByTag?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the reasoning behind offering this functionality?

Copy link
Author

@josh-hemphill josh-hemphill Feb 7, 2025

Choose a reason for hiding this comment

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

It a preference that wasn't available with the current sdk plugin. It's very Vue in style though; it allows for a decent amount of lazy-loading and/or treeshaking if you're following the standard Vue import patterns, just importing for the contexts you need in individual Vue SFC files.
You can still import the root index file to get everything in one go, but can progressively add narrower import contexts to components to cut down on bundled component sizes.
And with Vite auto-import and type caching, a lot of the context narrowing can happen behind the scenes at build time if it has separate files to work with

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the context! I'd like to see this in snapshot tests, it will be way easier to reason through it. We will most likely want to add this to SDKs too, it's just a matter of priority

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see added some snapshot tests so we can see the final output + typecheck in CI

Copy link
Author

Choose a reason for hiding this comment

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

Should I add a scenario to the openapi-ts\test\plugins.test.ts or add file snapshots to this directory, or both? Since I'm not sure the scenarios are specifically covering the behavior of this plugin, though not sure how much that matters.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please. Drop a few tests there running through various permutations of these configs, whatever you think is necessary to cover, and then pnpm openapi-ts test:update. I will likely need to refactor this again in the future, but it does the job for now

@mrlubos
Copy link
Member

mrlubos commented Feb 7, 2025

@josh-hemphill for the failing CI, you need to register this plugin in https://github.com/hey-api/openapi-ts/blob/2dc380eabc17c723654beb04ecd7bce6d33d3b49/packages/openapi-ts/src/plugins/index.ts and add it to types in https://github.com/hey-api/openapi-ts/blob/2dc380eabc17c723654beb04ecd7bce6d33d3b49/packages/openapi-ts/src/plugins/types.d.ts. I assume you've been importing it manually up to this point? This will make it so that it's readily available in the config.

@mrlubos
Copy link
Member

mrlubos commented Feb 7, 2025

Later, I will write documentation for the plugin once we've got the API finalised and test snapshots. I will also ask you to add pnpm changeset so you get the credit in the release

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.

Pinia Colada plugin Vue client / vue data loader plugin
2 participants