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

Add macro to simplify nesting route specs #138

Merged
merged 4 commits into from
Jan 14, 2024

Conversation

maximeborges
Copy link
Contributor

Proposition for #137

Example of usage:

let settings = OpenApiSettings::default();
let custom_route_spec = (vec![], custom_spec());
mount_endpoints_and_merged_docs! {
    building_rocket, "/v1".to_owned(), settings,
    "/" => custom_route_spec,
    "/api" => api::get_routes_and_docs(),
};

mod api {
    pub fn get_routes_and_docs(settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) {
        get_nested_endpoints_and_docs! {
            "/posts" => post::get_routes_and_docs(settings),
            "/message" => message::get_routes_and_docs(settings),
        }
    }
    mod posts {
        pub fn get_routes_and_docs(settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) {
            openapi_get_routes_spec![settings: create_post, get_post]
        }
    }
    mod messages {
        pub fn get_routes_and_docs(settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) {
            openapi_get_routes_spec![settings: create_message, get_message]
        }
    }
}

@ralpha
Copy link
Collaborator

ralpha commented Dec 17, 2023

Oh nice, that was quick. Looks good from a quick scan.
Will review and merge later.

@maximeborges
Copy link
Contributor Author

Ping just in case you missed the notification for new commits here.
No need to rush merging things ;)

@ralpha ralpha merged commit 8421dbd into GREsau:master Jan 14, 2024
1 check passed
@ralpha ralpha mentioned this pull request Jan 14, 2024
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.

2 participants