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

show the full path of the error/warning in iter_errors

Open AlwaysBeCalm opened this issue 3 years ago • 0 comments

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]

AlwaysBeCalm avatar Apr 26 '22 12:04 AlwaysBeCalm