Skip to content
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

Set the format of marshmallow.fields.Float fields to float #862

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/apispec/ext/marshmallow/field_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
DEFAULT_FIELD_MAPPING: dict[type, tuple[str | None, str | None]] = {
marshmallow.fields.Integer: ("integer", None),
marshmallow.fields.Number: ("number", None),
marshmallow.fields.Float: ("number", None),
marshmallow.fields.Float: ("number", "float"),
marshmallow.fields.Decimal: ("number", None),
marshmallow.fields.String: ("string", None),
marshmallow.fields.Boolean: ("boolean", None),
Expand Down
1 change: 1 addition & 0 deletions tests/test_ext_marshmallow_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_formatted_field_translates_to_array(ListClass, spec_fixture):
(fields.Date, "date"),
(fields.Email, "email"),
(fields.URL, "url"),
(fields.Float, "float"),
],
)
def test_field2property_formats(FieldClass, expected_format, spec_fixture):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_ext_marshmallow_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class UserSchema(Schema):
_id = fields.Int()
email = fields.Email(metadata={"description": "email address of the user"})
name = fields.Str()
my_float = fields.Float()

class Meta:
title = "User"
Expand All @@ -65,6 +66,7 @@ class Meta:
assert res["type"] == "object"
props = res["properties"]
assert props["_id"]["type"] == "integer"
assert props["my_float"]["format"] == "float"
assert props["email"]["type"] == "string"
assert props["email"]["format"] == "email"
assert props["email"]["description"] == "email address of the user"
Expand Down