diff --git a/pkg/registry/apis/datasource/openapi.go b/pkg/registry/apis/datasource/openapi.go index e424a7688be..050feeac046 100644 --- a/pkg/registry/apis/datasource/openapi.go +++ b/pkg/registry/apis/datasource/openapi.go @@ -29,7 +29,7 @@ func (b *DataSourceAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.Op if b.pluginJSON.Info.Build.Time > 0 { info["build"] = b.pluginJSON.Info.Build.Time } - oas.Info.VendorExtensible.AddExtension("plugin", info) + oas.Info.AddExtension("plugin", info) // The root api URL root := "/apis/" + b.datasourceResourceInfo.GroupVersion().String() + "/" diff --git a/pkg/tests/apis/helper.go b/pkg/tests/apis/helper.go index 379e3ac9734..ccb8fc1145e 100644 --- a/pkg/tests/apis/helper.go +++ b/pkg/tests/apis/helper.go @@ -873,10 +873,19 @@ func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h require.Failf(t, "Not OK", "Code[%d] %s", rsp.Response.StatusCode, string(rsp.Body)) } - var prettyJSON bytes.Buffer - err := json.Indent(&prettyJSON, rsp.Body, "", " ") + schema := map[string]any{} + err := json.Unmarshal(rsp.Body, &schema) + require.NoError(t, err) + info, found, err := unstructured.NestedMap(schema, "info", "plugin") + require.NoError(t, err) + if found { + delete(info, "version") // the version is unstable in test environments + err = unstructured.SetNestedMap(schema, info, "info", "plugin") + require.NoError(t, err) + } + + pretty, err := json.MarshalIndent(schema, "", " ") require.NoError(t, err) - pretty := prettyJSON.String() write := false fpath := filepath.Join(dir, fmt.Sprintf("%s-%s.json", gv.Group, gv.Version)) @@ -885,7 +894,7 @@ func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h // We can ignore the gosec G304 warning since this is a test and the function is only called with explicit paths body, err := os.ReadFile(fpath) if err == nil { - if !assert.JSONEq(t, string(body), pretty) { + if !assert.JSONEq(t, string(body), string(pretty)) { t.Logf("openapi spec has changed: %s", path) t.Fail() write = true diff --git a/pkg/tests/apis/openapi_snapshots/testdata.datasource.grafana.app-v0alpha1.json b/pkg/tests/apis/openapi_snapshots/testdata.datasource.grafana.app-v0alpha1.json index 396d72dc0d6..458016832a3 100644 --- a/pkg/tests/apis/openapi_snapshots/testdata.datasource.grafana.app-v0alpha1.json +++ b/pkg/tests/apis/openapi_snapshots/testdata.datasource.grafana.app-v0alpha1.json @@ -4,8 +4,7 @@ "description": "Generates test data in different forms", "title": "testdata.datasource.grafana.app/v0alpha1", "plugin": { - "plugin": "grafana-testdata-datasource", - "version": "12.4.0-pre" + "plugin": "grafana-testdata-datasource" } }, "paths": {