Comments (8)
Just to make sure I understand it correctly:
- If a route has
#[deprecated]
currently#[openapi]
will generate a warning? And you want this warning to be removed? What is the exact warning? - The route should be marked as deprecated in the spec if
#[deprecated]
is used?
And regarding the respecting of the #[deprecated]
and reflecting it in the spec. I agree.
from okapi.
I just checked and #[deprecated]
is generating a warning on declaration, with or without #[openapi]
.
use rocket::{get, routes, Build, Rocket};
use rocket_okapi::openapi;
#[get("/")]
#[deprecated]
fn handler_without_docs() -> &'static str {
"ok"
}
#[openapi]
#[get("/")]
#[deprecated]
fn handler_with_docs() -> &'static str {
"ok"
}
#[rocket::launch]
#[allow(deprecated)]
fn launch() -> Rocket<Build> {
rocket::build()
.mount("/without_docs", routes![handler_without_docs])
.mount("/with_docs", routes![handler_with_docs])
}
Compiling okapi_test v0.1.0 (/Users/matt.donoughe/Documents/okapi_test)
warning: use of deprecated function `handler_without_docs`
--> src/main.rs:8:4
|
8 | fn handler_without_docs() -> &'static str {
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: use of deprecated function `handler_with_docs`
--> src/main.rs:17:4
|
17 | fn handler_with_docs() -> &'static str {
| ^^^^^^^^^^^^^^^^^
warning: `okapi_test` (bin "okapi_test") generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 2.08s
IMO it would be great if rocket_okapi
suppressed that warning. Adding #[allow(deprecated)]
to the function has no effect. If that's not possible, maybe #[openapi]
takes key value pairs for the different OpenAPI Operator properties so you can write #[openapi(deprecated = true)]
, among other things. Maybe that's good for other cases anyway, but it doesn't seem as natural as #[deprecated]
for the deprecation case. Maybe later Rocket can suppress that warning so it works nicely with #[openapi]
.
from okapi.
This warning has nothing to do with Rocket or Okapi. So there is noting we can do about it.
You can try:
#[rocket::launch]
fn launch() -> Rocket<Build> {
#[allow(deprecated)]
rocket::build()
.mount("/without_docs", routes![handler_without_docs])
.mount("/with_docs", routes![handler_with_docs])
}
But I'm not sure this will work.
Otherwise you can try adding #![allow(deprecated)]
tot the top of the file. But this is not really recommended.
There is a difference between depreciating a Rust function and deprecating an API endpoint.
At work I deprecate functions in the following way:
I add a note to the top of the endpoint description.
/// **NOTE: This endpoint is deprecated (since 2022/xx/xx) and will be removed at some point.**
And I log the use of function to see where it is still used:
log::error!("Calling of deprecated endpoint: `/endpoint/path`");
I know this is not ideal. But it is good enough as a temporary solution.
But using #[openapi(deprecated = true)]
might indeed be a better solution. The spec also supports this: https://spec.openapis.org/oas/v3.0.0#fixed-fields-7
from okapi.
The warning is emitted even if you don't mount the endpoint or otherwise use it in any way.
#![allow(unused)]
use rocket::{get, Build, Rocket};
use rocket_okapi::openapi;
#[get("/")]
#[deprecated]
fn handler_without_docs() -> &'static str {
"ok"
}
#[openapi]
#[get("/")]
#[deprecated]
fn handler_with_docs() -> &'static str {
"ok"
}
#[rocket::launch]
#[allow(deprecated)]
fn launch() -> Rocket<Build> {
rocket::build()
}
Actually using the handler does not produce any warnings:
use rocket::{get, Build, Rocket, routes};
use rocket_okapi::openapi;
#[allow(deprecated)]
mod handlers {
use super::*;
#[get("/")]
#[deprecated]
pub fn handler_without_docs() -> &'static str {
"ok"
}
#[openapi]
#[get("/")]
#[deprecated]
pub fn handler_with_docs() -> &'static str {
"ok"
}
}
#[rocket::launch]
#[allow(deprecated)]
fn launch() -> Rocket<Build> {
rocket::build()
.mount("/without_docs", routes![handlers::handler_without_docs])
.mount("/with_docs", routes![handlers::handler_with_docs])
}
I'm pretty sure #[get]
is defining a type which implements something like Into<Route>
and the warning is generated by that impl.
from okapi.
I'm pretty sure #[get] is defining a type which implements something like Into and the warning is generated by that impl.
Yeah the macro is using it internally somewhere. Strange that the handler thing changes that.
But other then #[openapi(deprecated = true)]
I don't see and immediate solution.
from okapi.
It might be possible for the #[openapi]
attribute to remove the #[deprecated]
attribute so Rocket doesn't see it, or wrap the Rocket-generated code in a module, but neither of those sound good, if they're even possible. I haven't tried to do anything like that in an attribute macro before.
Maybe Rocket can be convinced to change this as the current behavior doesn't seem useful at all.
I like both options. #[openapi(deprecated = true)]
is good to have even if later #[deprecated]
becomes an option, I think.
from okapi.
I created rwf2/Rocket#2262 for #[deprecated]
.
from okapi.
Thanks for following up on this issue and resolving it! Very nicely done! 🤩
from okapi.
Related Issues (20)
- openapi doesn't ignore Rocket request guards? HOT 2
- Build with latest commit failed HOT 2
- Add support for persist-auth HOT 2
- How to impl JsonSchema for chrono::DateTime<Utc> or other lib struct? HOT 1
- Publishing updated versions to crates.io HOT 2
- Incorrect openapi.json Generated for Response with Tuple HOT 2
- Enforce strict key values for BTreeMap with enum key HOT 5
- Unable to borrow value returned from definitions_mut() function HOT 1
- Update rocket dependency to v0.5.0-rc.4 HOT 2
- OpenAPI support for FromForm for MsgPack and TempFile
- (waiting for) Impl JsonSchema for Date/Time
- When 0.8 release HOT 5
- Add support for OpenAPI 3.1.0
- Nested routes? HOT 3
- How to specify image response content-type? HOT 1
- How to document handlers with rocket_oauth2 structs HOT 1
- [FEATURE]: Support for Validated<T> implementation . HOT 2
- Reference object and nullable HOT 1
- Derive OpenApiResponderInner for #[derive(Responder)] enums HOT 1
- Request guard, impl OpenApiFromRequest with Bearer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okapi.