Skip to content

Commit 05839de

Browse files
committed
enable additionalProperties by default
1 parent ad4a270 commit 05839de

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ class {{ name }}(ModelNormal):
5454
}
5555
{%- endif %}
5656

57-
{%- if model.get("additionalProperties", false) is not false %}
57+
{%- set additionalProperties = model.get("additionalProperties", false) %}
58+
{%- if additionalProperties is not false %}
5859
@cached_property
5960
def additional_properties_type(_):
6061
{%- if refs %}
6162
{%- for ref in refs %}
6263
from {{ package }}.{{ version }}.model.{{ ref|safe_snake_case }} import {{ ref }}
6364
{%- endfor %}
6465
{%- endif %}
65-
return ({{ type_to_python(model["additionalProperties"]) }},)
66+
return ({{ type_to_python(additionalProperties) }},)
6667
{%- endif %}
6768

6869
{%- if model.nullable %}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class ModelNormal(OpenApiModel):
397397
var_name not in self.attribute_map
398398
and self._configuration is not None
399399
and self._configuration.discard_unknown_keys
400-
and self.additional_properties_type is None
400+
and self.additional_properties_type is not None
401401
):
402402
if self._spec_property_naming:
403403
# If it's returned from the API, store it if we need to send it back

0 commit comments

Comments
 (0)