Skip to content

Commit

Permalink
Ensure clients can handle empty oneOf objects (#2493)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Sep 30, 2024
1 parent 8a317be commit efa3b40
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-09-30 13:57:08.451305",
"spec_repo_commit": "eb66b1cf"
"regenerated": "2024-09-30 14:37:33.047156",
"spec_repo_commit": "60bc9127"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-09-30 13:57:08.465453",
"spec_repo_commit": "eb66b1cf"
"regenerated": "2024-09-30 14:37:33.070295",
"spec_repo_commit": "60bc9127"
}
}
}
85 changes: 85 additions & 0 deletions examples/v1/dashboards/CreateDashboard_1433408735.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Clients deserialize a dashboard with a empty time object

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.DashboardsApi;
import com.datadog.api.client.v1.model.Dashboard;
import com.datadog.api.client.v1.model.DashboardLayoutType;
import com.datadog.api.client.v1.model.FormulaAndFunctionCloudCostDataSource;
import com.datadog.api.client.v1.model.FormulaAndFunctionCloudCostQueryDefinition;
import com.datadog.api.client.v1.model.FormulaAndFunctionQueryDefinition;
import com.datadog.api.client.v1.model.FormulaAndFunctionResponseFormat;
import com.datadog.api.client.v1.model.TimeseriesWidgetDefinition;
import com.datadog.api.client.v1.model.TimeseriesWidgetDefinitionType;
import com.datadog.api.client.v1.model.TimeseriesWidgetRequest;
import com.datadog.api.client.v1.model.Widget;
import com.datadog.api.client.v1.model.WidgetDefinition;
import com.datadog.api.client.v1.model.WidgetDisplayType;
import com.datadog.api.client.v1.model.WidgetFormula;
import com.datadog.api.client.v1.model.WidgetLegacyLiveSpan;
import com.datadog.api.client.v1.model.WidgetLineType;
import com.datadog.api.client.v1.model.WidgetLineWidth;
import com.datadog.api.client.v1.model.WidgetRequestStyle;
import com.datadog.api.client.v1.model.WidgetTextAlign;
import com.datadog.api.client.v1.model.WidgetTime;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
DashboardsApi apiInstance = new DashboardsApi(defaultClient);

Dashboard body =
new Dashboard()
.title("Example-Dashboard")
.widgets(
Collections.singletonList(
new Widget()
.definition(
new WidgetDefinition(
new TimeseriesWidgetDefinition()
.title("Example Cloud Cost Query")
.titleSize("16")
.titleAlign(WidgetTextAlign.LEFT)
.type(TimeseriesWidgetDefinitionType.TIMESERIES)
.requests(
Collections.singletonList(
new TimeseriesWidgetRequest()
.formulas(
Collections.singletonList(
new WidgetFormula().formula("query1")))
.queries(
Collections.singletonList(
new FormulaAndFunctionQueryDefinition(
new FormulaAndFunctionCloudCostQueryDefinition()
.dataSource(
FormulaAndFunctionCloudCostDataSource
.CLOUD_COST)
.name("query1")
.query(
"sum:aws.cost.amortized{*} by"
+ " {aws_product}.rollup(sum,"
+ " monthly)"))))
.responseFormat(
FormulaAndFunctionResponseFormat.TIMESERIES)
.style(
new WidgetRequestStyle()
.palette("dog_classic")
.lineType(WidgetLineType.SOLID)
.lineWidth(WidgetLineWidth.NORMAL))
.displayType(WidgetDisplayType.BARS)))
.time(new WidgetTime(new WidgetLegacyLiveSpan()))))))
.layoutType(DashboardLayoutType.ORDERED);

