diff --git a/src/lib.rs b/src/lib.rs index ff60998..5b9dc6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ struct FooResource; /// The return type of the foo read method. #[derive(Serialize)] -# #[derive(OpenapiType)] +# #[cfg_attr(feature = "openapi", derive(OpenapiType))] struct Foo { id: u64 } @@ -123,6 +123,8 @@ None of this is currently supported by gotham's own JWT middleware. A simple example that uses only a single secret could look like this: ```rust,no_run +# #[cfg(feature = "auth")] +# mod auth_feature_enabled { # #[macro_use] extern crate gotham_restful_derive; # use gotham::{router::builder::*, pipeline::{new_pipeline, single::single_pipeline}, state::State}; # use gotham_restful::*; @@ -132,7 +134,7 @@ A simple example that uses only a single secret could look like this: struct SecretResource; #[derive(Serialize)] -# #[derive(OpenapiType)] +# #[cfg_attr(feature = "openapi", derive(OpenapiType))] struct Secret { id: u64, intended_for: String @@ -161,6 +163,7 @@ fn main() { route.resource::("secret"); })); } +# } ``` ## Database Feature @@ -173,6 +176,8 @@ you'll need to borrow the connection from the [`State`] yourself and return a bo A simple non-async example could look like this: ```rust,no_run +# #[cfg(feature = "database")] +# mod database_feature_enabled { # #[macro_use] extern crate diesel; # #[macro_use] extern crate gotham_restful_derive; # use diesel::{table, PgConnection, QueryResult, RunQueryDsl}; @@ -192,7 +197,7 @@ A simple non-async example could look like this: struct FooResource; #[derive(Queryable, Serialize)] -# #[derive(OpenapiType)] +# #[cfg_attr(feature = "openapi", derive(OpenapiType))] struct Foo { id: i64, value: String @@ -214,6 +219,7 @@ fn main() { route.resource::("foo"); })); } +# } ``` # Examples diff --git a/src/result/auth_result.rs b/src/result/auth_result.rs index bbfbe56..5c54efc 100644 --- a/src/result/auth_result.rs +++ b/src/result/auth_result.rs @@ -21,9 +21,10 @@ This return type can be used to map another `ResourceResult` that can only be re client is authenticated. Otherwise, an empty _403 Forbidden_ response will be issued. Use can look something like this (assuming the `auth` feature is enabled): -``` +```rust +# #[cfg(feature = "auth")] +# mod auth_feature_enabled { # #[macro_use] extern crate gotham_restful_derive; -# mod doc_tests_are_broken { # use gotham::state::State; # use gotham_restful::*; # use serde::Deserialize; @@ -81,8 +82,9 @@ client is authenticated. Otherwise, an empty _403 Forbidden_ response will be is look something like this (assuming the `auth` feature is enabled): ``` +# #[cfg(feature = "auth")] +# mod auth_feature_enabled { # #[macro_use] extern crate gotham_restful_derive; -# mod doc_tests_are_broken { # use gotham::state::State; # use gotham_restful::*; # use serde::Deserialize; diff --git a/src/result/success.rs b/src/result/success.rs index f622f12..dffd740 100644 --- a/src/result/success.rs +++ b/src/result/success.rs @@ -29,7 +29,7 @@ Usage example: # struct MyResource; # #[derive(Deserialize, Serialize)] -# #[derive(OpenapiType)] +# #[cfg_attr(feature = "openapi", derive(OpenapiType))] struct MyResponse { message: &'static str }