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

show the full path of the error/warning in iter_errors #152

Open
AlwaysBeCalm opened this issue Apr 26, 2022 · 0 comments
Open

show the full path of the error/warning in iter_errors #152

AlwaysBeCalm opened this issue Apr 26, 2022 · 0 comments

Comments

@AlwaysBeCalm
Copy link

Hi everyone

I'm validating this open API: https://api.apis.guru/v2/specs/exlibrisgroup.com/tasklists/1.0/openapi.json and I need it to show me the absolute path of the error/warning instead, not only: {'default': '10', 'type': 'integer', 'nullable': False}
because the API is a little big and I want an easy way to trace the error/warning.

the code:

import json
import requests
from openapi_spec_validator import openapi_v3_spec_validator

with open('openapi.json', 'w') as file:
    file.write(requests.get('https://api.apis.guru/v2/specs/exlibrisgroup.com/tasklists/1.0/openapi.json').text)
    file.close()

with open('openapi.json', 'r') as file:
    schema = json.load(file)
    file.close()

errors = openapi_v3_spec_validator.iter_errors(schema)
for error in errors:
    print(error)
    print(error.schema, error.path, error.absolute_schema_path)
    print(error.relative_path, error.relative_schema_path, error.schema_path)
    break    

the output:

'10' is not of type integer

Failed validating 'type' in schema:
    {'default': '10', 'nullable': False, 'type': 'integer'}

On instance:
    '10'
{'default': '10', 'type': 'integer', 'nullable': False} deque([]) deque(['type'])
deque([]) deque(['type']) deque(['type'])

it would be nice if this output is also added to the message:
#/paths//almaws/v1/task-lists/printouts/get/parameters[4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant