grafana / cog

Code Generation with a human touch
Apache License 2.0
43 stars 2 forks source link

Use a veneer to add the missing expr field in dashboard.AnnotationQuery #549

Closed K-Phoen closed 2 weeks ago

K-Phoen commented 2 weeks ago

Will help with grafana/grafana-foundation-sdk#229

github-actions[bot] commented 2 weeks ago

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

### 🔎 Changes to `grafana-foundation-sdk@next+cog-v0.0.x` ```patch diff --git a/go/dashboard/annotationquery_builder_gen.go b/go/dashboard/annotationquery_builder_gen.go index cac9c40..1fc2c1c 100644 --- a/go/dashboard/annotationquery_builder_gen.go +++ b/go/dashboard/annotationquery_builder_gen.go @@ -115,6 +115,12 @@ func (builder *AnnotationQueryBuilder) BuiltIn(builtIn float64) *AnnotationQuery return builder } +func (builder *AnnotationQueryBuilder) Expr(expr string) *AnnotationQueryBuilder { + builder.internal.Expr = &expr + + return builder +} + func (builder *AnnotationQueryBuilder) applyDefaults() { builder.Enable(true) builder.Hide(false) diff --git a/go/dashboard/types_gen.go b/go/dashboard/types_gen.go index 6bb90ae..823773f 100644 --- a/go/dashboard/types_gen.go +++ b/go/dashboard/types_gen.go @@ -134,6 +134,7 @@ type AnnotationQuery struct { Type *string `json:"type,omitempty"` // Set to 1 for the standard annotation query all dashboards have by default. BuiltIn *float64 `json:"builtIn,omitempty"` + Expr *string `json:"expr,omitempty"` } // A variable is a placeholder for a value. You can use variables in metric queries and in panel titles. diff --git a/java/src/main/java/com/grafana/foundation/common/Constants.java b/java/src/main/java/com/grafana/foundation/common/Constants.java index be9af52..cc841b4 100644 --- a/java/src/main/java/com/grafana/foundation/common/Constants.java +++ b/java/src/main/java/com/grafana/foundation/common/Constants.java @@ -3,6 +3,6 @@ package com.grafana.foundation.common; public class Constants { - public static final String TimeZoneBrowser = "browser"; public static final String TimeZoneUtc = "utc"; + public static final String TimeZoneBrowser = "browser"; } diff --git a/java/src/main/java/com/grafana/foundation/dashboard/AnnotationQuery.java b/java/src/main/java/com/grafana/foundation/dashboard/AnnotationQuery.java index 8edc319..5673a6b 100644 --- a/java/src/main/java/com/grafana/foundation/dashboard/AnnotationQuery.java +++ b/java/src/main/java/com/grafana/foundation/dashboard/AnnotationQuery.java @@ -45,6 +45,9 @@ public class AnnotationQuery { @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("builtIn") public Double builtIn; + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonProperty("expr") + public String expr; public String toJSON() throws JsonProcessingException { ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); @@ -105,6 +108,11 @@ public class AnnotationQuery { this.internal.builtIn = builtIn; return this; } + + public Builder expr(String expr) { + this.internal.expr = expr; + return this; + } public AnnotationQuery build() { return this.internal; } diff --git a/jsonschema/dashboard.jsonschema.json b/jsonschema/dashboard.jsonschema.json index a1454e7..0d5cfe6 100644 --- a/jsonschema/dashboard.jsonschema.json +++ b/jsonschema/dashboard.jsonschema.json @@ -271,6 +271,9 @@ "type": "number", "description": "Set to 1 for the standard annotation query all dashboards have by default.", "default": 0 + }, + "expr": { + "type": "string" } }, "description": "TODO docs\nFROM: AnnotationQuery in grafana-data/src/types/annotations.ts" diff --git a/openapi/dashboard.openapi.json b/openapi/dashboard.openapi.json index ab92de9..179bd5d 100644 --- a/openapi/dashboard.openapi.json +++ b/openapi/dashboard.openapi.json @@ -278,6 +278,9 @@ "type": "number", "description": "Set to 1 for the standard annotation query all dashboards have by default.", "default": 0 + }, + "expr": { + "type": "string" } }, "description": "TODO docs\nFROM: AnnotationQuery in grafana-data/src/types/annotations.ts" diff --git a/php/src/Dashboard/AnnotationContainer.php b/php/src/Dashboard/AnnotationContainer.php index 1b63944..2378bda 100644 --- a/php/src/Dashboard/AnnotationContainer.php +++ b/php/src/Dashboard/AnnotationContainer.php @@ -33,7 +33,7 @@ class AnnotationContainer implements \JsonSerializable $data = $inputData; return new self( list: array_filter(array_map((function($input) { - /** @var array{name?: string, datasource?: mixed, enable?: bool, hide?: bool, iconColor?: string, filter?: mixed, target?: mixed, type?: string, builtIn?: float} */ + /** @var array{name?: string, datasource?: mixed, enable?: bool, hide?: bool, iconColor?: string, filter?: mixed, target?: mixed, type?: string, builtIn?: float, expr?: string} */ $val = $input; return \Grafana\Foundation\Dashboard\AnnotationQuery::fromArray($val); }), $data["list"] ?? [])), diff --git a/php/src/Dashboard/AnnotationQuery.php b/php/src/Dashboard/AnnotationQuery.php index 266ae24..12e5072 100644 --- a/php/src/Dashboard/AnnotationQuery.php +++ b/php/src/Dashboard/AnnotationQuery.php @@ -54,6 +54,8 @@ class AnnotationQuery implements \JsonSerializable */ public ?float $builtIn; + public ?string $expr; + /** * @param string|null $name * @param \Grafana\Foundation\Dashboard\DataSourceRef|null $datasource @@ -64,8 +66,9 @@ class AnnotationQuery implements \JsonSerializable * @param \Grafana\Foundation\Dashboard\AnnotationTarget|null $target * @param string|null $type * @param float|null $builtIn + * @param string|null $expr */ - public function __construct(?string $name = null, ?\Grafana\Foundation\Dashboard\DataSourceRef $datasource = null, ?bool $enable = null, ?bool $hide = null, ?string $iconColor = null, ?\Grafana\Foundation\Dashboard\AnnotationPanelFilter $filter = null, ?\Grafana\Foundation\Dashboard\AnnotationTarget $target = null, ?string $type = null, ?float $builtIn = null) + public function __construct(?string $name = null, ?\Grafana\Foundation\Dashboard\DataSourceRef $datasource = null, ?bool $enable = null, ?bool $hide = null, ?string $iconColor = null, ?\Grafana\Foundation\Dashboard\AnnotationPanelFilter $filter = null, ?\Grafana\Foundation\Dashboard\AnnotationTarget $target = null, ?string $type = null, ?float $builtIn = null, ?string $expr = null) { $this->name = $name ?: ""; $this->datasource = $datasource ?: new \Grafana\Foundation\Dashboard\DataSourceRef(); @@ -76,6 +79,7 @@ class AnnotationQuery implements \JsonSerializable $this->target = $target; $this->type = $type; $this->builtIn = $builtIn; + $this->expr = $expr; } /** @@ -83,7 +87,7 @@ class AnnotationQuery implements \JsonSerializable */ public static function fromArray(array $inputData): self { - /** @var array{name?: string, datasource?: mixed, enable?: bool, hide?: bool, iconColor?: string, filter?: mixed, target?: mixed, type?: string, builtIn?: float} $inputData */ + /** @var array{name?: string, datasource?: mixed, enable?: bool, hide?: bool, iconColor?: string, filter?: mixed, target?: mixed, type?: string, builtIn?: float, expr?: string} $inputData */ $data = $inputData; return new self( name: $data["name"] ?? null, @@ -107,6 +111,7 @@ class AnnotationQuery implements \JsonSerializable })($data["target"]) : null, type: $data["type"] ?? null, builtIn: $data["builtIn"] ?? null, + expr: $data["expr"] ?? null, ); } @@ -136,6 +141,9 @@ class AnnotationQuery implements \JsonSerializable if (isset($this->builtIn)) { $data["builtIn"] = $this->builtIn; } + if (isset($this->expr)) { + $data["expr"] = $this->expr; + } return $data; } } diff --git a/php/src/Dashboard/AnnotationQueryBuilder.php b/php/src/Dashboard/AnnotationQueryBuilder.php index 99e4cdf..4ddc33a 100644 --- a/php/src/Dashboard/AnnotationQueryBuilder.php +++ b/php/src/Dashboard/AnnotationQueryBuilder.php @@ -110,5 +110,11 @@ class AnnotationQueryBuilder implements \Grafana\Foundation\Cog\Builder return $this; } + public function expr(string $expr): static + { + $this->internal->expr = $expr; + + return $this; + } } diff --git a/python/grafana_foundation_sdk/builders/dashboard.py b/python/grafana_foundation_sdk/builders/dashboard.py index ef3313b..ef00a3e 100644 --- a/python/grafana_foundation_sdk/builders/dashboard.py +++ b/python/grafana_foundation_sdk/builders/dashboard.py @@ -557,6 +557,11 @@ class AnnotationQuery(cogbuilder.Builder[dashboard.AnnotationQuery]): return self + def expr(self, expr: str) -> typing.Self: + self._internal.expr = expr + + return self + class DashboardLink(cogbuilder.Builder[dashboard.DashboardLink]): """ diff --git a/python/grafana_foundation_sdk/models/dashboard.py b/python/grafana_foundation_sdk/models/dashboard.py index 367d111..4006fef 100644 --- a/python/grafana_foundation_sdk/models/dashboard.py +++ b/python/grafana_foundation_sdk/models/dashboard.py @@ -335,8 +335,9 @@ class AnnotationQuery: type_val: typing.Optional[str] # Set to 1 for the standard annotation query all dashboards have by default. built_in: typing.Optional[float] + expr: typing.Optional[str] - def __init__(self, name: str = "", datasource: typing.Optional['DataSourceRef'] = None, enable: bool = True, hide: typing.Optional[bool] = False, icon_color: str = "", filter_val: typing.Optional['AnnotationPanelFilter'] = None, target: typing.Optional['AnnotationTarget'] = None, type_val: typing.Optional[str] = None, built_in: typing.Optional[float] = 0): + def __init__(self, name: str = "", datasource: typing.Optional['DataSourceRef'] = None, enable: bool = True, hide: typing.Optional[bool] = False, icon_color: str = "", filter_val: typing.Optional['AnnotationPanelFilter'] = None, target: typing.Optional['AnnotationTarget'] = None, type_val: typing.Optional[str] = None, built_in: typing.Optional[float] = 0, expr: typing.Optional[str] = None): self.name = name self.datasource = datasource if datasource is not None else DataSourceRef() self.enable = enable @@ -346,6 +347,7 @@ class AnnotationQuery: self.target = target self.type_val = type_val self.built_in = built_in + self.expr = expr def to_json(self) -> dict[str, object]: payload: dict[str, object] = { @@ -364,6 +366,8 @@ class AnnotationQuery: payload["type"] = self.type_val if self.built_in is not None: payload["builtIn"] = self.built_in + if self.expr is not None: + payload["expr"] = self.expr return payload @classmethod @@ -387,7 +391,9 @@ class AnnotationQuery: if "type" in data: args["type_val"] = data["type"] if "builtIn" in data: - args["built_in"] = data["builtIn"] + args["built_in"] = data["builtIn"] + if "expr" in data: + args["expr"] = data["expr"] return cls(**args) diff --git a/typescript/src/dashboard/annotationQueryBuilder.gen.ts b/typescript/src/dashboard/annotationQueryBuilder.gen.ts index 454bb84..da955a0 100644 --- a/typescript/src/dashboard/annotationQueryBuilder.gen.ts +++ b/typescript/src/dashboard/annotationQueryBuilder.gen.ts @@ -72,4 +72,9 @@ export class AnnotationQueryBuilder implements cog.Builder ({ ```