Skip to content
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

allOf validation not working? #120

Open
hotmeteor opened this issue Jul 22, 2021 · 1 comment
Open

allOf validation not working? #120

hotmeteor opened this issue Jul 22, 2021 · 1 comment
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed

Comments

@hotmeteor
Copy link

Hi, I'm having issues getting an example spec using allOf to work. This is the spec, as provided by the OpenAPI docs:

openapi: 3.0.0
info:
  title: AllOf.v1
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: Updated
components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
    Dog: # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [ Dingo, Husky, Retriever, Shepherd ]
    Cat: # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer

My test attempts to send a JSON PATCH request to the /pets endpoint, using:

[
    'pet_type' => 'Cat',
    'age' => 3,
    'hunts' => true,
]

However, this only results in:

Request body did not match provided JSON schema.

Digging in a bit more, it appears that the validator doesn't see the pet_type property it should be inheriting from the Pet component.

Any experience with this, or ideas? Thanks in advance.

@cebe cebe added good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed labels Oct 13, 2021
@Aribros
Copy link

Aribros commented Jul 28, 2023

I have been trying to reproduce this issue, @hotmeteor if you could give me a hint on how to reproduce the issue, it will be appreciated.

Please, which library are you using for your validation?

I think the issue may be as a result of failure of your library to recognise the allOf reference.

Please, I am waiting for your reply as I am working to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants