v2.4.4
- Add support for annotated types in
OpenAPIHandlerreturn types, by @tyzhnenko. This feature is important to support automatic generation of OpenAPI Documentation when returning instances ofResponse(e.g.Annotated[Response, ProductDetails]). - Introduce
MiddlewareListandMiddlewareCategoryto simplify middleware management and ordering of middlewares (see #620). Middlewares are now automatically sorted by category (INIT, SESSION, AUTH, AUTHZ, BUSINESS, MESSAGE) and optional priority within each category. This ensures proper execution order (e.g., CORS before authentication, authentication before authorization) without requiring developers to manually manage middleware insertion order. The system maintains backward compatibility while providing a more intuitive and error-resistant approach to middleware configuration. The same improvement is applied both to theApplicationand to theClientSessionclasses. - Add support for
list[str]as a value forno-cacheandprivatedirectives in code handling cache control headers, by @karpetrosyan. - Fix bug #619, that caused surprising behavior (requiring an explicit fallback or catch-all route to handle web requests that didn't match any route, otherwise middlewares would be bypassed for the defined
NotFoundexception handler). - Change the text of
Bad Requestresponse body when the input from the client causes aTypeErrorwhen trying to bind to an instance of the expected type (it reduces the amount of details sent to the client). - Improve the user experience by ignoring extra properties in request body by default, when mapping to user-defined dataclasses, Pydantic v2 models, or classes (see #614). Previously, extra properties were not ignored by default and required the user to explicitly code their input classes to allow extra properties. This is also done for sub-properties, lists, and dictionaries. The user can still control how exactly input bodies from clients are converted using custom binders or altering
blacksheep.server.bindings.class_converters. - Add support for specifying OpenAPI tags for controllers. This simplifies handling tags for documentation (#616).
- Improve the build matrix to build wheels for
arm64architecture for Linux and Windows, and usecibuildwheelfor Ubuntu and Windows, by @bymoye and @RobertoPrevato. - Update type annotations to Python >= 3.10.
- Fix bug that would prevent union types described using pipes from being properly represented in OpenAPI specification.
- Add support for alternative programming-style naming for generic types in OpenAPI specification files. When enabled, type names use underscore notation closer to actual type annotations (e.g.,
PaginatedSet_Addressinstead ofPaginatedSetOfAddress,Dict_str_intinstead ofDictOfstrAndint). This can be controlled via theprogramming_namesparameter inDefaultSerializeror theAPP_OPENAPI_PROGRAMMING_NAMESenvironment variable, setting it to a truthy value ('1' or 'true'). - Make
EnvironmentSettingsread-only, refactor to not usedataclass. - Attach
EnvironmentSettingsto theApplicationobject for runtime inspection, which is useful for: transparency and debugging, testing (assert app.env_settings.force_https is True), health check endpoints or admin tools can expose configuration. - Add
HTTPSchemeMiddlewareto set request scheme when running behind reverse proxies or load balancers with TLS termination. See #631. - Add support for
APP_HTTP_SCHEMEenvironment variable to explicitly set the request scheme tohttporhttps. - Add support for
APP_FORCE_HTTPSenvironment variable to force HTTPS scheme and automatically enable HSTS (HTTP Strict Transport Security) headers. - Add automatic scheme middleware configuration via
configure_scheme_middleware()- applied during application startup when eitherAPP_HTTP_SCHEMEorAPP_FORCE_HTTPSis set. EnvironmentSettingsnow includeshttp_schemeandforce_httpsproperties that are automatically populated from environment variables.- Request scheme is now automatically configured based on environment settings, to simplify correct URL generation in proxied environments (e.g. OIDC redirections).
- Improve the
generate_secretto usesecrets.token_urlsafe(48)by default. - Improve
OpenIDSettings,CookieAuthentication, andAntiForgeryHandlerto handle secrets using theSecretclass fromessentials.secrets. Passing secrets asstrdirectly issues a deprecation warning and won't be supported in2.5.xor2.6.x.
Several issues were reported by @ockan, including issues in the documentation.