7nohe / openapi-react-query-codegen

OpenAPI React Query Codegen is a code generator for creating React Query (also known as TanStack Query) hooks based on your OpenAPI schema.
https://openapi-react-query-codegen.vercel.app
MIT License
298 stars 30 forks source link

feat: Update `@hey-api/openapi-ts` version and re-enable namespacing enums #136

Closed collink closed 3 months ago

collink commented 3 months ago

I noticed that after updating to 1.4.1, that enums were being spit out next to the types instead of namespaced like previously. After some digging, I found that this was a @hey-api/openapi-ts issue which was resolved this week with a PR and the release of v0.52.0.

This PR does the following:

Looks like a huge diff, but it's almost entirely pnpm-lock.json, which we can just leave if you like, or you could re-run so that maybe the diff is smaller?

Why is this change important? The issue is that if you have enums defined in your OAPI YAML, @hey-api/openapi-ts (prior to v0.52.0) is depositing the TS enums directly next to the types, so you end up with enums that look like this:

export type Job = {
  // ...
  status: 'PENDING' | 'DONE',
  // ...
}

export enum status6 {
  PENDING: 'PENDING',
  DONE: 'DONE',
}

Before this change (and with this PR), that would look more like this:

export type Job = {
  // ...
  status: 'PENDING' | 'DONE',
  // ...
}

export namespace Job {
  export enum status {
    PENDING: 'PENDING',
    DONE: 'DONE',
  }
}

It's SO much less ambiguous to be able to use Job.status.DONE in my code than status6.DONE. 😅

collink commented 3 months ago

@7nohe @seriouslag I saw that there's a couple-week-old PR open for bumping the @hey-api/openapi-ts version, but this one bumps it to the current version. I was able to build and generate correctly without any major changes (just some type-related tweaks). Thanks again for the lib!

7nohe commented 3 months ago

@collink Sorry for the late reply. I would appreciate it if you could resolve the conflicts.

collink commented 3 months ago

@collink Sorry for the late reply. I would appreciate it if you could resolve the conflicts.

@7nohe no problem! All done 😄