mirror of https://github.com/zulip/zulip.git
9c53995830
This demonstrates some basic use cases of the Json[...] wrapper with @typed_endpoint. Along with this change we extend test_openapi so that schema checking based on function signatures will still work with this new decorator. Pydantic's TypeAdapter supports dumping the JSON schema of any given type, which is leveraged here to validate against our own OpenAPI definitions. Parts of the implementation will be covered in later commits as we migrate more functions to use @typed_endpoint. See also: https://docs.pydantic.dev/latest/api/type_adapter/#pydantic.type_adapter.TypeAdapter.json_schema For the OpenAPI schema, we preprocess it mostly the same way. For the parameter types though, we no longer need to use get_standardized_argument_type to normalize type annotation, because Pydantic dumps a JSON schema that is compliant with OpenAPI schema already, which makes it a lot convenient for us to compare the types with our OpenAPI definitions. Do note that there are some exceptions where our definitions do not match the generated one. For example, we use JSON to parse int and bool parameters, but we don't mark them to use "application/json" in our definitions. |
||
---|---|---|
.. | ||
actions | ||
data_import | ||
integration_fixtures/nagios | ||
lib | ||
management | ||
migrations | ||
openapi | ||
tests | ||
tornado | ||
transaction_tests | ||
views | ||
webhooks | ||
worker | ||
__init__.py | ||
apps.py | ||
context_processors.py | ||
decorator.py | ||
filters.py | ||
forms.py | ||
logging_handlers.py | ||
middleware.py | ||
models.py | ||
signals.py |