requirements: Upgrade to openapi-core pre-release.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-11-13 16:34:55 -08:00 committed by Anders Kaseorg
parent 41f253774d
commit d9f2f23c6a
5 changed files with 36 additions and 55 deletions

View File

@ -160,8 +160,7 @@ requests[security]
requests-oauthlib requests-oauthlib
# For OpenAPI schema validation. # For OpenAPI schema validation.
openapi-core 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
jsonschema-specifications<2023.11.1 # https://github.com/python-openapi/openapi-core/pull/686
importlib-resources ; python_version < "3.9" importlib-resources ; python_version < "3.9"
# For reporting errors to sentry.io # For reporting errors to sentry.io

View File

@ -1134,16 +1134,13 @@ jsonschema==4.21.1 \
jsonschema-path==0.3.2 \ jsonschema-path==0.3.2 \
--hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \ --hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \
--hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989 --hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989
# via openapi-spec-validator
jsonschema-spec==0.2.4 \
--hash=sha256:873e396ad1ba6edf9f52d6174c110d4fafb7b5f5894744246a53fe75e5251ec2 \
--hash=sha256:e6dcf7056734ec6854f7888da6c08ce6c421f28aeeddce96bb90de0fb6d711ef
# via openapi-core
jsonschema-specifications==2023.7.1 \
--hash=sha256:05adf340b659828a004220a9613be00fa3f223f2b82002e273dee62fd50524b1 \
--hash=sha256:c91a50404e88a1f6ba40636778e2ee08f6e24c5613fe4c53ac24578a5a7f72bb
# via # via
# -r requirements/common.in # openapi-core
# openapi-spec-validator
jsonschema-specifications==2023.12.1 \
--hash=sha256:48a76787b3e70f5ed53f1160d2b81f586e4ca6d1548c5de7085d1682674764cc \
--hash=sha256:87e4fdf3a94858b8a2ba2778d9ba57d8a9cafca7c7489c46ba0d30a8bc6a9c3c
# via
# jsonschema # jsonschema
# openapi-schema-validator # openapi-schema-validator
jsx-lexer==2.0.1 \ jsx-lexer==2.0.1 \
@ -1622,9 +1619,9 @@ oauthlib==3.2.2 \
# via # via
# requests-oauthlib # requests-oauthlib
# social-auth-core # social-auth-core
openapi-core==0.18.2 \ openapi-core==0.19.0a1 \
--hash=sha256:d4cc50f3ee03ae46313c83e97c6fbfe7e7ae9686741135eb0e4ed49e9d8ff08a \ --hash=sha256:3d339c12f0da2948b19d196203651592314fef4c7c9f88e0fa81bf47cc86deed \
--hash=sha256:ec13d366766d564450de60374f59feb0b5ccb447aed642cdf0f1ecfcc6fbe80a --hash=sha256:76414ebd43aea54a0f34c603ee986470293fe7bcde53fb74f4ba41a8f76746ac
# via -r requirements/common.in # via -r requirements/common.in
openapi-schema-validator==0.6.2 \ openapi-schema-validator==0.6.2 \
--hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \ --hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \
@ -1715,9 +1712,7 @@ parso==0.8.3 \
pathable==0.4.3 \ pathable==0.4.3 \
--hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \ --hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \
--hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14 --hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14
# via # via jsonschema-path
# jsonschema-path
# jsonschema-spec
pathspec==0.12.1 \ pathspec==0.12.1 \
--hash=sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08 \ --hash=sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08 \
--hash=sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712 --hash=sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712
@ -2291,7 +2286,6 @@ pyyaml==6.0.1 \
--hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f
# via # via
# jsonschema-path # jsonschema-path
# jsonschema-spec
# libcst # libcst
# moto # moto
# myst-parser # myst-parser
@ -2308,13 +2302,12 @@ redis==5.0.1 \
--hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \ --hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \
--hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f --hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f
# via -r requirements/common.in # via -r requirements/common.in
referencing==0.30.2 \ referencing==0.31.1 \
--hash=sha256:449b6669b6121a9e96a7f9e410b245d471e8d48964c67113ce9afe50c8dd7bdf \ --hash=sha256:81a1471c68c9d5e3831c30ad1dd9815c45b558e596653db751a2bfdd17b3b9ec \
--hash=sha256:794ad8003c65938edcdbc027f1933215e0d0ccc0291e3ce20a4d87432b59efc0 --hash=sha256:c19c4d006f1757e3dd75c4f784d38f8698d87b649c54f9ace14e5e8c9667c01d
# via # via
# jsonschema # jsonschema
# jsonschema-path # jsonschema-path
# jsonschema-spec
# jsonschema-specifications # jsonschema-specifications
# types-jsonschema # types-jsonschema
regex==2023.12.25 \ regex==2023.12.25 \
@ -2420,7 +2413,6 @@ requests[security]==2.31.0 \
# via # via
# -r requirements/common.in # -r requirements/common.in
# jsonschema-path # jsonschema-path
# jsonschema-spec
# moto # moto
# pyoembed # pyoembed
# python-digitalocean # python-digitalocean

View File

@ -884,16 +884,13 @@ jsonschema==4.21.1 \
jsonschema-path==0.3.2 \ jsonschema-path==0.3.2 \
--hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \ --hash=sha256:271aedfefcd161a0f467bdf23e1d9183691a61eaabf4b761046a914e369336c7 \
--hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989 --hash=sha256:4d0dababf341e36e9b91a5fb2a3e3fd300b0150e7fe88df4e55cc8253c5a3989
# via openapi-spec-validator
jsonschema-spec==0.2.4 \
--hash=sha256:873e396ad1ba6edf9f52d6174c110d4fafb7b5f5894744246a53fe75e5251ec2 \
--hash=sha256:e6dcf7056734ec6854f7888da6c08ce6c421f28aeeddce96bb90de0fb6d711ef
# via openapi-core
jsonschema-specifications==2023.7.1 \
--hash=sha256:05adf340b659828a004220a9613be00fa3f223f2b82002e273dee62fd50524b1 \
--hash=sha256:c91a50404e88a1f6ba40636778e2ee08f6e24c5613fe4c53ac24578a5a7f72bb
# via # via
# -r requirements/common.in # openapi-core
# openapi-spec-validator
jsonschema-specifications==2023.12.1 \
--hash=sha256:48a76787b3e70f5ed53f1160d2b81f586e4ca6d1548c5de7085d1682674764cc \
--hash=sha256:87e4fdf3a94858b8a2ba2778d9ba57d8a9cafca7c7489c46ba0d30a8bc6a9c3c
# via
# jsonschema # jsonschema
# openapi-schema-validator # openapi-schema-validator
jsx-lexer==2.0.1 \ jsx-lexer==2.0.1 \
@ -1201,9 +1198,9 @@ oauthlib==3.2.2 \
# via # via
# requests-oauthlib # requests-oauthlib
# social-auth-core # social-auth-core
openapi-core==0.18.2 \ openapi-core==0.19.0a1 \
--hash=sha256:d4cc50f3ee03ae46313c83e97c6fbfe7e7ae9686741135eb0e4ed49e9d8ff08a \ --hash=sha256:3d339c12f0da2948b19d196203651592314fef4c7c9f88e0fa81bf47cc86deed \
--hash=sha256:ec13d366766d564450de60374f59feb0b5ccb447aed642cdf0f1ecfcc6fbe80a --hash=sha256:76414ebd43aea54a0f34c603ee986470293fe7bcde53fb74f4ba41a8f76746ac
# via -r requirements/common.in # via -r requirements/common.in
openapi-schema-validator==0.6.2 \ openapi-schema-validator==0.6.2 \
--hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \ --hash=sha256:11a95c9c9017912964e3e5f2545a5b11c3814880681fcacfb73b1759bb4f2804 \
@ -1278,9 +1275,7 @@ parso==0.8.3 \
pathable==0.4.3 \ pathable==0.4.3 \
--hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \ --hash=sha256:5c869d315be50776cc8a993f3af43e0c60dc01506b399643f919034ebf4cdcab \
--hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14 --hash=sha256:cdd7b1f9d7d5c8b8d3315dbf5a86b2596053ae845f056f57d97c0eefff84da14
# via # via jsonschema-path
# jsonschema-path
# jsonschema-spec
pexpect==4.9.0 \ pexpect==4.9.0 \
--hash=sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523 \ --hash=sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523 \
--hash=sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f --hash=sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f
@ -1763,9 +1758,7 @@ pyyaml==6.0.1 \
--hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \ --hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \
--hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \ --hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \
--hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f
# via # via jsonschema-path
# jsonschema-path
# jsonschema-spec
qrcode==7.4.2 \ qrcode==7.4.2 \
--hash=sha256:581dca7a029bcb2deef5d01068e39093e80ef00b4a61098a2182eac59d01643a \ --hash=sha256:581dca7a029bcb2deef5d01068e39093e80ef00b4a61098a2182eac59d01643a \
--hash=sha256:9dd969454827e127dbd93696b20747239e6d540e082937c90f14ac95b30f5845 --hash=sha256:9dd969454827e127dbd93696b20747239e6d540e082937c90f14ac95b30f5845
@ -1774,13 +1767,12 @@ redis==5.0.1 \
--hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \ --hash=sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f \
--hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f --hash=sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f
# via -r requirements/common.in # via -r requirements/common.in
referencing==0.30.2 \ referencing==0.31.1 \
--hash=sha256:449b6669b6121a9e96a7f9e410b245d471e8d48964c67113ce9afe50c8dd7bdf \ --hash=sha256:81a1471c68c9d5e3831c30ad1dd9815c45b558e596653db751a2bfdd17b3b9ec \
--hash=sha256:794ad8003c65938edcdbc027f1933215e0d0ccc0291e3ce20a4d87432b59efc0 --hash=sha256:c19c4d006f1757e3dd75c4f784d38f8698d87b649c54f9ace14e5e8c9667c01d
# via # via
# jsonschema # jsonschema
# jsonschema-path # jsonschema-path
# jsonschema-spec
# jsonschema-specifications # jsonschema-specifications
regex==2023.12.25 \ regex==2023.12.25 \
--hash=sha256:0694219a1d54336fd0445ea382d49d36882415c0134ee1e8332afd1529f0baa5 \ --hash=sha256:0694219a1d54336fd0445ea382d49d36882415c0134ee1e8332afd1529f0baa5 \
@ -1885,7 +1877,6 @@ requests[security]==2.31.0 \
# via # via
# -r requirements/common.in # -r requirements/common.in
# jsonschema-path # jsonschema-path
# jsonschema-spec
# pyoembed # pyoembed
# python-gcm # python-gcm
# python-twitter # python-twitter

View File

@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 237
# historical commits sharing the same major version, in which case a # historical commits sharing the same major version, in which case a
# minor version bump suffices. # minor version bump suffices.
PROVISION_VERSION = (260, 0) PROVISION_VERSION = (261, 0)

View File

@ -10,9 +10,8 @@ import os
import re import re
from typing import Any, Dict, List, Mapping, Optional, Set, Tuple, Union from typing import Any, Dict, List, Mapping, Optional, Set, Tuple, Union
import openapi_core
import orjson import orjson
from openapi_core import Spec from openapi_core import OpenAPI
from openapi_core.testing import MockRequest, MockResponse from openapi_core.testing import MockRequest, MockResponse
from openapi_core.validation.exceptions import ValidationError as OpenAPIValidationError from openapi_core.validation.exceptions import ValidationError as OpenAPIValidationError
@ -77,7 +76,7 @@ class OpenAPISpec:
self.mtime: Optional[float] = None self.mtime: Optional[float] = None
self._openapi: Dict[str, Any] = {} self._openapi: Dict[str, Any] = {}
self._endpoints_dict: Dict[str, str] = {} self._endpoints_dict: Dict[str, str] = {}
self._spec: Optional[Spec] = None self._spec: Optional[OpenAPI] = None
def check_reload(self) -> None: def check_reload(self) -> None:
# Because importing yaml takes significant time, and we only # Because importing yaml takes significant time, and we only
@ -102,7 +101,7 @@ class OpenAPISpec:
openapi = yaml.load(f, Loader=yaml.CSafeLoader) openapi = yaml.load(f, Loader=yaml.CSafeLoader)
spec = Spec.from_dict(openapi) spec = OpenAPI.from_dict(openapi)
self._spec = spec self._spec = spec
self._openapi = naively_merge_allOf_dict(JsonRef.replace_refs(openapi)) self._openapi = naively_merge_allOf_dict(JsonRef.replace_refs(openapi))
self.create_endpoints_dict() self.create_endpoints_dict()
@ -161,7 +160,7 @@ class OpenAPISpec:
assert len(self._endpoints_dict) > 0 assert len(self._endpoints_dict) > 0
return self._endpoints_dict return self._endpoints_dict
def spec(self) -> Spec: def spec(self) -> OpenAPI:
"""Reload the OpenAPI file if it has been modified after the last time """Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects. to preceding functions. Used for proper access to OpenAPI objects.
@ -390,11 +389,11 @@ def validate_against_openapi_schema(
mock_request = MockRequest("http://localhost:9991/", method, "/api/v1" + path) mock_request = MockRequest("http://localhost:9991/", method, "/api/v1" + path)
mock_response = MockResponse( mock_response = MockResponse(
# TODO: Use original response content instead of re-serializing it. # TODO: Use original response content instead of re-serializing it.
orjson.dumps(content).decode(), orjson.dumps(content),
status_code=int(status_code), status_code=int(status_code),
) )
try: try:
openapi_core.validate_response(mock_request, mock_response, spec=openapi_spec.spec()) openapi_spec.spec().validate_response(mock_request, mock_response)
except OpenAPIValidationError as error: except OpenAPIValidationError as error:
message = f"Response validation error at {method} /api/v1{path} ({status_code}):" message = f"Response validation error at {method} /api/v1{path} ({status_code}):"
message += f"\n\n{type(error).__name__}: {error}" message += f"\n\n{type(error).__name__}: {error}"
@ -490,7 +489,7 @@ def validate_request(
"http://localhost:9991/", method, "/api/v1" + url, headers=http_headers, args=data "http://localhost:9991/", method, "/api/v1" + url, headers=http_headers, args=data
) )
try: try:
openapi_core.validate_request(mock_request, spec=openapi_spec.spec()) openapi_spec.spec().validate_request(mock_request)
except OpenAPIValidationError as error: except OpenAPIValidationError as error:
# Show a block error message explaining the options for fixing it. # Show a block error message explaining the options for fixing it.
msg = f""" msg = f"""