Failures in oneOf, anyOf, etc, are actually in the referenced schema

Ouverte
#126 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
docker, openapi, python
Domaine
api, testing-qa

Piste de recherche

Reproduce the issue with the provided OpenAPI YAML and the shown Docker command, then trace how validation handles oneOf and anyOf references. The fix is done when an invalid referenced Dog schema produces an error at components.schemas.Dog rather than at the containing oneOf or requestBody.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

If a schema is invalid, it will cause a oneOf to fail instead of failing on its own. I discovered this while thinking optional was a valid thing.

The below is valid except I've added optional to Dog. The failure is now On instance['paths']['/pets']['patch']['requestBody'] instead of the expected ['components']['schemas']['Dog'].

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Cat'
                  - $ref: '#/components/schemas/Dog'
components:
  schemas:
    Dog:
      type: object
      optional: [ "bark" ]
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
$ docker run -v $PWD/simple.yaml:/openapi.yaml --rm p1c2u/openapi-spec-validator /openapi.yaml
{'content': {'application/json': {'schema': {'oneOf': [{'$ref': '#/components/schemas/Cat', 'x-scope': ['file:///openapi.yaml']}, {'$ref':'#/components/schemas/Dog', 'x-scope': ['file:///openapi.yaml']}]}}}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['requestBody']:                             
    {'oneOf': [{'$ref': '#/definitions/RequestBody'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/pets']['patch']['requestBody']:
    {'content': {'application/json': {'schema': {'oneOf': [{'$ref': '#/components/schemas/Cat',
                                                            'x-scope': ['file:///openapi.yaml']},
                                                           {'$ref': '#/components/schemas/Dog',
                                                            'x-scope': ['file:///openapi.yaml']}]}}}}
Langage dominant
Python
Étoiles
409
Forks
73
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-openapi/openapi-spec-validator

Toutes les issues de python-openapi/openapi-spec-validator

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.