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

Improve type-safety: manually generate TS types based OpenAPI schema #3330

Closed
Tracked by #3338
brojd opened this issue Nov 13, 2023 · 1 comment
Closed
Tracked by #3338

Improve type-safety: manually generate TS types based OpenAPI schema #3330

brojd opened this issue Nov 13, 2023 · 1 comment
Assignees

Comments

@brojd
Copy link
Contributor

brojd commented Nov 13, 2023

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 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
@brojd brojd added the feature request New feature or request label Nov 13, 2023
Copy link
Contributor

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 brojd added involved:Frontend and removed feature request New feature or request more info needed labels Nov 13, 2023
@brojd 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 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
@brojd brojd self-assigned this Nov 17, 2023
github-merge-queue bot pushed a commit that referenced this issue Nov 29, 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)
@brojd brojd closed this as completed Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant