Skip to content

How to expose an openapi endpoint using utoipa #210

@rsansores

Description

@rsansores

All my endpoints are auto documented in a rapidoc platform thanks to utoipa actix crate. This one reads all the actix macros and generates the openapi definition automatically and expose rapidoc as an application.

To achieve that Utoipa takes an Actix App and then transform it into an Utoipa App that is made of two parts. The actual app and the rapidoc app.

This is the relevant code:

        let (app, mut api) = App::new()
            .into_utoipa_app() // This makes App into UtoipaApp
            .map(|app| {
                app.wrap(cors)
                    .wrap(TracingLogger::default())
                    .wrap(authorities)
            })
            .app_data(web::PayloadConfig::new(PAYLOAD_MAX_SIZE))
            .app_data(web::JsonConfig::default().limit(PAYLOAD_MAX_SIZE))
            .service(
                scope("/api").service(health).service(),
            )
            .split_for_parts();

        configure_openapi(&mut api);
        let rapidoc_service =
            RapiDoc::with_openapi(OPENAPI_SCHEMA_LOCATION, api).path(RAPIDOC_PATH);
        app.service(rapidoc_service)
    })
    .bind(format!("{}:{}", APP_BIND_ADDR, APP_PORT))
    .expect("We could not start the API server 💀")
    .workers(TOKIO_WORKERS)
    .run()
    .await;

Is there a way to map this kind of configuration into the ServiceConfig needed by Shuttle?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions