Skip to content

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

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

Open
phrfpeixoto opened this issue Jul 7, 2019 · 2 comments

Comments

@phrfpeixoto
Copy link
Contributor

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.

@phrfpeixoto
Copy link
Contributor Author

As a work around, you may add a type declaration alongside that allOf:

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

@phrfpeixoto phrfpeixoto changed the title properties' custom_formatters do work unless the containing shema is strictly Object properties' custom_formatters don't work unless the containing shema is strictly Object Jul 14, 2019
@phrfpeixoto
Copy link
Contributor Author

@p1c2u Would you mind reviewing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant