Skip to content
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

openapi: tag #335

Merged
merged 2 commits into from
Jan 27, 2025
Merged

openapi: tag #335

merged 2 commits into from
Jan 27, 2025

Conversation

kanarus
Copy link
Member

@kanarus kanarus commented Jan 27, 2025

Support tag in OpenAPI:

lib.rs

mod openapi {
...

    /// A fang to set OpenAPI tag for handlers of a `Ohkami`
    /// 
    /// ## note
    /// 
    /// * OpenAPI tags are inherited and stacked for child `Ohkami`s (if any).
    /// * This is a fang, but introduces NO runtime overhead.
    /// 
    /// ## example
    /// 
    /// ```ignore
    /// use ohkami::prelude::*;
    /// use ohkami::openapi;
    /// 
    /// #[tokio::main]
    /// async fn main() {
    ///     let users_ohkami = Ohkami::new((
    ///         openapi::Tag("users"),
    ///         "/"
    ///             .GET(list_users),
    ///             .POST(create_user),
    ///         "/:id"
    ///             .GET(get_user_profile),
    ///     ));
    ///     
    ///     Ohkami::new((
    ///         "/users".By(users_ohkami),
    ///         
    ///         // ...
    ///     )).howl("localhost:5050").await
    /// }
    /// # async fn list_users() {}
    /// # async fn create_user() {}
    /// # async fn get_user_profile() {}
    /// ```
    pub struct Tag(pub &'static str);
    impl<I: crate::FangProc> crate::Fang<I> for Tag {
        /// just pass `inner` through
        type Proc = I;
        fn chain(&self, inner: I) -> Self::Proc {inner}

        /// add tag for operations of `Ohkami` having this `Tag`
        fn openapi_map_operation(&self, operation: Operation) -> Operation {
            operation.with_tag(self.0)
        }
    }
}

@kanarus kanarus merged commit 21ab11a into v0.22 Jan 27, 2025
3 checks passed
@kanarus kanarus deleted the openapi/tag branch January 27, 2025 08:52
@kanarus kanarus mentioned this pull request Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant