-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Master) Issue with namespaced Components #230
Comments
I think it would be good to have the same |
Yeah. This indeed is something worth thinking. @kellpossible Any takes on this? If there is something that could be improved regarding the namespacing? |
I think there's not really any other way, it seems like we do need something like the proposed As a side note, I'm not using the macro_rules! tag {
($name:literal, $description:literal) => {
utoipa::openapi::tag::TagBuilder::new()
.name($name)
.description(Some($description))
.build()
};
}
macro_rules! component {
($c:path) => {
(stringify!($c).replace("::", "."), <$c as utoipa::Component>::component())
};
}
pub struct ApiDoc;
impl OpenApi for ApiDoc {
fn openapi() -> utoipa::openapi::OpenApi {
let tags = vec![
tag!("mytag", "descrfiption"),
];
let components = vec![
component!(path::to::MyComponent),
];
let components = components
.into_iter()
.fold(ComponentsBuilder::new(), |acc, (name, component)| {
acc.schema(name, component) // this could be called acc.component() currently I think
})
.build();
OpenApiBuilder::new()
.info(InfoBuilder::new().title("my-service").build())
.paths(paths)
.components(Some(components))
.tags(Some(tags))
.build()
}
} My paths procedural macro (not included here) creates a warp filter with all the paths, and also generates the openapi paths at the same time with the same definition which is neat. I'm guessing |
@RemiKalbe Here's my version of the macro_rules! component {
($c:path) => {
(stringify!($c).replace("::", "."), <$c as utoipa::Component>::component())
};
($c:path as $p:path) => {
(stringify!($p).replace("::", "."), <$c as utoipa::Component>::component())
};
} Playground example (you can use the macro expansion tool to see what it does): |
Closing this issue due inactivity. This is related to this #435 (comment) and #459 where the behavior has been changed to be more clear. |
Say I have the following handler
And it is defined like so in the
OpenApiDoc
This will result in the following path in the spec
But, the component will not be named the same, there is no
response.
If I change my
OpenApiDoc
like so it solves the problemNot sure what's the best approach for this, but I think I should point that out.
The text was updated successfully, but these errors were encountered: