Skip to content

Enable additionalProperties by default #2111

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 5 commits into from
Aug 16, 2024
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
4 changes: 4 additions & 0 deletions .generator/src/generator/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def basic_type_to_python(type_, schema, typing=False):
def type_to_python(schema, typing=False):
"""Return Python type name for the type."""

# Special case for additionalProperties: True
if schema is True:
return basic_type_to_python(None, {}, typing=typing)

name = formatter.get_name(schema)

if "oneOf" in schema:
Expand Down
8 changes: 7 additions & 1 deletion .generator/src/generator/templates/model_generic.j2
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@ class {{ name }}(ModelNormal):
}
{%- endif %}

{%- if model.get("additionalProperties", false) is not false %}
{%- set additionalProperties = model.get("additionalProperties") %}
{#- Only add additional_properties_type property if additionalProperties is disabled or has a custom type #}
{%- if (additionalProperties is false) or (additionalProperties and additionalProperties is not true) %}
@cached_property
def additional_properties_type(_):
{%- if additionalProperties is false %}
return None
{%- else -%}
{%- if refs %}
{%- for ref in refs %}
from {{ package }}.{{ version }}.model.{{ ref|safe_snake_case }} import {{ ref }}
{%- endfor %}
{%- endif %}
return ({{ type_to_python(model["additionalProperties"]) }},)
{%- endif %}
{%- endif %}

{%- if model.nullable %}
_nullable = True
Expand Down
12 changes: 1 addition & 11 deletions .generator/src/generator/templates/model_utils.j2
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class OpenApiModel(object):

_composed_schemas = empty_dict

additional_properties_type = None
additional_properties_type = ({{ type_to_python(True) }},)

attribute_map: Mapping[str, str] = empty_dict

Expand Down Expand Up @@ -393,16 +393,6 @@ class ModelNormal(OpenApiModel):
def __init__(self, kwargs):
super().__init__(kwargs)
for var_name, var_value in kwargs.items():
if (
var_name not in self.attribute_map
and self._configuration is not None
and self._configuration.discard_unknown_keys
and self.additional_properties_type is None
):
if self._spec_property_naming:
# If it's returned from the API, store it if we need to send it back
self.__dict__["_data_store"][var_name] = var_value
continue
setattr(self, var_name, var_value)
if not self._spec_property_naming and var_name in self.read_only_vars:
raise ApiAttributeError(f"`{var_name}` is a read-only attribute.")
Expand Down
23 changes: 12 additions & 11 deletions src/datadog_api_client/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ class OpenApiModel(object):

_composed_schemas = empty_dict

additional_properties_type = None
additional_properties_type = (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

attribute_map: Mapping[str, str] = empty_dict

Expand Down Expand Up @@ -395,16 +406,6 @@ def __eq__(self, other):
def __init__(self, kwargs):
super().__init__(kwargs)
for var_name, var_value in kwargs.items():
if (
var_name not in self.attribute_map
and self._configuration is not None
and self._configuration.discard_unknown_keys
and self.additional_properties_type is None
):
if self._spec_property_naming:
# If it's returned from the API, store it if we need to send it back
self.__dict__["_data_store"][var_name] = var_value
continue
setattr(self, var_name, var_value)
if not self._spec_property_naming and var_name in self.read_only_vars:
raise ApiAttributeError(f"`{var_name}` is a read-only attribute.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@


class NotebookCellCreateRequest(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.notebook_cell_create_request_attributes import (
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v1/model/slo_time_slice_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@


class SLOTimeSliceSpec(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.slo_time_slice_condition import SLOTimeSliceCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@


class BulkMuteFindingsRequestAttributes(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.bulk_mute_findings_request_properties import BulkMuteFindingsRequestProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class BulkMuteFindingsRequestProperties(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.finding_mute_reason import FindingMuteReason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
date,
datetime,
none_type,
unset,
UnsetType,
UUID,
)


Expand All @@ -22,21 +18,6 @@


class CloudConfigurationComplianceRuleOptions(ModelNormal):
@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.cloud_configuration_rego_rule import CloudConfigurationRegoRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,10 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
date,
datetime,
none_type,
UUID,
)


class DowntimeMonitorIdentifierId(ModelNormal):
@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
date,
datetime,
none_type,
UUID,
)


Expand All @@ -22,21 +18,6 @@ class DowntimeMonitorIdentifierTags(ModelNormal):
},
}

@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@


class DowntimeScheduleOneTimeCreateUpdateRequest(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,13 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
date,
datetime,
none_type,
unset,
UnsetType,
UUID,
)


class DowntimeScheduleRecurrenceCreateUpdateRequest(ModelNormal):
@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@


class DowntimeScheduleRecurrencesUpdateRequest(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.downtime_schedule_recurrence_create_update_request import (
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v2/model/finding_mute.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class FindingMute(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.finding_mute_reason import FindingMuteReason
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v2/model/finding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@


class FindingRule(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
return {
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v2/model/list_findings_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ListFindingsMeta(ModelNormal):
},
}

@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.list_findings_page import ListFindingsPage
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v2/model/list_findings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@


class ListFindingsPage(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,12 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
date,
datetime,
none_type,
unset,
UnsetType,
UUID,
)


class SecurityMonitoringRuleQueryPayloadData(ModelNormal):
@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@


class SecurityMonitoringSignalAttributes(ModelNormal):
@cached_property
def additional_properties_type(_):
return (
bool,
date,
datetime,
dict,
float,
int,
list,
str,
UUID,
none_type,
)

@cached_property
def openapi_types(_):
return {
Expand Down
Loading
Loading