add conversion

This commit is contained in:
Ryan McKinley
2025-10-16 16:14:27 +03:00
parent 2614a917de
commit 6df663584c
3 changed files with 23 additions and 63 deletions
@@ -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
+4 -1
View File
@@ -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, "/", "_"))
}
@@ -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",