Skip to content

Commit

Permalink
Merge pull request #892 from cjproud/fix-ip-field
Browse files Browse the repository at this point in the history
Add IP fields to DEFAULT_FIELD_MAPPING
  • Loading branch information
lafrech committed Mar 15, 2024
2 parents 2855263 + e0fc7b0 commit a24c940
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ Contributors (chronological)
- Sebastien Lovergne `@TheBigRoomXXL <https://github.com/TheBigRoomXXL>`_
- Luna Lovegood `@duchuyvp <https://github.com/duchuyvp>`_
- Tobias Kolditz `@kolditz-senec <https://github.com/kolditz-senec>`_
- Christian Proud `@cjproud <https://github.com/cjproud>`_
3 changes: 3 additions & 0 deletions src/apispec/ext/marshmallow/field_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
marshmallow.fields.Field: (None, None),
marshmallow.fields.Raw: (None, None),
marshmallow.fields.List: ("array", None),
marshmallow.fields.IP: ("string", "ip"),
marshmallow.fields.IPv4: ("string", "ipv4"),
marshmallow.fields.IPv6: ("string", "ipv6"),
}


Expand Down
6 changes: 6 additions & 0 deletions tests/test_ext_marshmallow_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def test_field2choices_preserving_order(openapi):
(fields.TimeDelta, "integer"),
(fields.Email, "string"),
(fields.URL, "string"),
(fields.IP, "string"),
(fields.IPv4, "string"),
(fields.IPv6, "string"),
# Custom fields inherit types from their parents
(CustomStringField, "string"),
(CustomIntegerField, "integer"),
Expand Down Expand Up @@ -66,6 +69,9 @@ def test_formatted_field_translates_to_array(ListClass, spec_fixture):
(fields.Date, "date"),
(fields.Email, "email"),
(fields.URL, "url"),
(fields.IP, "ip"),
(fields.IPv4, "ipv4"),
(fields.IPv6, "ipv6"),
],
)
def test_field2property_formats(FieldClass, expected_format, spec_fixture):
Expand Down

0 comments on commit a24c940

Please sign in to comment.