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

Added mutable getter for the openapi instance of a OpenApiRouter #1262

Merged

Conversation

zannabianca1997
Copy link
Contributor

There is currently no way of changing the OpenApi without breaking the router apart and recomposing it.

This enables modification of the API while mounting the routes.

I encountered this limitation while trying to build a router, and add a common security before nesting the router inside another. This will enable code like this:

let mut router = OpenApiRouter::default()
    .routes(routes!(handler1))
    .routes(routes!(handler2));

RequireUserToken.modify(router.get_openapi_mut());

let outer_router = OpenApiRouter::default()
    .nest("/inner", router)

There is currently no way of changing the `OpenApi` without breaking the router apart and recomposing it.

This enables modification of the API while mounting the routes.
@zannabianca1997
Copy link
Contributor Author

This would also help with #1157. Most of the Router API is already accessible, this will enable access to the other half.

Another possibility would be to create a method that takes a type that implements Modify, but that would be a unnecessary restriction.

@zannabianca1997
Copy link
Contributor Author

I opened an issue, #1263

This closes #1263

@juhaku juhaku linked an issue Jan 2, 2025 that may be closed by this pull request
Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just missing a CHANGELOG.md entry from utoipa-axum/CHANGELOG.md. Add a new entry under Unreleased section (create if does not exists) and then add sub title Changed if does not exist then add the a bullet with * title (https://PR)

Added the entry relative to the changed code
@zannabianca1997
Copy link
Contributor Author

Must have missed it! Thank you for your time

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

@juhaku juhaku merged commit f09edbe into juhaku:master Jan 2, 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.

Add mutable getter for the openapi instance of a OpenApiRouter
2 participants