waldronlab / cBioPortalData

Integrate the cancer genomics portal, cBioPortal, using MultiAssayExperiment
https://waldronlab.io/cBioPortalData/
30 stars 12 forks source link

Creating Python client using bravado results in ValidationErrors #45

Closed tdeboer-ilmn closed 2 years ago

tdeboer-ilmn commented 2 years ago

I'm trying to create a Python client for the cBioPortal API as described on the API documentation website, but run into validation errors.

from bravado.client import SwaggerClient
cbioportal = SwaggerClient.from_url('https://www.cbioportal.org/api/api-docs',
                                    config={"validate_requests":False,"validate_responses":False})
)
ValidationError                           Traceback (most recent call last)
~/NBdev/lib/python3.7/site-packages/swagger_spec_validator/common.py in wrapper(*args, **kwargs)
     35         try:
---> 36             return method(*args, **kwargs)
     37         except Exception as e:
.
.
.
ValidationError: {'name': 'credentials', 'in': 'query', 'required': False, 'type': 'object'} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['parameters']['items']:
    {'oneOf': [{'$ref': '#/definitions/parameter'},
               {'$ref': '#/definitions/jsonReference'}]}

On instance['paths']['/studies']['get']['parameters'][2]:
    {'in': 'query',
     'name': 'credentials',
     'required': False,
     'type': 'object'}

During handling of the above exception, another exception occurred:
.
.
.
SwaggerValidationError: ("{'name': 'credentials', 'in': 'query', 'required': False, 'type': 'object'} is not valid under any of the given schemas\n\nFailed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['parameters']['items']:\n    {'oneOf': [{'$ref': '#/definitions/parameter'},\n               {'$ref': '#/definitions/jsonReference'}]}\n\nOn instance['paths']['/studies']['get']['parameters'][2]:\n    {'in': 'query',\n     'name': 'credentials',\n     'required': False,\n     'type': 'object'}", <ValidationError: "{'name': 'credentials', 'in': 'query', 'required': False, 'type': 'object'} is not valid under any of the given schemas">)

I tried some other methods (openapi-python-client generate --url https://www.cbioportal.org/api/api-docs) with the same results, so it seems there may be some issues with the OpenAPI 2.0 defintion file?

tdeboer-ilmn commented 2 years ago

I found a workaround...

Adding "validate_swagger_spec":False to the config results in a functional client

from bravado.client import SwaggerClient
cbioportal = SwaggerClient.from_url(
    'https://www.cbioportal.org/api/api-docs',
    config={
        "validate_requests":False,
        "validate_responses":False,
        "validate_swagger_spec":False
    })
LiNk-NY commented 2 years ago

Hi Thon, @tdeboer-ilmn

We don't make changes to the API from cBioPortal. If you're encountering issues with the API, it's best to report them in this repo. https://github.com/cBioPortal/cbioportal

Best regards, Marcel