snok/drf-openapi-tester

UndocumentedSchemaSectionError

Closed this issue · 5 comments

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: `
```


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

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/']

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 🙂

yeah sure, will do that

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 🙂