diff --git a/go.mod b/go.mod index cd8ca60..95e68a6 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.21.3 require ( github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/davecgh/go-spew v1.1.1 - github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240214042209-d791fc906236 + github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240216223058-4ae1f0c8c645 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/stretchr/testify v1.8.4 golang.org/x/oauth2 v0.16.0 diff --git a/go.sum b/go.sum index 356e66d..26127b3 100644 --- a/go.sum +++ b/go.sum @@ -127,6 +127,8 @@ github.com/grafana/grafana-google-sdk-go v0.2.1 h1:XeFdKnkXBjOJjXc1gf4iMx4h5aCHT github.com/grafana/grafana-google-sdk-go v0.2.1/go.mod h1:RiITSHwBhqVTTd3se3HQq5Ncs/wzzhTB9OK5N0J0PEU= github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240214042209-d791fc906236 h1:jdxnjX5T2W25kMrNXwAD4WQjLYqha6Isojb5aeehoEw= github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240214042209-d791fc906236/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o= +github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240216223058-4ae1f0c8c645 h1:A0RzKzzeSZWl9pCIfQkRBvm0qVr14aEmSSrVfqmVs4c= +github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240216223058-4ae1f0c8c645/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= diff --git a/pkg/models/query_test.go b/pkg/models/query_test.go deleted file mode 100644 index 5066b6d..0000000 --- a/pkg/models/query_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package models - -import ( - "reflect" - "testing" - - "github.com/grafana/grafana-plugin-sdk-go/experimental/query" - "github.com/grafana/grafana-plugin-sdk-go/experimental/query/schema" - "github.com/stretchr/testify/require" -) - -func TestQueryTypeDefinitions(t *testing.T) { - builder, err := schema.NewBuilder( - schema.BuilderOptions{ - BasePackage: "github.com/grafana/google-sheets-datasource/pkg/models", - CodePath: "./", - }, - schema.QueryTypeInfo{ - Name: "default", - GoType: reflect.TypeOf(&QueryModel{}), - Examples: []query.QueryExample{ - { - Name: "public query", - Query: QueryModel{ - Spreadsheet: "YourSheetID", - Range: "A1:D6", - }, - }, - }, - }, - ) - - require.NoError(t, err) - - // Update the query schemas resource - builder.UpdateSchemaDefinition(t, "../../src/static/schema/dataquery.json") -} diff --git a/pkg/models/schema_test.go b/pkg/models/schema_test.go new file mode 100644 index 0000000..21273db --- /dev/null +++ b/pkg/models/schema_test.go @@ -0,0 +1,37 @@ +package models + +import ( + "reflect" + "testing" + + "github.com/grafana/grafana-plugin-sdk-go/experimental/schema" + "github.com/stretchr/testify/require" +) + +func TestSchemaDefinitions(t *testing.T) { + builder, err := schema.NewSchemaBuilder( + schema.BuilderOptions{ + BasePackage: "github.com/grafana/google-sheets-datasource/pkg/models", + CodePath: "./", + }, + ) + require.NoError(t, err) + err = builder.AddQueries(schema.QueryTypeInfo{ + Name: "default", + GoType: reflect.TypeOf(&QueryModel{}), + Examples: []schema.QueryExample{ + { + Name: "public query", + QueryPayload: QueryModel{ + Spreadsheet: "YourSheetID", + Range: "A1:D6", + }, + }, + }, + }) + + require.NoError(t, err) + + // Update the query schemas resource + builder.UpdateQueryDefinition(t, "../../src/static/schema/query.schema.json") +} diff --git a/src/static/schema/dataquery.json b/src/static/schema/query.schema.json similarity index 53% rename from src/static/schema/dataquery.json rename to src/static/schema/query.schema.json index b14e233..e705d5e 100644 --- a/src/static/schema/dataquery.json +++ b/src/static/schema/query.schema.json @@ -2,48 +2,49 @@ "kind": "QueryTypeDefinitionList", "apiVersion": "query.grafana.app/v0alpha1", "metadata": { - "resourceVersion": "1707880401234" + "resourceVersion": "1708122817819" }, "items": [ { "metadata": { "name": "default", - "resourceVersion": "1707880401234", - "creationTimestamp": "2024-02-14T03:13:21Z" + "resourceVersion": "1708122817819", + "creationTimestamp": "2024-02-16T22:33:37Z" }, "spec": { - "schema": { - "additionalProperties": false, - "description": "QueryModel represents a spreadsheet query.", + "querySchema": { + "$schema": "https://json-schema.org/draft-04/schema", "properties": { - "cacheDurationSeconds": { - "description": "Cache duration in seconds", - "type": "integer" + "spreadsheet": { + "type": "string", + "description": "The google sheets spreadsheet ID" }, "range": { - "description": "A1 notation", - "type": "string" + "type": "string", + "description": "A1 notation" }, - "spreadsheet": { - "description": "The google sheets spreadsheet ID", - "type": "string" + "cacheDurationSeconds": { + "type": "integer", + "description": "Cache duration in seconds" }, "useTimeFilter": { - "description": "Use the query time range to filer values from the table", - "type": "boolean" + "type": "boolean", + "description": "Use the query time range to filer values from the table" } }, + "additionalProperties": false, + "type": "object", "required": [ "spreadsheet" ], - "type": "object" + "description": "QueryModel represents a spreadsheet query." }, "examples": [ { "name": "public query", - "query": { - "range": "A1:D6", - "spreadsheet": "YourSheetID" + "queryPayload": { + "spreadsheet": "YourSheetID", + "range": "A1:D6" } } ]