Closed Nick-Lucas closed 3 months ago
Run & review this pull request in StackBlitz Codeflow.
Latest commit: 7e4849562668b9a7658b5b1bb9c146500d834da5
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.
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
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 | Jun 16, 2024 3:24pm |
Marking this ready for review since I'd like to get feedback on the general direction before completing the TODOs I've written up
Hey @Nick-Luca I will have a look but currently busy with other projects for a few weeks
Hey @Nick-Luca I will have a look but currently busy with other projects for a few weeks
Thanks! I think so long as I have an idea what your views are on the direction, I can finish it off and dogfood a fork for a while. We have a pretty complex API in my org so plenty of corner cases to discover I'm sure
Okay I've left some comments with questions and TODOs, but it's time for dinner here so I'll be back on it tomorrow for the few bits I already know the answer to.
A few details I think we can get away with ignoring initially as they're limitations rather than bugs and I'm wary of this PR getting too big and lasting too long
Enjoy your dinner @Nick-Lucas. Do you consider this pull request ready for now?
Not quite ready to merge, I spotted at least one certain bug so I'll fix that
But definitely ready for some review on the meat of it
Okay @mrlubos this is ready I believe. I've updated the RFC in the PR body and also documented the proposed limitations for the first version of this. I've linked it locally to my team's codebase. We have a 13,500 line OpenAPI spec from SpringDoc and it helped me fix one mistake but the rest looks good.
I haven't got my own codebase compiling yet but that's because our BFF+UI are now on fire because a bunch of strings are now dates :D
This is amazing @Nick-Lucas, I will review it + write docs
Attention: Patch coverage is 11.60542%
with 457 lines
in your changes missing coverage. Please review.
Project coverage is 71.65%. Comparing base (
8cdd1e2
) to head (340cbeb
). Report is 2 commits behind head on main.:exclamation: Current head 340cbeb differs from pull request most recent head 7e48495
Please upload reports for the commit 7e48495 to get more accurate results.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@Nick-Lucas since this changes types from string to Date, aren't you going to have an issue where requests now expect Dates according to TypeScript, but since there's no request transformer, we want to send strings?
@Nick-Lucas since this changes types from string to Date, aren't you going to have an issue where requests now expect Dates according to TypeScript, but since there's no request transformer, we want to send strings?
Yes because that's how the types emission currently works. Every JS request lib I know will serialise the dates into ISO strings, so I'm not expecting an issue really, unless someone has a format:date-time but is using a custom string format they want to manually serialise to.
I was wondering if we need to flip around generation so that request/response types are generated and pull from the schemas (ie. request could be Date | string
and response gets a transformer) as opposed to now where we generate types from the schemas and then map those to the request/response types. Might also help with schema-less types which are inlined on the request/response definitions
Do you want to merge and release this as is? Seems e2e tests are failing btw
Do you want to merge and release this as is? Seems e2e tests are failing btw
Hm if tests are failing because of these changes I'll need to have a look on Monday, everything I ran was passing but I maybe didn't get to run everything locally.
Looks like the errors here are angular and due to window.api being undefined TypeError: Cannot destructure property 'ComplexService' of 'window.api' as it is undefined.
I didn't change anything that I would have thought affects this though so either something weird or the main branch is also failing 🤔
145 asks for a way to transform the underlying data of a response when Date is set on the type itself.
For some use cases this would be inapropriate since it could bloat bundle size, but for many this is desirable behaviour. Bundle size could also be optimised a bit, but generating raw code to convert types is about the most efficient you can get for runtime performance
This PR is a first crack at adding optional transforms to the project.
Proposal:
readonly responseTransformer?: (data: unknown) => unknown;
- this way we can apply a transform to the result inside the CancellablePromise wrapper, so long as we implement a few lines within each clienttypes: { dates: true }
withboolean | "types" | "types+transform"
and leavetrue
as justtypes
export const ModelName = (data: unknown) => ModelName
- typescript is really great in this area, a type and a variable can have the same name so long as they're exported from the same file, and typescript will use the correct one contextuallyProposed limitations for the first iteration:
Work to do:
The above proposal produces output like the below: