The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/packages/grafana-alerting/scripts/codegen.ts

48 lines
1.7 KiB

/**
* This script will generate TypeScript type definitions and a RTKQ clients for the alerting k8s APIs.
*
* Run `yarn run codegen` from the "grafana-alerting" package to invoke this script.
*
* API clients will be placed in "src/grafana/api/<version>/api.gen.ts"
*/
import type { ConfigFile } from '@rtk-query/codegen-openapi';
// ℹ append versions here to generate additional API clients
const VERSIONS = ['v0alpha1'] as const;
const GROUP = 'notifications.alerting.grafana.app' as const;
type OutputFile = Omit<ConfigFile, 'outputFile'>;
type OutputFiles = Record<string, OutputFile>;
const outputFiles = VERSIONS.reduce<OutputFiles>((acc, version) => {
// we append the version here so we export versioned API clients from this package without having to re-export with an alias
const exportName = 'alertingAPI';
// ℹ these snapshots are generated by running "go test pkg/tests/apis/openapi_test.go" and "scripts/process-specs.ts",
// see the README in the "openapi_snapshots" directory
const schemaFile = `../../../data/openapi/${GROUP}-${version}.json`;
// ℹ make sure there is a API file in each versioned directory
const apiFile = `../src/grafana/api/${version}/api.ts`;
// output each api client into a versioned directory
const outputPath = `../src/grafana/api/${version}/api.gen.ts`;
acc[outputPath] = {
exportName,
schemaFile,
apiFile,
tag: true, // generate tags for cache invalidation
} satisfies OutputFile;
return acc;
}, {});
export default {
// these are intentionally empty but will be set for each versioned config file
exportName: '',
schemaFile: '',
apiFile: '',
outputFiles,
} satisfies ConfigFile;