Skip to content

properties' custom_formatters don't work unless the containing shema is strictly Object #149

Description

@phrfpeixoto

Found this issue while investigating the code for #147

I noticed that custom_formatters are not being user for unmarshalling and validating properties, unless their containing Schema is strictly defined.

That is, if the Schema is of type SchemaType.ANY, custom_validators will not work. That's because the _unmarshal_any object fails to propagate the attributes to get_cast_mapping:

def _unmarshal_any(self, value, custom_formatters=None, strict=True):
    types_resolve_order = [
        SchemaType.OBJECT, SchemaType.ARRAY, SchemaType.BOOLEAN,
        SchemaType.INTEGER, SchemaType.NUMBER, SchemaType.STRING,
    ]
    cast_mapping = self.get_cast_mapping()

    ...

This is specifically sensitive for defining MediaType objects:

paths:
  /test:
    get:
      operationId: test
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/DefaultResponse'
components:
  schemas:
    DefaultResponse:
      type: object
      properties:
        url:
          type: string
          format: url

The shema type for that MediaType will be Any (See #147), so that 'url' format will not unmarshal, even though you may define a custom formatter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions