@@ -243,7 +243,7 @@ custom field subclasses a standard marshmallow `Field` class then it will
243243inherit the default mapping. If you want to override the OpenAPI type and format
244244for custom fields, use the
245245`map_to_openapi_type <apispec.ext.marshmallow.MarshmallowPlugin.map_to_openapi_type> `
246- decorator . It can be invoked with either a pair of strings providing the
246+ method . It can be invoked with either a pair of strings providing the
247247OpenAPI type and format, or a marshmallow `Field ` that has the desired target mapping.
248248
249249.. code-block :: python
@@ -258,21 +258,26 @@ OpenAPI type and format, or a marshmallow `Field` that has the desired target ma
258258 title = " Demo" , version = " 0.1" , openapi_version = " 3.0.0" , plugins = (ma_plugin,)
259259 )
260260
261- # Inherits Integer mapping of ('integer', 'int32' )
262- class MyCustomInteger (Integer ):
261+ # Inherits Integer mapping of ('integer', None )
262+ class CustomInteger (Integer ):
263263 pass
264264
265265
266266 # Override Integer mapping
267- @ma_plugin.map_to_openapi_type (" string" , " uuid" )
268- class MyCustomField (Integer ):
267+ class Int32 (Integer ):
269268 pass
270269
271270
272- @ma_plugin.map_to_openapi_type (Integer) # will map to ('integer', 'int32')
273- class MyCustomFieldThatsKindaLikeAnInteger (Field ):
271+ ma_plugin.map_to_openapi_type(Int32, " string" , " int32" )
272+
273+
274+ # Map to ('integer', None) like Integer
275+ class IntegerLike (Field ):
274276 pass
275277
278+
279+ ma_plugin.map_to_openapi_type(IntegerLike, Integer)
280+
276281 In situations where greater control of the properties generated for a custom field
277282is desired, users may add custom logic to the conversion of fields to OpenAPI properties
278283through the use of the `add_attribute_function
0 commit comments