-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Validate doesnt seem to match schema correctly? #136
Comments
Hi @dicolanl thanks for the report. it's probably because you use schema keyword "items" as a property name. If you change the name it should work. I don't know the solution for the issue at this point. EDIT: validate(openapi_schema_path, response.json()) Are you sure you pass parameters correctly? |
it seems to validate fine, if i flip them i get
|
I changed my code but now nothing validates? ideas? def validate_api_endpoint(api_endpoint, request_payload=None, response_schema=None):
url = f"{base_url}{api_endpoint}"
headers = {'Authorization': 'token'}
try:
# Make an API request
response = requests.get(url, json=request_payload, verify=False, headers=headers)
if response.status_code == 200:
# Validate the response against the OpenAPI schema
validate(response.json(), response_schema)
else:
print(f"API endpoint '{api_endpoint}' call failed:")
return
print(f"API endpoint '{api_endpoint}' is valid according to the OpenAPI schema.")
except Exception as e:
print(f"API endpoint '{api_endpoint}' validation failed:")
print(str(e))
def validate_all_endpoints():
spec_dict, base_uri = read_from_filename(openapi_schema_path)
validate(spec_dict)
paths = spec_dict.get('paths', {})
for api_endpoint, methods in paths.items():
for http_method, _ in methods.items():
if http_method == 'get':
response_schema = spec_dict['paths'][api_endpoint]['get']['responses']['200']['content']['application/json']['schema']
validate_api_endpoint(api_endpoint, request_payload=None, response_schema=response_schema) |
I am using validate against API responses.
seems to work on many of the apis. But when the api returns something like:
which is an object with items property and an array of integers or objects in other cases. The validate throws
the schema is defined as
which matches the actual response.
Am i doing something wrong with validate?
The text was updated successfully, but these errors were encountered: