mirror of https://github.com/grafana/grafana.git
Provisioning: Fix OpenAPI generation (#109513)
* post-process spec * update client * fix the openapi * revert playlist change * Fix unmanaged resource counts --------- Co-authored-by: Roberto Jimenez Sanchez <roberto.jimenez@grafana.com>
This commit is contained in:
parent
2345da5100
commit
edcb6e6895
|
@ -793,7 +793,7 @@ func (b *APIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.OpenAPI, err
|
|||
repoprefix := root + "namespaces/{namespace}/repositories/{name}"
|
||||
defs := b.GetOpenAPIDefinitions()(func(path string) spec.Ref { return spec.Ref{} })
|
||||
defsBase := "github.com/grafana/grafana/apps/provisioning/pkg/apis/provisioning/v0alpha1."
|
||||
refsBase := "com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1."
|
||||
refsBase := "com.github.grafana.grafana.apps.provisioning.pkg.apis.provisioning.v0alpha1."
|
||||
|
||||
sub := oas.Paths.Paths[repoprefix+"/test"]
|
||||
if sub != nil {
|
||||
|
@ -1076,12 +1076,12 @@ spec:
|
|||
// Add any missing definitions
|
||||
//-----------------------------
|
||||
for k, v := range defs {
|
||||
clean := strings.Replace(k, defsBase, "com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.", 1)
|
||||
clean := strings.Replace(k, defsBase, "com.github.grafana.grafana.apps.provisioning.pkg.apis.provisioning.v0alpha1.", 1)
|
||||
if oas.Components.Schemas[clean] == nil {
|
||||
oas.Components.Schemas[clean] = &v.Schema
|
||||
}
|
||||
}
|
||||
compBase := "com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1."
|
||||
compBase := "com.github.grafana.grafana.apps.provisioning.pkg.apis.provisioning.v0alpha1."
|
||||
schema := oas.Components.Schemas[compBase+"RepositoryViewList"].Properties["items"]
|
||||
schema.Items = &spec.SchemaOrArray{
|
||||
Schema: &spec.Schema{
|
||||
|
@ -1128,6 +1128,10 @@ spec:
|
|||
schema.Items = countSpec
|
||||
oas.Components.Schemas[compBase+"ResourceStats"].Properties["instance"] = schema
|
||||
|
||||
schema = oas.Components.Schemas[compBase+"ResourceStats"].Properties["unmanaged"]
|
||||
schema.Items = countSpec
|
||||
oas.Components.Schemas[compBase+"ResourceStats"].Properties["unmanaged"] = schema
|
||||
|
||||
schema = oas.Components.Schemas[compBase+"ResourceStats"].Properties["managed"]
|
||||
schema.Items = managerSpec
|
||||
oas.Components.Schemas[compBase+"ResourceStats"].Properties["managed"] = schema
|
||||
|
|
|
@ -53,7 +53,7 @@ func (b *APIBuilder) GetAPIRoutes(gv schema.GroupVersion) *builder.APIRoutes {
|
|||
MediaTypeProps: spec3.MediaTypeProps{
|
||||
Schema: &spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.ResourceStats"),
|
||||
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.apps.provisioning.pkg.apis.provisioning.v0alpha1.ResourceStats"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -101,7 +101,7 @@ func (b *APIBuilder) GetAPIRoutes(gv schema.GroupVersion) *builder.APIRoutes {
|
|||
MediaTypeProps: spec3.MediaTypeProps{
|
||||
Schema: &spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryViewList"),
|
||||
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.apps.provisioning.pkg.apis.provisioning.v0alpha1.RepositoryViewList"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -853,6 +853,16 @@ export type JobResourceSummary = {
|
|||
update?: number;
|
||||
write?: number;
|
||||
};
|
||||
export type RepositoryUrLs = {
|
||||
/** Compare this version to the target branch */
|
||||
compareURL?: string;
|
||||
/** A URL that will create a new pull request for this branch */
|
||||
newPullRequestURL?: string;
|
||||
/** A URL pointing to the repository this lives in */
|
||||
repositoryURL?: string;
|
||||
/** A URL pointing to the file or ref in the repository */
|
||||
sourceURL?: string;
|
||||
};
|
||||
export type JobStatus = {
|
||||
errors?: string[];
|
||||
finished?: number;
|
||||
|
@ -869,6 +879,8 @@ export type JobStatus = {
|
|||
state?: 'error' | 'pending' | 'success' | 'warning' | 'working';
|
||||
/** Summary of processed actions */
|
||||
summary?: JobResourceSummary[];
|
||||
/** URLs contains URLs for the reference branch or commit if applicable. */
|
||||
url?: RepositoryUrLs;
|
||||
};
|
||||
export type Job = {
|
||||
/** APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */
|
||||
|
@ -1176,16 +1188,6 @@ export type ResourceObjects = {
|
|||
/** For write events, this will return the value that was added or updated */
|
||||
upsert?: Unstructured;
|
||||
};
|
||||
export type ResourceUrLs = {
|
||||
/** Compare this version to the target branch */
|
||||
compareURL?: string;
|
||||
/** A URL that will create a new pull requeset for this branch */
|
||||
newPullRequestURL?: string;
|
||||
/** A URL pointing to the repository this lives in */
|
||||
repositoryURL?: string;
|
||||
/** A URL pointing to the this file in the repository */
|
||||
sourceURL?: string;
|
||||
};
|
||||
export type ResourceWrapper = {
|
||||
/** APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */
|
||||
apiVersion?: string;
|
||||
|
@ -1206,7 +1208,7 @@ export type ResourceWrapper = {
|
|||
/** The modified time in the remote file system */
|
||||
timestamp?: Time;
|
||||
/** Typed links for this file (only supported by external systems, github etc) */
|
||||
urls?: ResourceUrLs;
|
||||
urls?: RepositoryUrLs;
|
||||
};
|
||||
export type ResourceListItem = {
|
||||
folder?: string;
|
||||
|
@ -1310,6 +1312,8 @@ export type ResourceStats = {
|
|||
/** Stats for each manager */
|
||||
managed?: ManagerStats[];
|
||||
metadata?: any;
|
||||
/** Stats across all unified storage When legacy storage is still used, this will offer a shim */
|
||||
unmanaged?: ResourceCount[];
|
||||
};
|
||||
export const {
|
||||
useListJobQuery,
|
||||
|
|
|
@ -69,6 +69,11 @@ function processOpenAPISpec(spec: OpenAPIV3.Document) {
|
|||
const newSchemas: Record<string, unknown> = {};
|
||||
for (const schemaKey of Object.keys(newSpec.components.schemas)) {
|
||||
const newKey = simplifySchemaName(schemaKey);
|
||||
if (newSchemas[newKey]) {
|
||||
// This can happen when invalid specs are used, although ignoring the error will work
|
||||
// it is better to fix the spec to avoid confusion.
|
||||
throw new Error(`Duplicate schema key found: ${newKey}. from: ${schemaKey}`);
|
||||
}
|
||||
|
||||
const schemaObject = newSpec.components.schemas[schemaKey];
|
||||
updateRefs(schemaObject);
|
||||
|
|
Loading…
Reference in New Issue