Skip to content

Commit

Permalink
Add additionalProperties: {} for Dict with the default values (#950)
Browse files Browse the repository at this point in the history
* Add `additionalProperties: {}` for Dict with the default `values`

* Add self to AUTHORS.rst

* Update changelog

---------

Co-authored-by: Steven Loria <[email protected]>
  • Loading branch information
luhn and sloria authored Oct 20, 2024
1 parent b1bcefb commit a05b37b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ Contributors (chronological)
- Tobias Kolditz `@kolditz-senec <https://github.com/kolditz-senec>`_
- Christian Proud `@cjproud <https://github.com/cjproud>`_
- `<https://github.com/kolditz-senec >`_
- Theron Luhn `@luhn <https://github.com/luhn>`_
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
6.7.0 (unreleased)
******************

Bug fixes:

- Fix handling of ``fields.Dict()`` with ``values`` unset (:issue:`949`).
Thanks :user:`luhn` for the catch and patch.

Other changes:

- Officially support Python 3.13 (:pr:`948`).
Expand Down
2 changes: 2 additions & 0 deletions src/apispec/ext/marshmallow/field_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ def dict2properties(self, field, **kwargs: typing.Any) -> dict:
value_field = field.value_field
if value_field:
ret["additionalProperties"] = self.field2property(value_field)
else:
ret["additionalProperties"] = {}
return ret

def timedelta2properties(self, field, **kwargs: typing.Any) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_marshmallow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ class SchemaWithDict(Schema):

spec.components.schema("SchemaWithDict", schema=SchemaWithDict)
result = get_schemas(spec)["SchemaWithDict"]["properties"]["dict_field"]
assert result == {"type": "object"}
assert result == {"type": "object", "additionalProperties": {}}

def test_dict_with_nested(self, spec):
class SchemaWithDict(Schema):
Expand Down

0 comments on commit a05b37b

Please sign in to comment.