You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in the frontend codebase most HTTP requests and responses are not typed. Any request payload can be passed when making HTTP call and then the response has any type which means that later developer doesn't have any restriction on how to use the data that's coming from the backend. This is error-prone and leads to type errors in the browser + bugs related to incorrect usage of API.
Ideally we should have a way of declaring TypeScript types based on Python models (we can probably use the approach of generating TypeScript types from OpenAPI schemas with tools like openapi-typescript or modelina ). The final result would be that if API contract changes and it affects / breaks frontend, we will know it during development, not after deployment.
There are several steps to achieve the final result: 1) Have a way to generate TypeScript types based on Python models and saving it within grafana-plugin directory
2) Use generated types on the frontend so that any HTTP request and response is correctly typed (#3331)
3) Automate generation of types (e.g. on prepush Git hook or similar). This way if changes in API breaks frontend, frontend build will automatically fail preventing us from introducing the bug (#3332)
This issue is about step 1)
Acceptance criteria
developer is able to manually generate / regenerate TypeScript types based on Python models
newly generated types are saved within grafana-plugin directory
Outcome
better type-safety in code
being able to catch type errors during development before they reach prod (shift left)
better developer experience thanks to increased number of type declarations and improved intellisense
The text was updated successfully, but these errors were encountered:
The current version of Grafana OnCall, at the time this issue was opened, is v1.3.57. If your issue pertains to an older version of Grafana OnCall, please be sure to list it in the PR description. Thank you 😄!
brojd
changed the title
Improve type-safety: generate TypeScript types based on Python models
Improve type-safety: generate TypeScript types based OpenAPI schema
Nov 15, 2023
brojd
changed the title
Improve type-safety: generate TypeScript types based OpenAPI schema
Improve type-safety: manually generate TS types based OpenAPI schema
Nov 15, 2023
# What this PR does
#3330
- add a script that generates TS type definitions based on OnCall API
OpenAPI schemas
- support adding custom properties on the frontend if needed
- add simple example of usage (for `'/labels/keys/'` endpoint)
## Checklist
- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
Problem
Currently in the frontend codebase most HTTP requests and responses are not typed. Any request payload can be passed when making HTTP call and then the response has
any
type which means that later developer doesn't have any restriction on how to use the data that's coming from the backend. This is error-prone and leads to type errors in the browser + bugs related to incorrect usage of API.Ideally we should have a way of declaring TypeScript types based on Python models (we can probably use the approach of generating TypeScript types from OpenAPI schemas with tools like openapi-typescript or modelina ). The final result would be that if API contract changes and it affects / breaks frontend, we will know it during development, not after deployment.
There are several steps to achieve the final result:
1) Have a way to generate TypeScript types based on Python models and saving it within
grafana-plugin
directory2) Use generated types on the frontend so that any HTTP request and response is correctly typed (#3331)
3) Automate generation of types (e.g. on prepush Git hook or similar). This way if changes in API breaks frontend, frontend build will automatically fail preventing us from introducing the bug (#3332)
This issue is about step 1)
Acceptance criteria
grafana-plugin
directoryOutcome
The text was updated successfully, but these errors were encountered: