Skip to content

Commit b7c39d1

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Fix schema for query scalar API (#1328)
* Specify nullable in array item types * Regenerate client from commit 98de9afb of spec repo --------- Co-authored-by: Thomas Hervé <thomas.herve@datadoghq.com> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent b6a9209 commit b7c39d1

14 files changed

+80
-27
lines changed

.apigentools-info

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2023-09-21 17:08:30.788788",
8-
"spec_repo_commit": "bcba1c72"
7+
"regenerated": "2023-09-22 09:03:21.874813",
8+
"spec_repo_commit": "98de9afb"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2023-09-21 17:08:30.805515",
13-
"spec_repo_commit": "bcba1c72"
12+
"regenerated": "2023-09-22 09:03:21.889787",
13+
"spec_repo_commit": "98de9afb"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

+22-6
Original file line numberDiff line numberDiff line change
@@ -3712,9 +3712,7 @@ components:
37123712
example: a
37133713
type: string
37143714
type:
3715-
description: The type of column present.
3716-
example: number
3717-
type: string
3715+
$ref: '#/components/schemas/ScalarColumnTypeNumber'
37183716
values:
37193717
description: The array of numerical values for one formula or query.
37203718
example:
@@ -3723,6 +3721,7 @@ components:
37233721
description: An individual value for a given column and group-by.
37243722
example: 0.5
37253723
format: double
3724+
nullable: true
37263725
type: number
37273726
type: array
37283727
type: object
@@ -5509,9 +5508,7 @@ components:
55095508
example: env
55105509
type: string
55115510
type:
5512-
description: The type of column present.
5513-
example: group
5514-
type: string
5511+
$ref: '#/components/schemas/ScalarColumnTypeGroup'
55155512
values:
55165513
description: The array of tag values for each group found for the results
55175514
of the formulas or queries.
@@ -12111,6 +12108,24 @@ components:
1211112108
oneOf:
1211212109
- $ref: '#/components/schemas/GroupScalarColumn'
1211312110
- $ref: '#/components/schemas/DataScalarColumn'
12111+
ScalarColumnTypeGroup:
12112+
default: group
12113+
description: The type of column present for groups.
12114+
enum:
12115+
- group
12116+
example: group
12117+
type: string
12118+
x-enum-varnames:
12119+
- GROUP
12120+
ScalarColumnTypeNumber:
12121+
default: number
12122+
description: The type of column present for numbers.
12123+
enum:
12124+
- number
12125+
example: number
12126+
type: string
12127+
x-enum-varnames:
12128+
- NUMBER
1211412129
ScalarFormulaQueryRequest:
1211512130
description: A wrapper request around one scalar query to be executed.
1211612131
properties:
@@ -12215,6 +12230,7 @@ components:
1221512230
If the second element is not present, the API returns null.'
1221612231
items:
1221712232
$ref: '#/components/schemas/Unit'
12233+
nullable: true
1221812234
type: array
1221912235
type: object
1222012236
ScalarQuery:

.generator/src/generator/openapi.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def form_parameter(operation):
5353
}
5454

5555

56-
def type_to_typescript(schema, alternative_name=None):
56+
def type_to_typescript(schema, alternative_name=None, check_nullable=True):
5757
"""Return Typescript type name for the type."""
5858
name = get_name(schema)
5959
if name and "items" not in schema and not is_primitive(schema):
@@ -88,12 +88,15 @@ def type_to_typescript(schema, alternative_name=None):
8888
min_items = schema.get("minItems")
8989
max_items = schema.get("maxItems")
9090
if min_items is not None and min_items == max_items:
91-
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None)
91+
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None, check_nullable=check_nullable)
9292
return "[{}]".format(", ".join([sub_type] * min_items))
93-
return "Array<{}>".format(type_to_typescript(schema["items"], name + "Item" if name else None))
93+
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None, check_nullable=check_nullable)
94+
if check_nullable and schema["items"].get("nullable"):
95+
sub_type = f"{sub_type} | null"
96+
return "Array<{}>".format(sub_type)
9497
elif type_ == "object":
9598
if "additionalProperties" in schema and not schema.get("properties"):
96-
return "{{ [key: string]: {}; }}".format(type_to_typescript(schema["additionalProperties"]))
99+
return "{{ [key: string]: {}; }}".format(type_to_typescript(schema["additionalProperties"], check_nullable=check_nullable))
97100
return (
98101
alternative_name
99102
if alternative_name

.generator/src/generator/templates/model/model.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class {{ name }} {
5858
{%- set format = get_format_for_schema(schema) %}
5959
"{{ attr|attribute_name }}": {
6060
"baseName": "{{ attr }}",
61-
"type": "{{ type_to_typescript(schema) }}",
61+
"type": "{{ type_to_typescript(schema, check_nullable=False) }}",
6262
{%- if isRequired %}
6363
"required": true,
6464
{%- endif %}
@@ -71,7 +71,7 @@ export class {{ name }} {
7171
{%- set format = get_format_for_schema(model["additionalProperties"]) %}
7272
"additionalProperties": {
7373
"baseName": "additionalProperties",
74-
"type": "{{ type_to_typescript(model["additionalProperties"]) }}",
74+
"type": "{{ type_to_typescript(model["additionalProperties"], check_nullable=False) }}",
7575
{%- if format %}
7676
"format": "{{ format }}",
7777
{%- endif %}

packages/datadog-api-client-v1/models/SLOHistoryMetricsSeriesMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class SLOHistoryMetricsSeriesMetadata {
3636
* For example, bytes represents one unit object and bytes per second represents two unit objects.
3737
* If a metric query only has one unit object, the second array element is null.
3838
*/
39-
"unit"?: Array<SLOHistoryMetricsSeriesMetadataUnit>;
39+
"unit"?: Array<SLOHistoryMetricsSeriesMetadataUnit | null>;
4040

4141
/**
4242
* @ignore

packages/datadog-api-client-v2/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ export { SAMLAssertionAttribute } from "./models/SAMLAssertionAttribute";
11441144
export { SAMLAssertionAttributeAttributes } from "./models/SAMLAssertionAttributeAttributes";
11451145
export { SAMLAssertionAttributesType } from "./models/SAMLAssertionAttributesType";
11461146
export { ScalarColumn } from "./models/ScalarColumn";
1147+
export { ScalarColumnTypeGroup } from "./models/ScalarColumnTypeGroup";
1148+
export { ScalarColumnTypeNumber } from "./models/ScalarColumnTypeNumber";
11471149
export { ScalarFormulaQueryRequest } from "./models/ScalarFormulaQueryRequest";
11481150
export { ScalarFormulaQueryResponse } from "./models/ScalarFormulaQueryResponse";
11491151
export { ScalarFormulaRequest } from "./models/ScalarFormulaRequest";

packages/datadog-api-client-v2/models/DataScalarColumn.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* This product includes software developed at Datadog (https://www.datadoghq.com/).
44
* Copyright 2020-Present Datadog, Inc.
55
*/
6+
import { ScalarColumnTypeNumber } from "./ScalarColumnTypeNumber";
67
import { ScalarMeta } from "./ScalarMeta";
78

89
import { AttributeTypeMap } from "../../datadog-api-client-common/util";
@@ -20,13 +21,13 @@ export class DataScalarColumn {
2021
*/
2122
"name"?: string;
2223
/**
23-
* The type of column present.
24+
* The type of column present for numbers.
2425
*/
25-
"type"?: string;
26+
"type"?: ScalarColumnTypeNumber;
2627
/**
2728
* The array of numerical values for one formula or query.
2829
*/
29-
"values"?: Array<number>;
30+
"values"?: Array<number | null>;
3031

3132
/**
3233
* @ignore
@@ -47,7 +48,7 @@ export class DataScalarColumn {
4748
},
4849
type: {
4950
baseName: "type",
50-
type: "string",
51+
type: "ScalarColumnTypeNumber",
5152
},
5253
values: {
5354
baseName: "values",

packages/datadog-api-client-v2/models/GroupScalarColumn.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* This product includes software developed at Datadog (https://www.datadoghq.com/).
44
* Copyright 2020-Present Datadog, Inc.
55
*/
6+
import { ScalarColumnTypeGroup } from "./ScalarColumnTypeGroup";
67

78
import { AttributeTypeMap } from "../../datadog-api-client-common/util";
89

@@ -15,9 +16,9 @@ export class GroupScalarColumn {
1516
*/
1617
"name"?: string;
1718
/**
18-
* The type of column present.
19+
* The type of column present for groups.
1920
*/
20-
"type"?: string;
21+
"type"?: ScalarColumnTypeGroup;
2122
/**
2223
* The array of tag values for each group found for the results of the formulas or queries.
2324
*/
@@ -38,7 +39,7 @@ export class GroupScalarColumn {
3839
},
3940
type: {
4041
baseName: "type",
41-
type: "string",
42+
type: "ScalarColumnTypeGroup",
4243
},
4344
values: {
4445
baseName: "values",

packages/datadog-api-client-v2/models/ObjectSerializer.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,8 @@ const enumsMap: { [key: string]: any[] } = {
11501150
],
11511151
RolesType: ["roles"],
11521152
SAMLAssertionAttributesType: ["saml_assertion_attributes"],
1153+
ScalarColumnTypeGroup: ["group"],
1154+
ScalarColumnTypeNumber: ["number"],
11531155
ScalarFormulaRequestType: ["scalar_request"],
11541156
ScalarFormulaResponseType: ["scalar_response"],
11551157
SecurityFilterFilteredDataType: ["logs"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2020-Present Datadog, Inc.
5+
*/
6+
7+
import { UnparsedObject } from "../../datadog-api-client-common/util";
8+
9+
/**
10+
* The type of column present for groups.
11+
*/
12+
13+
export type ScalarColumnTypeGroup = typeof GROUP | UnparsedObject;
14+
export const GROUP = "group";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2020-Present Datadog, Inc.
5+
*/
6+
7+
import { UnparsedObject } from "../../datadog-api-client-common/util";
8+
9+
/**
10+
* The type of column present for numbers.
11+
*/
12+
13+
export type ScalarColumnTypeNumber = typeof NUMBER | UnparsedObject;
14+
export const NUMBER = "number";

packages/datadog-api-client-v2/models/ScalarMeta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ScalarMeta {
1717
* The second element describes the "per unit" (for example, `second` in `bytes per second`).
1818
* If the second element is not present, the API returns null.
1919
*/
20-
"unit"?: Array<Unit>;
20+
"unit"?: Array<Unit | null>;
2121

2222
/**
2323
* @ignore

packages/datadog-api-client-v2/models/TimeseriesResponseAttributes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class TimeseriesResponseAttributes {
2222
/**
2323
* Array of value-arrays. The index here corresponds to the index in the `formulas` or `queries` array from the request.
2424
*/
25-
"values"?: Array<Array<number>>;
25+
"values"?: Array<Array<number | null>>;
2626

2727
/**
2828
* @ignore

packages/datadog-api-client-v2/models/TimeseriesResponseSeries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class TimeseriesResponseSeries {
2525
* The second element describes the "per unit" (for example, `second` in `bytes per second`).
2626
* If the second element is not present, the API returns null.
2727
*/
28-
"unit"?: Array<Unit>;
28+
"unit"?: Array<Unit | null>;
2929

3030
/**
3131
* @ignore

0 commit comments

Comments
 (0)