DataSource: Fix openapi spec (#112150)

This commit is contained in:
Ryan McKinley
2025-10-08 14:36:24 +03:00
committed by GitHub
parent 047c51be01
commit 13a3c46079
6 changed files with 1191 additions and 12 deletions
@@ -136,6 +136,10 @@ func (UnstructuredSpec) OpenAPIDefinition() openapi.OpenAPIDefinition {
s := schema_pkg_apis_datasource_v0alpha1_GenericDataSourceSpec(func(path string) spec.Ref {
return spec.MustCreateRef(path)
})
jsonData := spec.MapProperty(nil)
jsonData.AdditionalProperties = &spec.SchemaOrBool{Allows: true}
jsonData.Extensions = map[string]any{"x-kubernetes-preserve-unknown-fields": true}
s.Schema.Properties["jsonData"] = *jsonData
s.Schema.AdditionalProperties = &spec.SchemaOrBool{
Allows: true,
}
+3 -6
View File
@@ -24,7 +24,6 @@ import (
queryV0 "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic"
"github.com/grafana/grafana/pkg/configprovider"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/manager/sources"
"github.com/grafana/grafana/pkg/promlib/models"
@@ -50,7 +49,6 @@ type DataSourceAPIBuilder struct {
contextProvider PluginContextWrapper
accessControl accesscontrol.AccessControl
queryTypes *queryV0.QueryTypeDefinitionList
log log.Logger
configCrudUseNewApis bool
}
@@ -65,10 +63,10 @@ func RegisterAPIService(
reg prometheus.Registerer,
) (*DataSourceAPIBuilder, error) {
// We want to expose just a limited set of plugins
explictPluginList := features.IsEnabledGlobally(featuremgmt.FlagDatasourceAPIServers)
explicitPluginList := features.IsEnabledGlobally(featuremgmt.FlagDatasourceAPIServers)
// This requires devmode!
if !explictPluginList && !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) {
if !explicitPluginList && !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) {
return nil, nil // skip registration unless opting into experimental apis
}
@@ -91,7 +89,7 @@ func RegisterAPIService(
}
for _, pluginJSON := range pluginJSONs {
if explictPluginList && !slices.Contains(ids, pluginJSON.ID) {
if explicitPluginList && !slices.Contains(ids, pluginJSON.ID) {
continue // skip this one
}
@@ -155,7 +153,6 @@ func NewDataSourceAPIBuilder(
datasources: datasources,
contextProvider: contextProvider,
accessControl: accessControl,
log: log.New("grafana-apiserver.datasource"),
configCrudUseNewApis: configCrudUseNewApis,
}
if loadQueryTypes {
@@ -15,7 +15,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
queryV0 "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/ngalert/models"
)
@@ -28,7 +27,6 @@ func TestSubQueryConnect(t *testing.T) {
},
datasources: mockDatasources{},
contextProvider: mockContextProvider{},
log: log.NewNopLogger(),
},
}
@@ -73,7 +71,6 @@ func TestSubQueryConnectWhenDatasourceNotFound(t *testing.T) {
},
datasources: mockDatasources{},
contextProvider: mockContextProvider{},
log: log.NewNopLogger(),
},
}
+2 -3
View File
@@ -201,10 +201,9 @@ func getOpenAPIPostProcessor(version string, builders []APIGroupBuilder, gvs []s
keep := make([]map[string]any, 0, len(gvks))
for _, val := range gvks {
gvk, ok := val.(map[string]any)
if ok && gvk["version"] == "__internal" {
continue
if ok && gvk["group"] == gv.Group && gvk["version"] != "__internal" {
keep = append(keep, gvk) // only expose real versions in the same group
}
keep = append(keep, gvk)
}
v.Extensions["x-kubernetes-group-version-kind"] = keep
}
File diff suppressed because it is too large Load Diff
+3
View File
@@ -105,6 +105,9 @@ func TestIntegrationOpenAPIs(t *testing.T) {
}, {
Group: "shorturl.grafana.app",
Version: "v1alpha1",
}, {
Group: "testdata.datasource.grafana.app",
Version: "v0alpha1",
}}
for _, gv := range groups {
VerifyOpenAPISnapshots(t, dir, gv, h)