Skip to content

Auto collect schemas recursively from usages #1065

Closed
@juhaku

Description

@juhaku

Description

Currently all schemas need to be manually listed to the OpenApi via #[openapi(components(schemas(...)))] or manually by adding them directly to the OpenApi. While this is fine, it gets burdensome for large projects and is prone to errors and in reality is not feasible in long run.

Solution

Allow utoipa to automatically collect schemas recursively within types that implement ToSchema trait (by derive) and all usages e.g. when type implementing ToSchema is defined as a request body or response body.

This does not change the fact that still handlers need to manually added to the schema either via #[openapi(paths(...))] or by other means.

Tasks

  • Refactor request body parsing
  • Implement support for recursively generating schema references for types implementing ToSchema trait (via derive).
  • Implement support for recognizing recursive schemas from request body usage e.g. via #[utoipa::path(request_body = ...)] or from handler function argument for frameworks that supports request body auto recognition. These are actix_web axum and maybe rocket
  • Refactor response body parsing, and unify it with the request body parsing.
  • Implement support for recognizing recursive schemas from responses (tuples) maybe IntoResponses and ToResponse as well?
  • Implement automatic recursive schema addition to utoipa-axum (request_body and responses).

Closes #1025 Closes #465

Fixes #692

Relates #662 #591 #965 #779

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Released

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions