Skip to content

Commit 43080c8

Browse files
anderskamaranand360
authored andcommitted
requirements: Upgrade to openapi-core pre-release.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
1 parent 7fd2fef commit 43080c8

File tree

5 files changed

+36
-55
lines changed

5 files changed

+36
-55
lines changed

requirements/common.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ requests[security]
160160
requests-oauthlib
161161

162162
# For OpenAPI schema validation.
163-
openapi-core
164-
jsonschema-specifications<2023.11.1 # https://github.com/python-openapi/openapi-core/pull/686
163+
openapi-core>=0.19.0a1 # https://github.com/python-openapi/openapi-core/pull/646, https://github.com/python-openapi/openapi-core/pull/697, https://github.com/python-openapi/openapi-core/pull/701, https://github.com/python-openapi/openapi-core/pull/713, https://github.com/python-openapi/openapi-core/pull/725
165164
importlib-resources ; python_version < "3.9"
166165

167166
# For reporting errors to sentry.io

requirements/dev.txt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,16 +1134,13 @@ jsonschema==4.21.1 \
11341134
jsonschema-path==0.3.2 \
11351135
--hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \
11361136
--hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989
1137-
# via openapi-spec-validator
1138-
jsonschema-spec==0.2.4 \
1139-
--hash=sha256:873e396ad1ba6edf9f52d6174c110d4fafb7b5f5894744246a53fe75e5251ec2 \
1140-
--hash=sha256:e6dcf7056734ec6854f7888da6c08ce6c421f28aeeddce96bb90de0fb6d711ef
1141-
# via openapi-core
1142-
jsonschema-specifications==2023.7.1 \
1143-
--hash=sha256:05adf340b659828a004220a9613be00fa3f223f2b82002e273dee62fd50524b1 \
1144-
--hash=sha256:c91a50404e88a1f6ba40636778e2ee08f6e24c5613fe4c53ac24578a5a7f72bb
11451137
# via
1146-
# -r requirements/common.in
1138+
# openapi-core
1139+
# openapi-spec-validator
1140+
jsonschema-specifications==2023.12.1 \
1141+
--hash=sha256:48a76787b3e70f5ed53f1160d2b81f586e4ca6d1548c5de7085d1682674764cc \
1142+
--hash=sha256:87e4fdf3a94858b8a2ba2778d9ba57d8a9cafca7c7489c46ba0d30a8bc6a9c3c
1143+
# via
11471144
# jsonschema
11481145
# openapi-schema-validator
11491146
jsx-lexer==2.0.1 \
@@ -1622,9 +1619,9 @@ oauthlib==3.2.2 \
16221619
# via
16231620
# requests-oauthlib
16241621
# social-auth-core
1625-
openapi-core==0.18.2 \
1626-
--hash=sha256:d4cc50f3ee03ae46313c83e97c6fbfe7e7ae9686741135eb0e4ed49e9d8ff08a \
1627-
--hash=sha256:ec13d366766d564450de60374f59feb0b5ccb447aed642cdf0f1ecfcc6fbe80a
1622+
openapi-core==0.19.0a1 \
1623+
--hash=sha256:3d339c12f0da2948b19d196203651592314fef4c7c9f88e0fa81bf47cc86deed \
1624+
--hash=sha256:76414ebd43aea54a0f34c603ee986470293fe7bcde53fb74f4ba41a8f76746ac
16281625
# via -r requirements/common.in
16291626
openapi-schema-validator==0.6.2 \
16301627
--hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \
@@ -1715,9 +1712,7 @@ parso==0.8.3 \
17151712
pathable==0.4.3 \
17161713
--hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \
17171714
--hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14
1718-
# via
1719-
# jsonschema-path
1720-
# jsonschema-spec
1715+
# via jsonschema-path
17211716
pathspec==0.12.1 \
17221717
--hash=sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08 \
17231718
--hash=sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712
@@ -2291,7 +2286,6 @@ pyyaml==6.0.1 \
22912286
--hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f
22922287
# via
22932288
# jsonschema-path
2294-
# jsonschema-spec
22952289
# libcst
22962290
# moto
22972291
# myst-parser
@@ -2308,13 +2302,12 @@ redis==5.0.1 \
23082302
--hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \
23092303
--hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f
23102304
# via -r requirements/common.in
2311-
referencing==0.30.2 \
2312-
--hash=sha256:449b6669b6121a9e96a7f9e410b245d471e8d48964c67113ce9afe50c8dd7bdf \
2313-
--hash=sha256:794ad8003c65938edcdbc027f1933215e0d0ccc0291e3ce20a4d87432b59efc0
2305+
referencing==0.31.1 \
2306+
--hash=sha256:81a1471c68c9d5e3831c30ad1dd9815c45b558e596653db751a2bfdd17b3b9ec \
2307+
--hash=sha256:c19c4d006f1757e3dd75c4f784d38f8698d87b649c54f9ace14e5e8c9667c01d
23142308
# via
23152309
# jsonschema
23162310
# jsonschema-path
2317-
# jsonschema-spec
23182311
# jsonschema-specifications
23192312
# types-jsonschema
23202313
regex==2023.12.25 \
@@ -2420,7 +2413,6 @@ requests[security]==2.31.0 \
24202413
# via
24212414
# -r requirements/common.in
24222415
# jsonschema-path
2423-
# jsonschema-spec
24242416
# moto
24252417
# pyoembed
24262418
# python-digitalocean

requirements/prod.txt

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -884,16 +884,13 @@ jsonschema==4.21.1 \
884884
jsonschema-path==0.3.2 \
885885
--hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \
886886
--hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989
887-
# via openapi-spec-validator
888-
jsonschema-spec==0.2.4 \
889-
--hash=sha256:873e396ad1ba6edf9f52d6174c110d4fafb7b5f5894744246a53fe75e5251ec2 \
890-
--hash=sha256:e6dcf7056734ec6854f7888da6c08ce6c421f28aeeddce96bb90de0fb6d711ef
891-
# via openapi-core
892-
jsonschema-specifications==2023.7.1 \
893-
--hash=sha256:05adf340b659828a004220a9613be00fa3f223f2b82002e273dee62fd50524b1 \
894-
--hash=sha256:c91a50404e88a1f6ba40636778e2ee08f6e24c5613fe4c53ac24578a5a7f72bb
895887
# via
896-
# -r requirements/common.in
888+
# openapi-core
889+
# openapi-spec-validator
890+
jsonschema-specifications==2023.12.1 \
891+
--hash=sha256:48a76787b3e70f5ed53f1160d2b81f586e4ca6d1548c5de7085d1682674764cc \
892+
--hash=sha256:87e4fdf3a94858b8a2ba2778d9ba57d8a9cafca7c7489c46ba0d30a8bc6a9c3c
893+
# via
897894
# jsonschema
898895
# openapi-schema-validator
899896
jsx-lexer==2.0.1 \
@@ -1201,9 +1198,9 @@ oauthlib==3.2.2 \
12011198
# via
12021199
# requests-oauthlib
12031200
# social-auth-core
1204-
openapi-core==0.18.2 \
1205-
--hash=sha256:d4cc50f3ee03ae46313c83e97c6fbfe7e7ae9686741135eb0e4ed49e9d8ff08a \
1206-
--hash=sha256:ec13d366766d564450de60374f59feb0b5ccb447aed642cdf0f1ecfcc6fbe80a
1201+
openapi-core==0.19.0a1 \
1202+
--hash=sha256:3d339c12f0da2948b19d196203651592314fef4c7c9f88e0fa81bf47cc86deed \
1203+
--hash=sha256:76414ebd43aea54a0f34c603ee986470293fe7bcde53fb74f4ba41a8f76746ac
12071204
# via -r requirements/common.in
12081205
openapi-schema-validator==0.6.2 \
12091206
--hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \
@@ -1278,9 +1275,7 @@ parso==0.8.3 \
12781275
pathable==0.4.3 \
12791276
--hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \
12801277
--hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14
1281-
# via
1282-
# jsonschema-path
1283-
# jsonschema-spec
1278+
# via jsonschema-path
12841279
pexpect==4.9.0 \
12851280
--hash=sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523 \
12861281
--hash=sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f
@@ -1763,9 +1758,7 @@ pyyaml==6.0.1 \
17631758
--hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \
17641759
--hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \
17651760
--hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f
1766-
# via
1767-
# jsonschema-path
1768-
# jsonschema-spec
1761+
# via jsonschema-path
17691762
qrcode==7.4.2 \
17701763
--hash=sha256:581dca7a029bcb2deef5d01068e39093e80ef00b4a61098a2182eac59d01643a \
17711764
--hash=sha256:9dd969454827e127dbd93696b20747239e6d540e082937c90f14ac95b30f5845
@@ -1774,13 +1767,12 @@ redis==5.0.1 \
17741767
--hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \
17751768
--hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f
17761769
# via -r requirements/common.in
1777-
referencing==0.30.2 \
1778-
--hash=sha256:449b6669b6121a9e96a7f9e410b245d471e8d48964c67113ce9afe50c8dd7bdf \
1779-
--hash=sha256:794ad8003c65938edcdbc027f1933215e0d0ccc0291e3ce20a4d87432b59efc0
1770+
referencing==0.31.1 \
1771+
--hash=sha256:81a1471c68c9d5e3831c30ad1dd9815c45b558e596653db751a2bfdd17b3b9ec \
1772+
--hash=sha256:c19c4d006f1757e3dd75c4f784d38f8698d87b649c54f9ace14e5e8c9667c01d
17801773
# via
17811774
# jsonschema
17821775
# jsonschema-path
1783-
# jsonschema-spec
17841776
# jsonschema-specifications
17851777
regex==2023.12.25 \
17861778
--hash=sha256:0694219a1d54336fd0445ea382d49d36882415c0134ee1e8332afd1529f0baa5 \
@@ -1885,7 +1877,6 @@ requests[security]==2.31.0 \
18851877
# via
18861878
# -r requirements/common.in
18871879
# jsonschema-path
1888-
# jsonschema-spec
18891880
# pyoembed
18901881
# python-gcm
18911882
# python-twitter

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
# historical commits sharing the same major version, in which case a
4949
# minor version bump suffices.
5050

