Skip to content

Commit 28d5556

Browse files
Enable additionalProperties by default (#2111)
* enable additionalProperties by default * enabled additionalProps * reduce change size * Update .generator/src/generator/templates/model_generic.j2 Co-authored-by: jack-edmonds-dd <[email protected]> * remove check --------- Co-authored-by: jack-edmonds-dd <[email protected]>
1 parent ad4a270 commit 28d5556

29 files changed

+64
-303
lines changed

.generator/src/generator/openapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def basic_type_to_python(type_, schema, typing=False):
6767
def type_to_python(schema, typing=False):
6868
"""Return Python type name for the type."""
6969

70+
# Special case for additionalProperties: True
71+
if schema is True:
72+
return basic_type_to_python(None, {}, typing=typing)
73+
7074
name = formatter.get_name(schema)
7175

7276
if "oneOf" in schema:

.generator/src/generator/templates/model_generic.j2

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,22 @@ class {{ name }}(ModelNormal):
5454
}
5555
{%- endif %}
5656

57-
{%- if model.get("additionalProperties", false) is not false %}
57+
{%- set additionalProperties = model.get("additionalProperties") %}
58+
{#- Only add additional_properties_type property if additionalProperties is disabled or has a custom type #}
59+
{%- if (additionalProperties is false) or (additionalProperties and additionalProperties is not true) %}
5860
@cached_property
5961
def additional_properties_type(_):
62+
{%- if additionalProperties is false %}
63+
return None
64+
{%- else -%}
6065
{%- if refs %}
6166
{%- for ref in refs %}
6267
from {{ package }}.{{ version }}.model.{{ ref|safe_snake_case }} import {{ ref }}
6368
{%- endfor %}
6469
{%- endif %}
6570
return ({{ type_to_python(model["additionalProperties"]) }},)
6671
{%- endif %}
72+
{%- endif %}
6773

6874
{%- if model.nullable %}
6975
_nullable = True

.generator/src/generator/templates/model_utils.j2

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class OpenApiModel(object):
107107

108108
_composed_schemas = empty_dict
109109

110-
additional_properties_type = None
110+
additional_properties_type = ({{ type_to_python(True) }},)
111111

112112
attribute_map: Mapping[str, str] = empty_dict
113113

@@ -393,16 +393,6 @@ class ModelNormal(OpenApiModel):
393393
def __init__(self, kwargs):
394394
super().__init__(kwargs)
395395
for var_name, var_value in kwargs.items():
396-
if (
397-
var_name not in self.attribute_map
398-
and self._configuration is not None
399-
and self._configuration.discard_unknown_keys
400-
and self.additional_properties_type is None
401-
):
402-
if self._spec_property_naming:
403-
# If it's returned from the API, store it if we need to send it back
404-
self.__dict__["_data_store"][var_name] = var_value
405-
continue
406396
setattr(self, var_name, var_value)
407397
if not self._spec_property_naming and var_name in self.read_only_vars:
408398
raise ApiAttributeError(f"`{var_name}` is a read-only attribute.")

src/datadog_api_client/model_utils.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ class OpenApiModel(object):
109109

110110
_composed_schemas = empty_dict
111111

112-
additional_properties_type = None
112+
additional_properties_type = (
113+
bool,
114+
date,
115+
datetime,
116+
dict,
117+
float,
118+
int,
119+
list,
120+
str,
121+
UUID,
122+
none_type,
123+
)
113124

114125
attribute_map: Mapping[str, str] = empty_dict
115126

@@ -395,16 +406,6 @@ def __eq__(self, other):
395406
def __init__(self, kwargs):
396407
super().__init__(kwargs)
397408
for var_name, var_value in kwargs.items():
398-
if (
399-
var_name not in self.attribute_map
400-
and self._configuration is not None
401-
and self._configuration.discard_unknown_keys
402-
and self.additional_properties_type is None
403-
):
404-
if self._spec_property_naming:
405-
# If it's returned from the API, store it if we need to send it back
406-
self.__dict__["_data_store"][var_name] = var_value
407-
continue
408409
setattr(self, var_name, var_value)
409410
if not self._spec_property_naming and var_name in self.read_only_vars:
410411
raise ApiAttributeError(f"`{var_name}` is a read-only attribute.")

src/datadog_api_client/v1/model/notebook_cell_create_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424

2525
class NotebookCellCreateRequest(ModelNormal):
26+
@cached_property
27+
def additional_properties_type(_):
28+
return None
29+
2630
@cached_property
2731
def openapi_types(_):
2832
from datadog_api_client.v1.model.notebook_cell_create_request_attributes import (

src/datadog_api_client/v1/model/slo_time_slice_spec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717

1818
class SLOTimeSliceSpec(ModelNormal):
19+
@cached_property
20+
def additional_properties_type(_):
21+
return None
22+
1923
@cached_property
2024
def openapi_types(_):
2125
from datadog_api_client.v1.model.slo_time_slice_condition import SLOTimeSliceCondition

src/datadog_api_client/v2/model/bulk_mute_findings_request_attributes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717

1818
class BulkMuteFindingsRequestAttributes(ModelNormal):
19+
@cached_property
20+
def additional_properties_type(_):
21+
return None
22+
1923
@cached_property
2024
def openapi_types(_):
2125
from datadog_api_client.v2.model.bulk_mute_findings_request_properties import BulkMuteFindingsRequestProperties

src/datadog_api_client/v2/model/bulk_mute_findings_request_properties.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919

2020
class BulkMuteFindingsRequestProperties(ModelNormal):
21+
@cached_property
22+
def additional_properties_type(_):
23+
return None
24+
2125
@cached_property
2226
def openapi_types(_):
2327
from datadog_api_client.v2.model.finding_mute_reason import FindingMuteReason

src/datadog_api_client/v2/model/cloud_configuration_compliance_rule_options.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11-
date,
12-
datetime,
13-
none_type,
1411
unset,
1512
UnsetType,
16-
UUID,
1713
)
1814

1915

@@ -22,21 +18,6 @@
2218

2319

2420
class CloudConfigurationComplianceRuleOptions(ModelNormal):
25-
@cached_property
26-
def additional_properties_type(_):
27-
return (
28-
bool,
29-
date,
30-
datetime,
31-
dict,
32-
float,
33-
int,
34-
list,
35-
str,
36-
UUID,
37-
none_type,
38-
)
39-
4021
@cached_property
4122
def openapi_types(_):
4223
from datadog_api_client.v2.model.cloud_configuration_rego_rule import CloudConfigurationRegoRule

src/datadog_api_client/v2/model/downtime_monitor_identifier_id.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,10 @@
77
from datadog_api_client.model_utils import (
88
ModelNormal,
99
cached_property,
10-
date,
11-
datetime,
12-
none_type,
13-
UUID,
1410
)
1511

1612

1713
class DowntimeMonitorIdentifierId(ModelNormal):
18-
@cached_property
19-
def additional_properties_type(_):
20-
return (
21-
bool,
22-
date,
23-
datetime,
24-
dict,
25-
float,
26-
int,
27-
list,
28-
str,
29-
UUID,
30-
none_type,
31-
)
32-
3314
@cached_property
3415
def openapi_types(_):
3516
return {

src/datadog_api_client/v2/model/downtime_monitor_identifier_tags.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11-
date,
12-
datetime,
13-
none_type,
14-
UUID,
1511
)
1612

1713

@@ -22,21 +18,6 @@ class DowntimeMonitorIdentifierTags(ModelNormal):
2218
},
2319
}
2420

