Replies: 2 comments 1 reply
-
Great that the library has been useful :)
At the moment it is not possible to add
Features that are general purpose are all wecome PR:s. Yes the OpenAPI spec allows defining responses inside components but currently only schema components are supported. There is ongoing effort in making distinction between response and schema components thus allowing definition of other type of components within OpenAPI. See #215.
Method like above might be okay to add. And adding most commonly used utilities is not a bad thing. But with it need to be careful so that the api does not become polluted of things that not everybody will use. I'd like to keep the basic api as close as possible to the OpenAPI spec and other stuff would be additional extensions. These extras could be under a feature flag allowing users to decide whether they want to pay for the extras or not.
Sure API improvements are welcome and utility functions like above could be be added as extensions to the original types under a feature flag. As an example below. There could be a new feature flag # in Cargo.toml
[features]
openapi_extensions = [] #[cfg(feature = "openapi_extensions")]
trait RequestBodyBuilderExt {
fn json_component_ref(self, ref_name: &str) -> Self;
}
#[cfg(feature = "openapi_extensions")]
impl RequestBodyBuilderExt for RequestBodyBuilder {
fn json_component_ref(self, ref_name: &str) -> RequestBodyBuilder {
self.content(
"application/json",
utoipa::openapi::Content::new(utoipa::openapi::Ref::from_component_name(ref_name)),
)
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback @juhaku. I made a PR based on our discussion here. No rush on addressing it, of course, and I am happy to take any feedback or modify it as requested. |
Beta Was this translation helpful? Give feedback.
-
Hello! Thanks for building this library: I have been using it in a warp project at work and I wanted to say thanks for working on it!
I also wanted to mention two things I found when working with it.
OpenApi
directly, something like this:Question: Is it possible to add a
"servers"
block using theOpenApi
derive macro? I didn't see this in the docs anywhere.MyType::component()
to generate an array of component specs, but thepaths
are pretty involved to create. As a result, I made some convenience functions and traits to make it easier to add things that were useful for us. Here's a modified example:In this way, I could make a requestBody like this:
RequestBodyBuilder::new().json_component_ref("TokenPayload").build()
Questions:
from_response_name
(openapi allows definedresponses
inside components) for theRef
struct. Would that be something you would like to add to this project? (I'd be happy to contribute a PR to add this if so and it's welcome.)Path
objects.Overall, I prefer to build this opeapi spec on request (my schema is infrequently requested) or on application start as opposed to in macros, where I have it building at compile time, but I respect that other people wouldn't want that. At any rate, because of this perspective, I'd like to explore ways to improve the ergonomics of the runtime generation of specs.
Thanks again!
Beta Was this translation helpful? Give feedback.
All reactions