51-
PROVISION_VERSION = (260, 0)
51+
PROVISION_VERSION = (261, 0)

zerver/openapi/openapi.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
import re
1111
from typing import Any, Dict, List, Mapping, Optional, Set, Tuple, Union
1212

13-
import openapi_core
1413
import orjson
15-
from openapi_core import Spec
14+
from openapi_core import OpenAPI
1615
from openapi_core.testing import MockRequest, MockResponse
1716
from openapi_core.validation.exceptions import ValidationError as OpenAPIValidationError
1817

@@ -77,7 +76,7 @@ def __init__(self, openapi_path: str) -> None:
7776
self.mtime: Optional[float] = None
7877
self._openapi: Dict[str, Any] = {}
7978
self._endpoints_dict: Dict[str, str] = {}
80-
self._spec: Optional[Spec] = None
79+
self._spec: Optional[OpenAPI] = None
8180

8281
def check_reload(self) -> None:
8382
# Because importing yaml takes significant time, and we only
@@ -102,7 +101,7 @@ def check_reload(self) -> None:
102101

103102
openapi = yaml.load(f, Loader=yaml.CSafeLoader)
104103

105-
spec = Spec.from_dict(openapi)
104+
spec = OpenAPI.from_dict(openapi)
106105
self._spec = spec
107106
self._openapi = naively_merge_allOf_dict(JsonRef.replace_refs(openapi))
108107
self.create_endpoints_dict()
@@ -161,7 +160,7 @@ def endpoints_dict(self) -> Dict[str, str]:
161160
assert len(self._endpoints_dict) > 0
162161
return self._endpoints_dict
163162

164-
def spec(self) -> Spec:
163+
def spec(self) -> OpenAPI:
165164
"""Reload the OpenAPI file if it has been modified after the last time
166165
it was read, and then return the openapi_core validator object. Similar
167166
to preceding functions. Used for proper access to OpenAPI objects.
@@ -390,11 +389,11 @@ def validate_against_openapi_schema(
390389
mock_request = MockRequest("http://localhost:9991/", method, "/api/v1" + path)
391390
mock_response = MockResponse(
392391
# TODO: Use original response content instead of re-serializing it.
393-
orjson.dumps(content).decode(),
392+
orjson.dumps(content),
394393
status_code=int(status_code),
395394
)
396395
try:
397-
openapi_core.validate_response(mock_request, mock_response, spec=openapi_spec.spec())
396+
openapi_spec.spec().validate_response(mock_request, mock_response)
398397
except OpenAPIValidationError as error:
399398
message = f"Response validation error at {method} /api/v1{path} ({status_code}):"
400399
message += f"\n\n{type(error).__name__}: {error}"
@@ -490,7 +489,7 @@ def validate_request(
490489
"http://localhost:9991/", method, "/api/v1" + url, headers=http_headers, args=data
491490
)
492491
try:
493-
openapi_core.validate_request(mock_request, spec=openapi_spec.spec())
492+
openapi_spec.spec().validate_request(mock_request)
494493
except OpenAPIValidationError as error:
495494
# Show a block error message explaining the options for fixing it.
496495
msg = f"""

0 commit comments

Comments
 (0)