Files
grafana/public/app/api/README.md
Alex Khomenko 618ffd0275 API clients: Add generator (#104093)
* Add API client generator

* Extract config entry template

* Fix index file

* Fix message and file pattern

* Fix generate-rtk template

* Match generated-api

* Format

* Split helpers

* Cleanup

* Remove unused helpers

* Simplify group name handling

* Run generate-apis

* Prettier

* Format + lint

* improve lint/format

* Optional filterEndpoints

* Format

* Update readme

* More updates

* Move the helpers out

* Switch to TS

* Cleanup types

* Add support for Enterprise

* Add comments

* Refactor endpoint handling and update README

* Simplify checks

* Do not register reducers and middleware for enterprise

* More docs updates

* Remove redundant sections

* Format gitignored files

* Add limitations

* Simplify types

* Simplify path logic

* Do not format OSS paths for enterprise

* dedupe

* format

* Simplify instructions

* Update lockfile

* Add comments

* Remove custom types
2025-04-25 09:42:37 +03:00

1.1 KiB
Raw Permalink Blame History

Generating RTK Query API Clients

To show the steps to follow, we are going to work on adding an API client to create a new dashboard. Just adapt the following guide to your use case.

1. Generate an OpenAPI snapshot

First, check if the group and the version are already present in openapi_test.go. If so, move on to the next step.
If you need to add a new block, you can check for the right group and version in the backend API call that you want to replicate in the frontend.

{
  Group:   "dashboard.grafana.app",
  Version: "v0alpha1",
}

Afterwards, you need to run the TestIntegrationOpenAPIs test. Note that it will fail the first time you run it. On the second run, it will generate the corresponding OpenAPI spec, which you can find in openapi_snapshots.

Note: You dont need to follow these two steps if the group youre working with is already in the openapi_test.go file.

2. Run the API generator script

Run yarn generate:api-client and follow the prompts. See API Client Generator for details.