snok / drf-openapi-tester

Test utility for validating OpenAPI documentation
https://github.com/snok/django-openapi-tester
BSD 3-Clause "New" or "Revised" License
119 stars 23 forks source link

UndocumentedSchemaSectionError #257

Closed nibinjose closed 2 years ago

nibinjose commented 2 years ago

I'm using drf_spectacular and Django oscar with auto-generated schema, while running test cases with

@staticmethod
def assertResponse(response: Response, **kwargs) -> None:
  """helper to run validate_response and pass kwargs to it"""
  schema_tester.validate_response(response=response, **kwargs)

getting an UndocumentedSchemaSectionError, example URL : '/api/storefront/{version}/addresses/'

Error message is

Error
 Traceback (most recent call last):
   File "/usr/local/lib/python3.9/site-packages/openapi_tester/schema_tester.py", line 86, in get_key_value
     return schema[key]
 KeyError: '/api/storefront/{version}/addresses/'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/project/tests/storefront_api/tests_address.py", line 193, in test_address_listing
    self.assertResponse(response=response)
  File "/opt/project/tests/utils.py", line 208, in assertResponse
    schema_tester.validate_response(response=response, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/openapi_tester/schema_tester.py", line 382, in validate_response
    response_schema = self.get_response_schema_section(response)
  File "/usr/local/lib/python3.9/site-packages/openapi_tester/schema_tester.py", line 125, in get_response_schema_section
    route_object = self.get_key_value(
  File "/usr/local/lib/python3.9/site-packages/openapi_tester/schema_tester.py", line 88, in get_key_value
    raise UndocumentedSchemaSectionError(
openapi_tester.exceptions.UndocumentedSchemaSectionError: Error: Unsuccessfully tried to index the OpenAPI schema by `/api/storefront/{version}/addresses/`. 

Undocumented route /api/storefront/{version}/addresses/.

Documented routes: `
sondrelg commented 2 years ago

Hi @nibinjose :) What does your OpenAPI schema look like? Does it contain the route mentioned?

nibinjose commented 2 years ago

yes it is.

['/api/storefront/{version}/order/{order_number}/payments/airpay/check/', '/api/dashboard/{version}/media/', '/api/admin/{version}/products/{upc}/', '/api/dashboard/{version}/components/{pk}/', '/api/storefront/{version}/contact-us/', '/api/storefront/{version}/addresses/']

sondrelg commented 2 years ago

Would you mind opening a PR replicating the issue in the repo's test-project folder? I'm not really sure how to explore this further without an example to test 🙂

nibinjose commented 2 years ago

yeah sure, will do that

sondrelg commented 2 years ago

I'm going to temporarily close this. Feel free to ping me when you get a chance to open a PR and I'll re-open 🙂