openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

Failed validating 'oneOf' in schema

Open manchenkoff opened this issue 3 years ago • 5 comments

Hi, after updating to the latest release I had a strange error with schemas.

Swagger example

/couriers/{courierIdentifier}:
        get:
            description: 'description text'
            tags:
                - Couriers
            parameters:
                -   $ref: '#/components/parameters/courierIdentifierInPath'
            responses:
                200:
                    description: 'successful response'
                    content:
                        application/json:
                            schema:
                                $ref: 'definitions/couriers/get.yml#/responses/GetResponse'
                400:
                    $ref: '#/components/responses/CommonSuccessfulResponse'
                500:
                    $ref: '#/components/responses/CommonSuccessfulResponse'

Validation error

{'description': 'successful response', 'content': {'application/json': {'schema': {'$ref': 'definitions/couriers/get.yml#/responses/GetResponse', 'x-scope': ['file:///data/swagger.yml']}}}} 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']['responses']['patternProperties']['^[1-5](?:\\d{2}|XX)$']:
    {'oneOf': [{'$ref': '#/definitions/Response'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/couriers/{courierIdentifier}']['get']['responses']['200']:
    {'content': {'application/json': {'schema': {'$ref': 'definitions/couriers/get.yml#/responses/GetResponse',
                                                 'x-scope': ['file:///data/swagger.yml']}}},
     'description': 'successful response'}

But if I remove $ref parameter in schema description or change it to type: string it works fine.

Do you know any solutions? Thanks

manchenkoff avatar Feb 26 '21 12:02 manchenkoff

This happens to me, too.

/become:
    get:
      operationId: become_user
      parameters:
      - description: Numeric identifier of the user to turn into.
        explode: false
        in: query
        name: id
        required: false
        schema:
          type: string
        style: simple

Error:

connexion.exceptions.InvalidSpecification: {'description': 'Numeric identifier of the user to turn into.', 'explode': False, 'in': 'query', 'name': 'id', 'required': False, 'schema': {'type': 'string'}, 'style': 'simple'} 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']['parameters']['items']:
    {'oneOf': [{'$ref': '#/definitions/Parameter'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/become']['get']['parameters'][0]:
    {'description': 'Numeric identifier of the user to turn into.',
     'explode': False,
     'in': 'query',
     'name': 'id',
     'required': False,
     'schema': {'type': 'string'},
     'style': 'simple'}

vmarkovtsev avatar Feb 26 '21 14:02 vmarkovtsev

I have this issue as well. For now I have added openapi-spec-validator<0.3 in my project's requirements.txt to avoid this issue.

briankinney avatar Mar 01 '21 15:03 briankinney

You're probably getting stuck on #126 - The easiest workaround is to make a very basic '#/components/schemas/simple and point all your refs to that; then it'll validate all your other schemata and tell you where the error is.

Altreus avatar May 19 '21 14:05 Altreus

Also pinning down the package here... :-/

MRigal avatar Jun 21 '21 14:06 MRigal

Does https://github.com/p1c2u/openapi-spec-validator/pull/129 helps?

It can be tried temporarily using:

pip install --force-reinstall git+https://github.com/JulienPalard/openapi-spec-validator@show-context

JulienPalard avatar Sep 02 '21 10:09 JulienPalard