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

Commit b20460e

Browse files
authored
Merge pull request #292 from darduf/support-alt-application-json-types
fix: failing test with vnd.api+json content type
2 parents 98ed1f6 + 3524c9a commit b20460e

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

openapi_tester/schema_tester.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" Schema Tester """
22
from __future__ import annotations
33

4+
import re
45
from itertools import chain
56
from typing import TYPE_CHECKING, Any, Callable, cast
67

@@ -89,11 +90,16 @@ def __init__(
8990
raise ImproperlyConfigured(INIT_ERROR)
9091

9192
@staticmethod
92-
def get_key_value(schema: dict[str, dict], key: str, error_addon: str = "") -> dict:
93+
def get_key_value(schema: dict[str, dict], key: str, error_addon: str = "", use_regex=False) -> dict:
9394
"""
9495
Returns the value of a given key
9596
"""
9697
try:
98+
if use_regex:
99+
compiled_pattern = re.compile(key)
100+
for key_ in schema.keys():
101+
if compiled_pattern.match(key_):
102+
return schema[key_]
97103
return schema[key]
98104
except KeyError as e:
99105
raise UndocumentedSchemaSectionError(
@@ -168,9 +174,10 @@ def get_response_schema_section(self, response: Response) -> dict[str, Any]:
168174
)
169175
json_object = self.get_key_value(
170176
content_object,
171-
"application/json",
177+
r"^application\/.*json$",
172178
"\n\nNo `application/json` responses documented for method: "
173179
f"{response_method}, path: {parameterized_path}",
180+
use_regex=True,
174181
)
175182
return self.get_key_value(json_object, "schema")
176183

tests/schemas/sample-schemas/content_types.yaml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ paths:
4848
requestBody:
4949
description: Update an existent pet in the store
5050
content:
51-
application/json:
51+
application/vnd.api+json:
5252
schema:
5353
$ref: '#/components/schemas/Pet'
5454
application/xml:
@@ -62,7 +62,7 @@ paths:
6262
'200':
6363
description: Successful operation
6464
content:
65-
application/json:
65+
application/vnd.api+json:
6666
schema:
6767
$ref: '#/components/schemas/Pet'
6868
application/xml:
@@ -87,7 +87,7 @@ paths:
8787
requestBody:
8888
description: Create a new pet in the store
8989
content:
90-
application/json:
90+
application/vnd.api+json:
9191
schema:
9292
$ref: '#/components/schemas/Pet'
9393
application/xml:
@@ -101,7 +101,7 @@ paths:
101101
'200':
102102
description: Successful operation
103103
content:
104-
application/json:
104+
application/vnd.api+json:
105105
schema:
106106
$ref: '#/components/schemas/Pet'
107107
application/xml:
@@ -137,7 +137,7 @@ paths:
137137
'200':
138138
description: successful operation
139139
content:
140-
application/json:
140+
application/vnd.api+json:
141141
schema:
142142
type: array
143143
items:
@@ -174,7 +174,7 @@ paths:
174174
'200':
175175
description: successful operation
176176
content:
177-
application/json:
177+
application/vnd.api+json:
178178
schema:
179179
type: array
180180
items:
@@ -209,7 +209,7 @@ paths:
209209
'200':
210210
description: successful operation
211211
content:
212-
application/json:
212+
application/vnd.api+json:
213213
schema:
214214
$ref: '#/components/schemas/Pet'
215215
application/xml:
@@ -313,7 +313,7 @@ paths:
313313
'200':
314314
description: successful operation
315315
content:
316-
application/json:
316+
application/vnd.api+json:
317317
schema:
318318
$ref: '#/components/schemas/ApiResponse'
319319
security:
@@ -331,7 +331,7 @@ paths:
331331
'200':
332332
description: successful operation
333333
content:
334-
application/json:
334+
application/vnd.api+json:
335335
schema:
336336
type: object
337337
additionalProperties:
@@ -348,7 +348,7 @@ paths:
348348
operationId: placeOrder
349349
requestBody:
350350
content:
351-
application/json:
351+
application/vnd.api+json:
352352
schema:
353353
$ref: '#/components/schemas/Order'
354354
application/xml:
@@ -361,7 +361,7 @@ paths:
361361
'200':
362362
description: successful operation
363363
content:
364-
application/json:
364+
application/vnd.api+json:
365365
schema:
366366
$ref: '#/components/schemas/Order'
367367
'405':
@@ -385,7 +385,7 @@ paths:
385385
'200':
386386
description: successful operation
387387
content:
388-
application/json:
388+
application/vnd.api+json:
389389
schema:
390390
$ref: '#/components/schemas/Order'
391391
application/xml:
@@ -424,7 +424,7 @@ paths:
424424
requestBody:
425425
description: Created user object
426426
content:
427-
application/json:
427+
application/vnd.api+json:
428428
schema:
429429
$ref: '#/components/schemas/User'
430430
application/xml:
@@ -437,7 +437,7 @@ paths:
437437
default:
438438
description: successful operation
439439
content:
440-
application/json:
440+
application/vnd.api+json:
441441
schema:
442442
$ref: '#/components/schemas/User'
443443
application/xml:
@@ -452,7 +452,7 @@ paths:
452452
operationId: createUsersWithListInput
453453
requestBody:
454454
content:
455-
application/json:
455+
application/vnd.api+json:
456456
schema:
457457
type: array
458458
items:
@@ -461,7 +461,7 @@ paths:
461461
'200':
462462
description: Successful operation
463463
content:
464-
application/json:
464+
application/vnd.api+json:
465465
schema:
466466
$ref: '#/components/schemas/User'
467467
application/xml:
@@ -507,7 +507,7 @@ paths:
507507
application/xml:
508508
schema:
509509
type: string
510-
application/json:
510+
application/vnd.api+json:
511511
schema:
512512
type: string
513513
'400':
@@ -541,7 +541,7 @@ paths:
541541
'200':
542542
description: successful operation
543543
content:
544-
application/json:
544+
application/vnd.api+json:
545545
schema:
546546
$ref: '#/components/schemas/User'
547547
application/xml:
@@ -567,7 +567,7 @@ paths:
567567
requestBody:
568568
description: Update an existent user in the store
569569
content:
570-
application/json:
570+
application/vnd.api+json:
571571
schema:
572572
$ref: '#/components/schemas/User'
573573
application/xml:
@@ -773,7 +773,7 @@ components:
773773
Pet:
774774
description: Pet object that needs to be added to the store
775775
content:
776-
application/json:
776+
application/vnd.api+json:
777777
schema:
778778
$ref: '#/components/schemas/Pet'
779779
application/xml:
@@ -782,7 +782,7 @@ components:
782782
UserArray:
783783
description: List of user object
784784
content:
785-
application/json:
785+
application/vnd.api+json:
786786
schema:
787787
type: array
788788
items:

0 commit comments

Comments
 (0)