Skip to content

Commit

Permalink
Update rocket_db_pools to 0.2 and documentation versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ralpha committed Nov 7, 2024
1 parent 96a65fb commit bea7b69
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 13 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contribute to this project

In this document are some instructions that might help you contribute to this project.

Main maintainers:
- [@Ralpha](https://github.com/ralpha)
- [@GREsau](https://github.com/GREsau)

## Error while testing
If you run the tests `cargo test` and get the error:
```
= note: /usr/bin/ld: cannot find -lsqlite3: No such file or directory
collect2: error: ld returned 1 exit status
error: could not compile `rocket_okapi` (test "db_pool") due to 1 previous error
```
You need to install `libsqlite3-dev`. You can do this using your package manager.
```bash
sudo apt install libsqlite3-dev
```
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ rocket = { version = "=0.5.1", default-features = false, features = ["json"] }
rocket_ws = "0.1.1"
rocket_http = "=0.5.1"
rocket_dyn_templates = "=0.2.0"
rocket_db_pools = "=0.1.0"
rocket_db_pools = "=0.2.0"
rocket_sync_db_pools = "=0.1.0"
schemars = "0.8"
serde = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ visualize the documentation. Rocket-okapi currently includes [RapiDoc][RapiDoc]
[Swagger UI][Swagger_UI], but others can be used too.

Supported OpenAPI Spec: [3.0.0][OpenAPI_3.0.0]<br/>
Supported Rocket version (for `rocket_okapi`): [0.5.0](https://crates.io/crates/rocket/0.5.0)
Supported Rocket version (for `rocket_okapi`): [0.5.1](https://crates.io/crates/rocket/0.5.1)

Example of generated documentation using Okapi:
- DF Storyteller: [RapiDoc](https://docs.dfstoryteller.com/rapidoc/),
Expand Down Expand Up @@ -163,15 +163,15 @@ two [`OpenAPI`](https://docs.rs/okapi/latest/okapi/openapi3/struct.OpenApi.html)
This crate can be reused to create OpenAPI support in other web framework.

`Rocket-Okapi` crate contains all the code for generating the OpenAPI file and serve it once created.
This code is usually executed using macro's like: [`mount_endpoints_and_merged_docs!{...}`,
This code is usually executed using macro's like: [`mount_endpoints_and_merged_docs!{...}`,
`openapi_get_routes![...]`, `openapi_get_routes_spec![...]` and `openapi_get_spec![...]`
](https://docs.rs/rocket_okapi/latest/rocket_okapi/#macros).

When the Rocket server is started (or wherever macro is placed) the OpenAPI file is generated once.
This file/structure is then stored in memory and will be served when requested.

The `Rocket-Okapi-codegen` crate contains code for
[derive macros](https://doc.rust-lang.org/book/ch19-06-macros.html).
[derive macros](https://doc.rust-lang.org/book/ch19-06-macros.html).
`#[openapi]`, `rocket_okapi::openapi_spec![...]`, `rocket_okapi::openapi_routes![...]`
and `#[derive(OpenApiFromRequest)]` in our case.
This needs to be in a separate crate because of Rust restrictions.
Expand Down
4 changes: 2 additions & 2 deletions rocket-okapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! First, add the following lines to your `Cargo.toml`
//! ```toml
//! [dependencies]
//! rocket = { version = "0.5.0", default-features = false, features = ["json"] }
//! rocket = { version = "0.5.1", default-features = false, features = ["json"] }
//! schemars = "0.8.16"
//! okapi = { version = "0.7.0" }
//! rocket_okapi = { version = "0.8.0", features = ["swagger"] }
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn get_openapi_route(
/// The macro expects the following arguments:
/// - rocket_builder: `Rocket<Build>`,
/// - base_path: `&str`, `String` or [`Uri`](rocket::http::uri::Uri). (Anything that implements `ToString`)
/// Anything accepted by [`mount()`](https://docs.rs/rocket/0.5.0/rocket/struct.Rocket.html#method.mount)
/// Anything accepted by [`mount()`](https://docs.rs/rocket/0.5.1/rocket/struct.Rocket.html#method.mount)
/// - openapi_settings: `OpenApiSettings` (use `OpenApiSettings::default()` if default settings are okay for you),
/// - List of (0 or more):
/// - path: `&str`, `String` or [`Uri`](rocket::http::uri::Uri).
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/request/from_data_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ macro_rules! fn_request_body {

// Implement `OpenApiFromData` for everything that implements `FromData`
// Order is same as on:
// https://docs.rs/rocket/0.5.0/rocket/data/trait.FromData.html#foreign-impls
// https://docs.rs/rocket/0.5.1/rocket/data/trait.FromData.html#foreign-impls

// ## Implementations on Foreign Types

Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/request/from_form_param_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Implement `OpenApiFromForm` for everything that implements `FromForm`
//! <https://docs.rs/rocket/0.5.0/rocket/form/trait.FromForm.html#foreign-impls>
//! <https://docs.rs/rocket/latest/rocket/form/trait.FromForm.html#foreign-impls>
use super::{get_nested_form_parameters, OpenApiFromForm, OpenApiFromFormField};
use crate::gen::OpenApiGenerator;
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/request/from_param_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Implement `OpenApiFromParam` for everything that implements `FromParam`
//! <https://docs.rs/rocket/0.5.0/rocket/request/trait.FromParam.html#foreign-impls>
//! <https://docs.rs/rocket/latest/rocket/request/trait.FromParam.html#foreign-impls>
use super::OpenApiFromParam;
use crate::gen::OpenApiGenerator;
Expand Down
10 changes: 8 additions & 2 deletions rocket-okapi/src/request/from_request_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::result::Result as StdResult;

// Implement `OpenApiFromRequest` for everything that implements `FromRequest`
// Order is same as on:
// https://docs.rs/rocket/0.5.0/rocket/request/trait.FromRequest.html#foreign-impls
// https://docs.rs/rocket/0.5.1/rocket/request/trait.FromRequest.html#foreign-impls
// https://api.rocket.rs/v0.5/rocket/request/trait.FromRequest.html#foreign-impls

type Result = crate::Result<RequestHeaderInput>;
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'r, T: OpenApiFromRequest<'r>> OpenApiFromRequest<'r>
}

// ## Implementations for other crates
// https://docs.rs/rocket_db_pools/0.1.0/rocket_db_pools/struct.Connection.html#impl-FromRequest%3C%27r%3E
// https://docs.rs/rocket_db_pools/latest/rocket_db_pools/struct.Connection.html#impl-FromRequest%3C'r%3E-for-Connection%3CD%3E

#[cfg(feature = "rocket_db_pools")]
impl<'r, D: rocket_db_pools::Database> OpenApiFromRequest<'r> for rocket_db_pools::Connection<D> {
Expand All @@ -193,20 +193,26 @@ impl<'r, D: rocket_db_pools::Database> OpenApiFromRequest<'r> for rocket_db_pool
}
}

// https://docs.rs/rocket_dyn_templates/latest/rocket_dyn_templates/struct.Metadata.html#impl-FromRequest%3C'r%3E-for-Metadata%3C'r%3E

#[cfg(feature = "rocket_dyn_templates")]
impl<'r> OpenApiFromRequest<'r> for rocket_dyn_templates::Metadata<'r> {
fn from_request_input(_gen: &mut OpenApiGenerator, _name: String, _required: bool) -> Result {
Ok(RequestHeaderInput::None)
}
}

// https://docs.rs/rocket_sync_db_pools/latest/rocket_sync_db_pools/example/struct.ExampleDb.html#impl-FromRequest%3C'r%3E-for-ExampleDb

#[cfg(feature = "rocket_sync_db_pools")]
impl<'r> OpenApiFromRequest<'r> for rocket_sync_db_pools::example::ExampleDb {
fn from_request_input(_gen: &mut OpenApiGenerator, _name: String, _required: bool) -> Result {
Ok(RequestHeaderInput::None)
}
}

// https://docs.rs/rocket_ws/latest/rocket_ws/struct.WebSocket.html#impl-FromRequest%3C'r%3E-for-WebSocket

#[cfg(feature = "rocket_ws")]
impl<'r> OpenApiFromRequest<'r> for rocket_ws::WebSocket {
fn from_request_input(_gen: &mut OpenApiGenerator, _name: String, _required: bool) -> Result {
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/request/from_segments_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Implement `OpenApiFromSegments` for everything that implements `FromSegments`
//! <https://docs.rs/rocket/0.5.0/rocket/request/trait.FromSegments.html#foreign-impls>
//! <https://docs.rs/rocket/latest/rocket/request/trait.FromSegments.html#foreign-impls>
use super::OpenApiFromSegments;
use crate::gen::OpenApiGenerator;
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi/src/response/responder_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Result = crate::Result<Responses>;

// Implement `OpenApiResponderInner` for everything that implements `Responder`
// Order is same as on:
// https://docs.rs/rocket/0.5.0/rocket/response/trait.Responder.html#foreign-impls
// https://docs.rs/rocket/0.5.1/rocket/response/trait.Responder.html#foreign-impls

// ## Implementations on Foreign Types

Expand Down

0 comments on commit bea7b69

Please sign in to comment.