From 6df663584cdd4466b4d8b6b62198c97af1fe54a0 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 16 Oct 2025 16:14:27 +0300 Subject: [PATCH] add conversion --- .../apis/datasource/hardcoded/testdata.go | 29 +++++------ pkg/registry/apis/datasource/openapi.go | 5 +- ...tdata.datasource.grafana.app-v0alpha1.json | 52 ++----------------- 3 files changed, 23 insertions(+), 63 deletions(-) diff --git a/pkg/registry/apis/datasource/hardcoded/testdata.go b/pkg/registry/apis/datasource/hardcoded/testdata.go index 66f7cc73ca2..3e811b0e6ae 100644 --- a/pkg/registry/apis/datasource/hardcoded/testdata.go +++ b/pkg/registry/apis/datasource/hardcoded/testdata.go @@ -9,29 +9,28 @@ import ( func TestdataOpenAPIExtension() (*datasourceV0.DataSourceOpenAPIExtension, error) { oas := &datasourceV0.DataSourceOpenAPIExtension{ - SecureValues: []datasourceV0.SecureValueInfo{{ - Key: "aaa", - Description: "describe aaa", - Required: true, - }, { - Key: "bbb", - Description: "describe bbb", - }}, + SecureValues: []datasourceV0.SecureValueInfo{ // empty + // { + // Key: "aaa", + // Description: "describe aaa", + // Required: true, + // }, { + // Key: "bbb", + // Description: "describe bbb", + // }, + }, } // Dummy spec p := &spec.Schema{} //SchemaProps: spec.SchemaProps{Type: []string{"object"}}} - p.Description = "HELLO!" - p.Required = []string{"url"} + p.Description = "Test data does not require any explicit configuration" + p.Required = []string{} p.AdditionalProperties = &spec.SchemaOrBool{Allows: false} p.Properties = map[string]spec.Schema{ - "url": *spec.StringProperty(), - "str": *spec.StringProperty(), // ??? must this be under jsonData? - "int64": *spec.Int64Property(), // ??? must this be under jsonData? + "url": *spec.StringProperty().WithDescription("not used"), } p.Example = map[string]any{ - "url": "http://xxxx", - "int64": 1234, + "url": "http://xxxx", } oas.DataSourceSpec = p diff --git a/pkg/registry/apis/datasource/openapi.go b/pkg/registry/apis/datasource/openapi.go index 870f81d2c8c..2f9af1ce7ca 100644 --- a/pkg/registry/apis/datasource/openapi.go +++ b/pkg/registry/apis/datasource/openapi.go @@ -3,6 +3,7 @@ package datasource import ( "fmt" "maps" + "slices" "strings" "k8s.io/kube-openapi/pkg/spec3" @@ -154,10 +155,12 @@ func (b *DataSourceAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.Op } v.Parameters = append(v.Parameters, ds.Parameters[0:2]...) for m, op := range builder.GetPathOperations(v) { - op.Tags = append(op.Tags, "Route") // Custom resource? if op.Extensions == nil { op.Extensions = make(spec.Extensions) } + if !slices.Contains(op.Tags, "Route") { + op.Tags = append(op.Tags, "Route") // Custom resource? + } tmp := strings.ReplaceAll(strings.ReplaceAll(k, "{", ""), "}", "") op.OperationId = fmt.Sprintf("%s_route%s", strings.ToLower(m), strings.ReplaceAll(tmp, "/", "_")) } 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 b28fe311947..1661c4d4188 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 @@ -1037,7 +1037,6 @@ "summary": "hello world", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route", @@ -1080,7 +1079,6 @@ "summary": "force a panic", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route_boom", @@ -1099,7 +1097,6 @@ }, "post": { "tags": [ - "Route", "Route" ], "operationId": "post_route_boom", @@ -1143,7 +1140,6 @@ "summary": "hello world", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route_scenarios", @@ -1187,7 +1183,6 @@ "description": "Get list of simulations", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route_sim_key", @@ -1213,7 +1208,6 @@ }, "post": { "tags": [ - "Route", "Route" ], "operationId": "post_route_sim_key", @@ -1274,7 +1268,6 @@ "description": "Get list of simulations", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route_sims", @@ -1318,7 +1311,6 @@ "summary": "Get streaming response", "get": { "tags": [ - "Route", "Route" ], "operationId": "get_route_stream", @@ -1414,12 +1406,9 @@ "summary": "Echo any request", "post": { "tags": [ - "Route", - "Route", - "Route", "Route" ], - "operationId": "post_route_test", + "operationId": "post_route_test_json", "requestBody": { "content": { "application/json": { @@ -1470,12 +1459,9 @@ "summary": "Echo any request", "post": { "tags": [ - "Route", - "Route", - "Route", "Route" ], - "operationId": "post_route_test", + "operationId": "post_route_test_json", "requestBody": { "content": { "application/json": { @@ -1575,25 +1561,15 @@ "components": { "schemas": { "DataSourceSpec": { - "description": "HELLO!", - "required": [ - "url" - ], + "description": "Test data does not require any explicit configuration", "properties": { - "int64": { - "type": "integer", - "format": "int64" - }, - "str": { - "type": "string" - }, "url": { + "description": "not used", "type": "string" } }, "additionalProperties": false, "example": { - "int64": 1234, "url": "http://xxxx" } }, @@ -1630,25 +1606,7 @@ }, "SecureValues": { "description": "custom secure value definition", - "required": [ - "aaa" - ], - "properties": { - "aaa": { - "description": "describe aaa", - "$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apimachinery.apis.common.v0alpha1.InlineSecureValue" - }, - "bbb": { - "description": "describe bbb", - "$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apimachinery.apis.common.v0alpha1.InlineSecureValue" - } - }, - "additionalProperties": false, - "example": { - "aaa": { - "create": "[REDACTED]" - } - } + "additionalProperties": false }, "com.github.grafana.grafana-plugin-sdk-go.backend.DataResponse": { "description": "todo... improve schema",