try {
Dashboard result = apiInstance.createDashboard(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DashboardsApi#createDashboard");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-09-24T19:19:31.807Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"httpRequest": {
"body": {
"type": "JSON",
"json": "{\"layout_type\":\"ordered\",\"title\":\"Test-Clients_deserialize_a_dashboard_with_a_empty_time_object-1727205571\",\"widgets\":[{\"definition\":{\"requests\":[{\"display_type\":\"bars\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"data_source\":\"cloud_cost\",\"name\":\"query1\",\"query\":\"sum:aws.cost.amortized{*} by {aws_product}.rollup(sum, monthly)\"}],\"response_format\":\"timeseries\",\"style\":{\"line_type\":\"solid\",\"line_width\":\"normal\",\"palette\":\"dog_classic\"}}],\"time\":{},\"title\":\"Example Cloud Cost Query\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"timeseries\"}}]}"
},
"headers": {},
"method": "POST",
"path": "/api/v1/dashboard",
"keepAlive": false,
"secure": true
},
"httpResponse": {
"body": "{\"id\":\"han-5zg-c32\",\"title\":\"Test-Clients_deserialize_a_dashboard_with_a_empty_time_object-1727205571\",\"description\":null,\"author_handle\":\"[email protected]\",\"author_name\":null,\"layout_type\":\"ordered\",\"url\":\"/dashboard/han-5zg-c32/test-clientsdeserializeadashboardwithaemptytimeobject-1727205571\",\"is_read_only\":false,\"template_variables\":null,\"widgets\":[{\"definition\":{\"requests\":[{\"display_type\":\"bars\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"data_source\":\"cloud_cost\",\"name\":\"query1\",\"query\":\"sum:aws.cost.amortized{*} by {aws_product}.rollup(sum, monthly)\"}],\"response_format\":\"timeseries\",\"style\":{\"line_type\":\"solid\",\"line_width\":\"normal\",\"palette\":\"dog_classic\"}}],\"time\":{},\"title\":\"Example Cloud Cost Query\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"timeseries\"},\"id\":4274057372149908}],\"notify_list\":null,\"created_at\":\"2024-09-24T19:19:32.071328+00:00\",\"modified_at\":\"2024-09-24T19:19:32.071328+00:00\",\"experience_type\":\"default\",\"restricted_roles\":[]}\n",
"headers": {
"Content-Type": [
"application/json"
]
},
"statusCode": 200,
"reasonPhrase": "OK"
},
"times": {
"remainingTimes": 1
},
"timeToLive": {
"unlimited": true
},
"id": "25f142c7-7556-d0a0-7f60-c9aea7b1aa17"
},
{
"httpRequest": {
"headers": {},
"method": "DELETE",
"path": "/api/v1/dashboard/han-5zg-c32",
"keepAlive": false,
"secure": true
},
"httpResponse": {
"body": "{\"deleted_dashboard_id\":\"han-5zg-c32\"}\n",
"headers": {
"Content-Type": [
"application/json"
]
},
"statusCode": 200,
"reasonPhrase": "OK"
},
"times": {
"remainingTimes": 1
},
"timeToLive": {
"unlimited": true
},
"id": "9350b5ff-5d55-807a-27b7-1a985a5d0edd"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Feature: Dashboards
And a valid "appKeyAuth" key in the system
And an instance of "Dashboards" API

@replay-only @team:DataDog/dashboards-backend
Scenario: Clients deserialize a dashboard with a empty time object
Given new "CreateDashboard" request
And body with value { "title": "{{ unique }}", "widgets": [ { "definition": { "title": "Example Cloud Cost Query", "title_size": "16", "title_align": "left", "type": "timeseries", "requests": [ { "formulas": [ { "formula": "query1" } ], "queries": [ { "data_source": "cloud_cost", "name": "query1", "query": "sum:aws.cost.amortized{*} by {aws_product}.rollup(sum, monthly)" } ], "response_format": "timeseries", "style": { "palette": "dog_classic", "line_type": "solid", "line_width": "normal" }, "display_type": "bars" } ], "time": {} } } ], "layout_type": "ordered" }
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.time" is equal to {}

@team:DataDog/dashboards-backend
Scenario: Create a distribution widget using a histogram request containing a formulas and functions APM Stats query
Given new "CreateDashboard" request
Expand Down

0 comments on commit efa3b40

Please sign in to comment.