Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
fix for vnd.api+json content type using regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Darragh Duffy committed Dec 1, 2022
1 parent de0b4e7 commit 3524c9a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions openapi_tester/schema_tester.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Schema Tester """
from __future__ import annotations

import re
from itertools import chain
from typing import TYPE_CHECKING, Any, Callable, cast

Expand Down Expand Up @@ -89,11 +90,16 @@ def __init__(
raise ImproperlyConfigured(INIT_ERROR)

@staticmethod
def get_key_value(schema: dict[str, dict], key: str, error_addon: str = "") -> dict:
def get_key_value(schema: dict[str, dict], key: str, error_addon: str = "", use_regex=False) -> dict:
"""
Returns the value of a given key
"""
try:
if use_regex:
compiled_pattern = re.compile(key)
for key_ in schema.keys():
if compiled_pattern.match(key_):
return schema[key_]
return schema[key]
except KeyError as e:
raise UndocumentedSchemaSectionError(
Expand Down Expand Up @@ -168,9 +174,10 @@ def get_response_schema_section(self, response: Response) -> dict[str, Any]:
)
json_object = self.get_key_value(
content_object,
"application/json",
r"^application\/.*json$",
"\n\nNo `application/json` responses documented for method: "
f"{response_method}, path: {parameterized_path}",
use_regex=True,
)
return self.get_key_value(json_object, "schema")

Expand Down

0 comments on commit 3524c9a

Please sign in to comment.