def test_attributes(self) -> None: """ Checks: * All endpoints have `operationId` and `tag` attributes. * All example responses match their schema. * That no opaque object exists. """ EXCLUDE = ["/real-time", "/register", "/events"] VALID_TAGS = [ "users", "server_and_organizations", "authentication", "real_time_events", "streams", "messages", "users", "webhooks" ] paths = OpenAPISpec(OPENAPI_SPEC_PATH).openapi()["paths"] for path, path_item in paths.items(): if path in EXCLUDE: continue for method, operation in path_item.items(): # Check if every file has an operationId assert ("operationId" in operation) assert ("tags" in operation) tag = operation["tags"][0] assert (tag in VALID_TAGS) for status_code, response in operation['responses'].items(): schema = response['content']['application/json']['schema'] if 'oneOf' in schema: for subschema_index, subschema in enumerate( schema['oneOf']): validate_schema(subschema) assert (validate_against_openapi_schema( subschema['example'], path, method, status_code + '_' + str(subschema_index))) continue validate_schema(schema) assert (validate_against_openapi_schema( schema['example'], path, method, status_code))
def test_attributes(self) -> None: """ Checks: * All endpoints have `operationId` and `tag` attributes. * All example responses match their schema. * That no opaque object exists. """ EXCLUDE = ["/real-time"] VALID_TAGS = [ "users", "server_and_organizations", "authentication", "real_time_events", "streams", "messages", "drafts", "webhooks", ] paths = OpenAPISpec(OPENAPI_SPEC_PATH).openapi()["paths"] for path, path_item in paths.items(): if path in EXCLUDE: continue for method, operation in path_item.items(): # Check if every file has an operationId assert "operationId" in operation assert "tags" in operation tag = operation["tags"][0] assert tag in VALID_TAGS for status_code, response in operation["responses"].items(): schema = response["content"]["application/json"]["schema"] if "oneOf" in schema: for subschema_index, subschema in enumerate( schema["oneOf"]): validate_schema(subschema) assert validate_against_openapi_schema( subschema["example"], path, method, status_code + "_" + str(subschema_index), ) continue validate_schema(schema) assert validate_against_openapi_schema( schema["example"], path, method, status_code)