Closed ctron closed 3 weeks ago
I came up with this:
pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, ui: &UiResources) {
config.service(NoSpecWrapper(
ResourceFiles::new("/", ui.resources()).resolve_not_found_to(""),
));
}
struct NoSpecWrapper<T: HttpServiceFactory>(pub T);
impl<T: HttpServiceFactory> HttpServiceFactory for NoSpecWrapper<T> {
fn register(self, config: &mut AppService) {
self.0.register(config);
}
}
impl<T: HttpServiceFactory> OpenApiFactory for NoSpecWrapper<T> {
fn paths(&self) -> utoipa::openapi::path::Paths {
Default::default()
}
fn schemas(
&self,
_schemas: &mut Vec<(
String,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
)>,
) {
Default::default()
}
}
Not sure that works, need to test. But I think this should be somehow part of the crate.
Yeah, I have totally ignored that it would be useful for ServiceConfig
to also have direct access to actix_web::web::ServiceConfig
:facepalm:
I shortly fix this with PR and make a release for it.
This PR #1174 Adds similar map
method for ServiceConfig
that is present in Scope
and UtoipaApp
which allows direct access to underlying actix_web type which in this case is actix_web::web::ServiceConfig
.
I am trying
utoipa_actix_web
withResourceFiles
, and to struggle a bit. Here is the snippet:I can't add
ResourceFiles
with service, because it doesn't implementOpenApiFactory
. Makes sense. But how do I work around this?It's ok to just leave this out of the OpenAPI spec.