Go to file
Zixuan James Li f4caf9dd79 api: Add new typed_endpoint decorators.
The goal of typed_endpoint is to replicate most features supported by
has_request_variables, and to improve on top of it. There are some
unresolved issues that we don't plan to work on currently. For example,
typed_endpoint does not support ignored_parameters_supported for 400
responses, and it does not run validators on path-only arguments.

Unlike has_request_variables, typed_endpoint supports error handling by
processing validation errors from Pydantic.

Most features supported by has_request_variables are supported by
typed_endpoint in various ways.

To define a function, use a syntax like this with Annotated if there is
any metadata you want to associate with a parameter, do note that
parameters that are not keyword-only are ignored from the request:
```
@typed_endpoint
def view(
    request: HttpRequest,
    user_profile: UserProfile,
    *,
    foo: Annotated[int, ApiParamConfig(path_only=True)],
    bar: Json[int],
    other: Annotated[
        Json[int],
        ApiParamConfig(
            whence="lorem",
            documentation_status=NTENTIONALLY_UNDOCUMENTED
        )
    ] = 10,
) -> HttpResponse:
    ....
```

There are also some shorthands for the commonly used annotated types,
which are encouraged when applicable for better readability and less
typing:
```
WebhookPayload = Annotated[Json[T], ApiParamConfig(argument_type_is_body=True)]
PathOnly = Annotated[T, ApiParamConfig(path_only=True)]
```

Then the view function above can be rewritten as:
```
@typed_endpoint
def view(
    request: HttpRequest,
    user_profile: UserProfile,
    *,
    foo: PathOnly[int],
    bar: Json[int],
    other: Annotated[
        Json[int],
        ApiParamConfig(
            whence="lorem",
            documentation_status=INTENTIONALLY_UNDOCUMENTED
        )
    ] = 10,
) -> HttpResponse:
    ....
```

There are some intentional restrictions:
- A single parameter cannot have more than one ApiParamConfig
- Path-only parameters cannot have default values
- argument_type_is_body is incompatible with whence
- Arguments of name "request", "user_profile", "args", and "kwargs" and
  etc. are ignored by typed_endpoint.
- positional-only arguments are not supported by typed_endpoint. Only
  keyword-only parameters are expected to be parsed from the request.
- Pydantic's strict mode is always enabled, because we don't want to
  coerce input parsed from JSON into other types unnecessarily.
- Using strict mode all the time also means that we should always use
  Json[int] instead of int, because it is only possible for the request
  to have data of type str, and a type annotation of int will always
  reject such data.

typed_endpoint's handling of ignored_parameters_unsupported is mostly
identical to that of has_request_variables.
2023-09-08 08:20:17 -07:00
.github user_groups: Make locks required for updating user group memberships. 2023-08-24 17:21:08 -07:00
.tx provision: Replace transifex-client with new transifex-cli. 2022-12-13 12:34:08 -08:00
.vscode vscode: Recommend remote development extension. 2021-11-03 16:03:46 -07:00
analytics mypy: Upgrade mypy from 1.4.1 to 1.5.1. 2023-09-07 17:51:42 -07:00
api_docs events: Send invites changes event to non-admin users also. 2023-09-07 14:21:01 -07:00
confirmation python: Annotate type aliases with TypeAlias. 2023-08-07 10:02:49 -07:00
corporate billing: Rename a few confusing references to "Zulip Limited". 2023-09-07 17:52:04 -07:00
docs docs: Fix typos caught by ‘typos’. 2023-09-06 18:59:05 -07:00
help help: Document "Add subscribers" mobile feature. 2023-09-08 08:08:06 -07:00
locale i18n: Update translation data from Transifex. 2023-07-25 21:12:09 -07:00
pgroonga migrations: Import BaseDatabaseSchemaEditor from its canonical module. 2023-03-05 14:46:28 -08:00
puppet postgres_exporter: Explicitly specify the zulip database. 2023-09-06 09:20:57 -07:00
requirements requirements: Add pydantic and configure mypy plugin. 2023-09-08 08:20:17 -07:00
scripts ruff: Fix PIE808 Unnecessary `start` argument in `range`. 2023-09-01 14:57:01 -07:00
static help: Add mobile instructions to "Unsubscribe from a stream". 2023-08-30 11:30:53 -07:00
stubs/taint actions: Split out zerver.actions.message_send. 2022-04-14 17:14:34 -07:00
templates recent: Rename #recent_topics_loading_messages_indicator. 2023-09-08 07:36:33 -07:00
tools api: Add new typed_endpoint decorators. 2023-09-08 08:20:17 -07:00
var/puppeteer puppeteer_tests: Port to TypeScript. 2021-02-22 16:03:10 -08:00
web recent: Rename recent_topics test file. 2023-09-08 07:36:33 -07:00
zerver api: Add new typed_endpoint decorators. 2023-09-08 08:20:17 -07:00
zilencer mypy: Upgrade mypy from 1.4.1 to 1.5.1. 2023-09-07 17:51:42 -07:00
zproject transaction_tests: Remove testing URL. 2023-09-06 09:13:02 -07:00
.codecov.yml
.codespellignore codespell: Fix newly found typos. 2023-04-03 22:39:21 -07:00
.editorconfig editorconfig: Restore indent_size = 2 for Markdown. 2021-08-20 23:14:37 -07:00
.eslintignore web: Move web app to ‘web’ directory. 2023-02-23 16:04:17 -08:00
.eslintrc.json eslint: Follow @typescript-eslint/no-parameter-properties rule rename. 2023-07-21 15:58:42 -07:00
.gitattributes .gitattributes: Mark *.bmp, *.bson, *.mp3, *.pdf as binary. 2022-02-07 18:51:06 -08:00
.gitignore dependencies: Switch to pnpm. 2023-03-20 15:48:29 -07:00
.gitlint lint: Update line-length for commit message to 72 in gitlint. 2023-05-01 10:35:52 -07:00
.mailmap mailmap: Put sorted list back in order. 2023-08-02 17:19:05 -07:00
.npmignore
.npmrc dependencies: Switch to pnpm. 2023-03-20 15:48:29 -07:00
.prettierignore dependencies: Switch to pnpm. 2023-03-20 15:48:29 -07:00
.pyre_configuration pysa: Update .pyre_configuration to point to typeshed. 2020-09-22 15:44:47 -07:00
.readthedocs.yaml readthedocs: Add a configuration file. 2023-02-03 16:36:54 -08:00
.sonarcloud.properties
CODE_OF_CONDUCT.md docs: Rename "private message" -> "direct message". 2023-06-23 14:36:16 -07:00
CONTRIBUTING.md docs: Link to new guide on suggesting features and improvements. 2023-06-12 17:05:42 -07:00
Dockerfile-postgresql docker: Document the PostgreSQL Dockerfile build steps. 2022-04-26 18:00:00 -07:00
LICENSE license: Move copyright notice from LICENSE to NOTICE. 2021-02-05 09:28:12 -08:00
NOTICE docs: Bump copyright year. 2021-02-05 09:28:15 -08:00
README.md README: Update Ruff badge. 2023-03-21 11:46:20 -07:00
SECURITY.md docs: Update .html links pointing to "Upgrade Zulip" or "Modify Zulip". 2023-08-11 16:49:32 -07:00
Vagrantfile vagrant: Add Fedora 36 support. 2022-09-08 16:12:59 -07:00
manage.py ruff: Fix PERF401 Use a list comprehension to create a transformed list. 2023-08-07 17:23:55 -07:00
package.json dependencies: Upgrade JavaScript dependencies. 2023-08-17 18:16:47 -07:00
pnpm-lock.yaml dependencies: Upgrade JavaScript dependencies. 2023-08-17 18:16:47 -07:00
prettier.config.js prettier: Disable embedded language formatting for Markdown. 2021-08-20 23:14:37 -07:00
pyproject.toml requirements: Add pydantic and configure mypy plugin. 2023-09-08 08:20:17 -07:00
stylelint.config.js dependencies: Upgrade JavaScript dependencies. 2023-07-21 15:58:42 -07:00
tsconfig.json dependencies: Install `@types/jquery.validation for type annotation. 2023-08-14 16:00:20 -07:00
version.py requirements: Add pydantic and configure mypy plugin. 2023-09-08 08:20:17 -07:00

README.md

Zulip overview

Zulip is an open-source team collaboration tool with unique topic-based threading that combines the best of email and chat to make remote work productive and delightful. Fortune 500 companies, leading open source projects, and thousands of other organizations use Zulip every day. Zulip is the only modern team chat app that is designed for both live and asynchronous conversations.

Zulip is built by a distributed community of developers from all around the world, with 74+ people who have each contributed 100+ commits. With over 1000 contributors merging over 500 commits a month, Zulip is the largest and fastest growing open source team chat project.

Come find us on the development community chat!

GitHub Actions build status coverage status Mypy coverage Ruff code style: black code style: prettier GitHub release docs Zulip chat Twitter GitHub Sponsors

Getting started

You may also be interested in reading our blog, and following us on Twitter and LinkedIn.

Zulip is distributed under the Apache 2.0 license.