Skip to content

Schemas defined by allOf are not treated as Objects #147

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

Closed
phrfpeixoto opened this issue Jul 7, 2019 · 4 comments
Closed

Schemas defined by allOf are not treated as Objects #147

phrfpeixoto opened this issue Jul 7, 2019 · 4 comments
Labels
area/schema Indicates an issue on schema area

Comments

@phrfpeixoto
Copy link
Contributor

phrfpeixoto commented Jul 7, 2019

I've noticed that if you define a Schema using allOf, that particular schema will note marked as an object itself, even though it's based in other objects.

OAS3 States:

Composition and Inheritance (Polymorphism)

The OpenAPI Specification allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model composition. allOf takes an array of object definitions that are validated independently but together compose a single object.

It's clear that the result of a usage of an allOf statement should produce an object.

Tried with:

components:
  schemas:
    Error:
      type: object,
      properties:
        message:
          type: string
    TS:
      type: object
      properties:
        moment:
          type: string,
          format: datetime
    ExtendedError:
      type: object
      properties:
        message:
          type: string
        suberror:
          allOf:
            - $ref: '#/components/schemas/Error'
            - $ref: '#/components/schemas/TS'

In this case the Schema for suberror have it's type property set to SchemaType.Any because of they way how the type is defined without checking on inheritance:

self.type = SchemaType(schema_type)
# ... REDACTED CODE ...
self.all_of = all_of and list(all_of) or []
@phrfpeixoto
Copy link
Contributor Author

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

components:
  schemas:
    Error:
      type: object,
      properties:
        message:
          type: string
    TS:
      type: object
      properties:
        moment:
          type: string,
          format: datetime
    ExtendedError:
      type: object
      properties:
        message:
          type: string
        suberror:
          type: object
          allOf:
            - $ref: '#/components/schemas/Error'
            - $ref: '#/components/schemas/TS'

@phrfpeixoto
Copy link
Contributor Author

@p1c2u Would you mind reviewing this?

@p1c2u p1c2u added the area/schema Indicates an issue on schema area label Sep 5, 2019
@p1c2u
Copy link
Collaborator

p1c2u commented Sep 7, 2019

It's clear that the result of a usage of an allOf statement should produce an object.

It's said they both compose a single object. Object here is meant by object definition and not object type

Take a look at the following example:

allOf:
  - type: string
  - type: string

@phrfpeixoto
Copy link
Contributor Author

That's exactly what I'm reporting. The code only treats the resulting object as such if you specify the type

@p1c2u p1c2u closed this as completed Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Indicates an issue on schema area
Projects
None yet
Development

No branches or pull requests

2 participants