Skip to content

Fix schema for query scalar API #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "2023-09-21 17:08:30.788788",
"spec_repo_commit": "bcba1c72"
"regenerated": "2023-09-22 09:03:21.874813",
"spec_repo_commit": "98de9afb"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-09-21 17:08:30.805515",
"spec_repo_commit": "bcba1c72"
"regenerated": "2023-09-22 09:03:21.889787",
"spec_repo_commit": "98de9afb"
}
}
}
28 changes: 22 additions & 6 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3712,9 +3712,7 @@ components:
example: a
type: string
type:
description: The type of column present.
example: number
type: string
$ref: '#/components/schemas/ScalarColumnTypeNumber'
values:
description: The array of numerical values for one formula or query.
example:
Expand All @@ -3723,6 +3721,7 @@ components:
description: An individual value for a given column and group-by.
example: 0.5
format: double
nullable: true
type: number
type: array
type: object
Expand Down Expand Up @@ -5509,9 +5508,7 @@ components:
example: env
type: string
type:
description: The type of column present.
example: group
type: string
$ref: '#/components/schemas/ScalarColumnTypeGroup'
values:
description: The array of tag values for each group found for the results
of the formulas or queries.
Expand Down Expand Up @@ -12111,6 +12108,24 @@ components:
oneOf:
- $ref: '#/components/schemas/GroupScalarColumn'
- $ref: '#/components/schemas/DataScalarColumn'
ScalarColumnTypeGroup:
default: group
description: The type of column present for groups.
enum:
- group
example: group
type: string
x-enum-varnames:
- GROUP
ScalarColumnTypeNumber:
default: number
description: The type of column present for numbers.
enum:
- number
example: number
type: string
x-enum-varnames:
- NUMBER
ScalarFormulaQueryRequest:
description: A wrapper request around one scalar query to be executed.
properties:
Expand Down Expand Up @@ -12215,6 +12230,7 @@ components:
If the second element is not present, the API returns null.'
items:
$ref: '#/components/schemas/Unit'
nullable: true
type: array
type: object
ScalarQuery:
Expand Down
11 changes: 7 additions & 4 deletions .generator/src/generator/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def form_parameter(operation):
}


def type_to_typescript(schema, alternative_name=None):
def type_to_typescript(schema, alternative_name=None, check_nullable=True):
"""Return Typescript type name for the type."""
name = get_name(schema)
if name and "items" not in schema and not is_primitive(schema):
Expand Down Expand Up @@ -88,12 +88,15 @@ def type_to_typescript(schema, alternative_name=None):
min_items = schema.get("minItems")
max_items = schema.get("maxItems")
if min_items is not None and min_items == max_items:
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None)
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None, check_nullable=check_nullable)
return "[{}]".format(", ".join([sub_type] * min_items))
return "Array<{}>".format(type_to_typescript(schema["items"], name + "Item" if name else None))
sub_type = type_to_typescript(schema["items"], name + "Item" if name else None, check_nullable=check_nullable)
if check_nullable and schema["items"].get("nullable"):
sub_type = f"{sub_type} | null"
return "Array<{}>".format(sub_type)
elif type_ == "object":
if "additionalProperties" in schema and not schema.get("properties"):
return "{{ [key: string]: {}; }}".format(type_to_typescript(schema["additionalProperties"]))
return "{{ [key: string]: {}; }}".format(type_to_typescript(schema["additionalProperties"], check_nullable=check_nullable))
return (
alternative_name
if alternative_name
Expand Down
4 changes: 2 additions & 2 deletions .generator/src/generator/templates/model/model.j2
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class {{ name }} {
{%- set format = get_format_for_schema(schema) %}
"{{ attr|attribute_name }}": {
"baseName": "{{ attr }}",
"type": "{{ type_to_typescript(schema) }}",
"type": "{{ type_to_typescript(schema, check_nullable=False) }}",
{%- if isRequired %}
"required": true,
{%- endif %}
Expand All @@ -71,7 +71,7 @@ export class {{ name }} {
{%- set format = get_format_for_schema(model["additionalProperties"]) %}
"additionalProperties": {
"baseName": "additionalProperties",
"type": "{{ type_to_typescript(model["additionalProperties"]) }}",
"type": "{{ type_to_typescript(model["additionalProperties"], check_nullable=False) }}",
{%- if format %}
"format": "{{ format }}",
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SLOHistoryMetricsSeriesMetadata {
* For example, bytes represents one unit object and bytes per second represents two unit objects.
* If a metric query only has one unit object, the second array element is null.
*/
"unit"?: Array<SLOHistoryMetricsSeriesMetadataUnit>;
"unit"?: Array<SLOHistoryMetricsSeriesMetadataUnit | null>;

/**
* @ignore
Expand Down
2 changes: 2 additions & 0 deletions packages/datadog-api-client-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,8 @@ export { SAMLAssertionAttribute } from "./models/SAMLAssertionAttribute";
export { SAMLAssertionAttributeAttributes } from "./models/SAMLAssertionAttributeAttributes";
export { SAMLAssertionAttributesType } from "./models/SAMLAssertionAttributesType";
export { ScalarColumn } from "./models/ScalarColumn";
export { ScalarColumnTypeGroup } from "./models/ScalarColumnTypeGroup";
export { ScalarColumnTypeNumber } from "./models/ScalarColumnTypeNumber";
export { ScalarFormulaQueryRequest } from "./models/ScalarFormulaQueryRequest";
export { ScalarFormulaQueryResponse } from "./models/ScalarFormulaQueryResponse";
export { ScalarFormulaRequest } from "./models/ScalarFormulaRequest";
Expand Down
9 changes: 5 additions & 4 deletions packages/datadog-api-client-v2/models/DataScalarColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2020-Present Datadog, Inc.
*/
import { ScalarColumnTypeNumber } from "./ScalarColumnTypeNumber";
import { ScalarMeta } from "./ScalarMeta";

import { AttributeTypeMap } from "../../datadog-api-client-common/util";
Expand All @@ -20,13 +21,13 @@ export class DataScalarColumn {
*/
"name"?: string;
/**
* The type of column present.
* The type of column present for numbers.
*/
"type"?: string;
"type"?: ScalarColumnTypeNumber;
/**
* The array of numerical values for one formula or query.
*/
"values"?: Array<number>;
"values"?: Array<number | null>;

/**
* @ignore
Expand All @@ -47,7 +48,7 @@ export class DataScalarColumn {
},
type: {
baseName: "type",
type: "string",
type: "ScalarColumnTypeNumber",
},
values: {
baseName: "values",
Expand Down
7 changes: 4 additions & 3 deletions packages/datadog-api-client-v2/models/GroupScalarColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2020-Present Datadog, Inc.
*/
import { ScalarColumnTypeGroup } from "./ScalarColumnTypeGroup";

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

Expand All @@ -15,9 +16,9 @@ export class GroupScalarColumn {
*/
"name"?: string;
/**
* The type of column present.
* The type of column present for groups.
*/
"type"?: string;
"type"?: ScalarColumnTypeGroup;
/**
* The array of tag values for each group found for the results of the formulas or queries.
*/
Expand All @@ -38,7 +39,7 @@ export class GroupScalarColumn {
},
type: {
baseName: "type",
type: "string",
type: "ScalarColumnTypeGroup",
},
values: {
baseName: "values",
Expand Down
2 changes: 2 additions & 0 deletions packages/datadog-api-client-v2/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ const enumsMap: { [key: string]: any[] } = {
],
RolesType: ["roles"],
SAMLAssertionAttributesType: ["saml_assertion_attributes"],
ScalarColumnTypeGroup: ["group"],
ScalarColumnTypeNumber: ["number"],
ScalarFormulaRequestType: ["scalar_request"],
ScalarFormulaResponseType: ["scalar_response"],
SecurityFilterFilteredDataType: ["logs"],
Expand Down
14 changes: 14 additions & 0 deletions packages/datadog-api-client-v2/models/ScalarColumnTypeGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2020-Present Datadog, Inc.
*/

import { UnparsedObject } from "../../datadog-api-client-common/util";

/**
* The type of column present for groups.
*/

export type ScalarColumnTypeGroup = typeof GROUP | UnparsedObject;
export const GROUP = "group";
14 changes: 14 additions & 0 deletions packages/datadog-api-client-v2/models/ScalarColumnTypeNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2020-Present Datadog, Inc.
*/

import { UnparsedObject } from "../../datadog-api-client-common/util";

/**
* The type of column present for numbers.
*/

export type ScalarColumnTypeNumber = typeof NUMBER | UnparsedObject;
export const NUMBER = "number";
2 changes: 1 addition & 1 deletion packages/datadog-api-client-v2/models/ScalarMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ScalarMeta {
* The second element describes the "per unit" (for example, `second` in `bytes per second`).
* If the second element is not present, the API returns null.
*/
"unit"?: Array<Unit>;
"unit"?: Array<Unit | null>;

/**
* @ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TimeseriesResponseAttributes {
/**
* Array of value-arrays. The index here corresponds to the index in the `formulas` or `queries` array from the request.
*/
"values"?: Array<Array<number>>;
"values"?: Array<Array<number | null>>;

/**
* @ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class TimeseriesResponseSeries {
* The second element describes the "per unit" (for example, `second` in `bytes per second`).
* If the second element is not present, the API returns null.
*/
"unit"?: Array<Unit>;
"unit"?: Array<Unit | null>;

/**
* @ignore
Expand Down