Internal API#

API documented here is not public, it can change at any time. Please, do not use it directly.

However, it is documented so people and LLMs can better understand the code.

Middleware wrappers#

class dmr.internal.middleware_wrapper.DecoratorWithResponses(*, decorator: _ClassDecorator, responses: list[ResponseSpec])[source]#

Type for decorator with responses attribute.

__call__(klass: _TypeT) → _TypeT[source]#

Apply the decorator to the class.

CSRF helpers#

dmr.internal.csrf.ensure_csrf(controller: Controller[BaseSerializer]) → None[source]#

Raise APIError (403) if the CSRF check fails.

Does not perform the second CSRF check if it was processed before. Since it uses the standard Django tooling, the default middleware checks csrf_processing_done which is set on each successful check.

Json backends#

class dmr.internal.json.JsonModule(*args, **kwargs)[source]#

Json module protocol.

This is how we use our json modules to parse / render data.

dumps(to_serialize: Any, /, default: Callable[[Any], Any] | None = None) → bytes[source]#

How data should be serialized.

loads(to_deserialize: Any, /) → Any[source]#

How data should be deserialized.

class dmr.internal.json.NativeJson[source]#

Native json module implementation.

classmethod dumps(to_serialize: Any, /, default: Callable[[Any], Any] | None = None) → bytes[source]#

Internal method to dump json to bytes.

classmethod loads(to_deserialize: str | Raw, /) → Any[source]#

Internal method to load json as a simple object.

Routing helpers#

final class dmr.internal.routing.RouterMetadata(*, tags: list[str], deprecated: bool, ignore_from_spec: bool)[source]#

Used to represent the metadata that we apply from router to all operations.

Must contain all the metadata fields from dmr.routing.Router.

Added in version 0.15.0.

classmethod from_included(router: Router, included: Self) → Self[source]#

Create metadata from included and including routers.

classmethod from_router(router: Router) → Self[source]#

Create metadata from router instance.

Typing helpers#

dmr.internal.types.StrOrPromise: TypeAlias = str | django.utils.functional.Promise#

Re-export of django-stubs internal value.