25-
@cached_property
26-
def additional_properties_type(_):
27-
return (
28-
bool,
29-
date,
30-
datetime,
31-
dict,
32-
float,
33-
int,
34-
list,
35-
str,
36-
UUID,
37-
none_type,
38-
)
39-
4021
@cached_property
4122
def openapi_types(_):
4223
return {

src/datadog_api_client/v2/model/downtime_schedule_one_time_create_update_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717

1818
class DowntimeScheduleOneTimeCreateUpdateRequest(ModelNormal):
19+
@cached_property
20+
def additional_properties_type(_):
21+
return None
22+
1923
@cached_property
2024
def openapi_types(_):
2125
return {

src/datadog_api_client/v2/model/downtime_schedule_recurrence_create_update_request.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,13 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11-
date,
12-
datetime,
1311
none_type,
1412
unset,
1513
UnsetType,
16-
UUID,
1714
)
1815

1916

2017
class DowntimeScheduleRecurrenceCreateUpdateRequest(ModelNormal):
21-
@cached_property
22-
def additional_properties_type(_):
23-
return (
24-
bool,
25-
date,
26-
datetime,
27-
dict,
28-
float,
29-
int,
30-
list,
31-
str,
32-
UUID,
33-
none_type,
34-
)
35-
3618
@cached_property
3719
def openapi_types(_):
3820
return {

src/datadog_api_client/v2/model/downtime_schedule_recurrences_update_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121

2222
class DowntimeScheduleRecurrencesUpdateRequest(ModelNormal):
23+
@cached_property
24+
def additional_properties_type(_):
25+
return None
26+
2327
@cached_property
2428
def openapi_types(_):
2529
from datadog_api_client.v2.model.downtime_schedule_recurrence_create_update_request import (

src/datadog_api_client/v2/model/finding_mute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919

2020
class FindingMute(ModelNormal):
21+
@cached_property
22+
def additional_properties_type(_):
23+
return None
24+
2125
@cached_property
2226
def openapi_types(_):
2327
from datadog_api_client.v2.model.finding_mute_reason import FindingMuteReason

src/datadog_api_client/v2/model/finding_rule.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515

1616
class FindingRule(ModelNormal):
17+
@cached_property
18+
def additional_properties_type(_):
19+
return None
20+
1721
@cached_property
1822
def openapi_types(_):
1923
return {

src/datadog_api_client/v2/model/list_findings_meta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class ListFindingsMeta(ModelNormal):
2424
},
2525
}
2626

27+
@cached_property
28+
def additional_properties_type(_):
29+
return None
30+
2731
@cached_property
2832
def openapi_types(_):
2933
from datadog_api_client.v2.model.list_findings_page import ListFindingsPage

src/datadog_api_client/v2/model/list_findings_page.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515

1616
class ListFindingsPage(ModelNormal):
17+
@cached_property
18+
def additional_properties_type(_):
19+
return None
20+
1721
@cached_property
1822
def openapi_types(_):
1923
return {

src/datadog_api_client/v2/model/security_monitoring_rule_query_payload_data.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,12 @@
88
from datadog_api_client.model_utils import (
99
ModelNormal,
1010
cached_property,
11-
date,
12-
datetime,
13-
none_type,
1411
unset,
1512
UnsetType,
16-
UUID,
1713
)
1814

1915

2016
class SecurityMonitoringRuleQueryPayloadData(ModelNormal):
21-
@cached_property
22-
def additional_properties_type(_):
23-
return (
24-
bool,
25-
date,
26-
datetime,
27-
dict,
28-
float,
29-
int,
30-
list,
31-
str,
32-
UUID,
33-
none_type,
34-
)
35-
3617
@cached_property
3718
def openapi_types(_):
3819
return {

src/datadog_api_client/v2/model/security_monitoring_signal_attributes.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@
1818

1919

2020
class SecurityMonitoringSignalAttributes(ModelNormal):
21-
@cached_property
22-
def additional_properties_type(_):
23-
return (
24-
bool,
25-
date,
26-
datetime,
27-
dict,
28-
float,
29-
int,
30-
list,
31-
str,
32-
UUID,
33-
none_type,
34-
)
35-
3621
@cached_property
3722
def openapi_types(_):
3823
return {

0 commit comments

Comments
 (0)