netlify / build

Netlify Build (node process) runs the build command, Build Plugins and bundles Netlify Functions. Can be run in Buildbot or locally using Netlify CLI
https://docs.netlify.com/configure-builds/build-plugins/
MIT License
218 stars 57 forks source link

Create types for the OpenAPI specification based on the swagger.json #5307

Closed lukasholzer closed 4 weeks ago

lukasholzer commented 1 year ago

Currently, our OpenAPI client is used everywhere. It's "the way™️" to access our API in all of our JavaScript Node.js projects. Like build, CLI, etc...

Sadly the client we expose don't have any types as it's a JavaScript class that generates the functions on the fly based on the @netlify/open-api package which is the swagger.json we are generating.

Thorough that we don't have any type safety when working with this package.

As a lot of types in the CLI and the build are based on the return types of the API methods we end up not having a proper type safety throughout the whole codebase which puts of in a brittle position when working with any all the time. To fix our upstream types in the CLI or the build it is required to get proper types from the API return methods.

Proposal

To fix our types we should autogenerate the functions on build time before releasing the package. This means we should generate all the JS methods as static functions in code as generating them on the fly in a constructor call. This is not only speeding up the API access (as we don't have to generate all the functions during runtime), furthermore, it helps us troubleshoot issues as we have an actual code generated we can inspect. When generating the code we can generate typescript with proper types by leveraging the typescript AST.

This should ultimately help us work with our API by having types available and should enable customers the same if they want to use the API inside build plugins where currently no documentation is available.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had activity in 1 year. It will be closed in 14 days if no further activity occurs. Thanks!

github-actions[bot] commented 4 weeks ago

This issue was closed because it had no activity for over 1 year.