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 Generics to fn_name building to solve lifetimes issues #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ members = [
"examples/openapi_attributes",
"examples/raw_identifiers",
"examples/websocket",
"examples/lifetimes",
]
resolver = "2"
9 changes: 6 additions & 3 deletions examples/custom_schema/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "custom_schema"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
serde = "1.0"
serde_json = "1.0"
12 changes: 8 additions & 4 deletions examples/dyn_templates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[package]
name = "dyn_templates"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
schemars = { version = "0.8" }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc", "rocket_dyn_templates" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
"rocket_dyn_templates",
] }
serde = "1.0"
rocket_dyn_templates = { version = "=0.1.0", features = [ "handlebars" ] }
rocket_dyn_templates = { version = "=0.1.0", features = ["handlebars"] }
handlebars = "5.0.0"
9 changes: 6 additions & 3 deletions examples/json-web-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "json_web_api"
version = "0.1.0"
authors = [ "Graham Esau <[email protected]>" ]
authors = ["Graham Esau <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc" ] }
rocket = { version = "=0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
serde = "1.0"
13 changes: 13 additions & 0 deletions examples/lifetimes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "lifetimes"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
55 changes: 55 additions & 0 deletions examples/lifetimes/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use rocket::{Build, get, Rocket, State};
use rocket_okapi::{mount_endpoints_and_merged_docs, openapi, openapi_get_routes_spec};
use rocket_okapi::rapidoc::{GeneralConfig, HideShowConfig, make_rapidoc, RapiDocConfig};
use rocket_okapi::settings::{OpenApiSettings, UrlObject};
use rocket_okapi::swagger_ui::{make_swagger_ui, SwaggerUIConfig};

#[rocket::main]
async fn main() {
let launch_result = create_server().launch().await;
match launch_result {
Ok(_) => println!("Rocket shut down gracefully."),
Err(err) => println!("Rocket had an error: {}", err),
};
}

pub fn create_server() -> Rocket<Build> {
let mut building_rocket = rocket::build()
.mount(
"/swagger-ui/",
make_swagger_ui(&SwaggerUIConfig {
url: "../v1/openapi.json".to_owned(),
..Default::default()
}),
)
.mount(
"/rapidoc/",
make_rapidoc(&RapiDocConfig {
title: Some("My special documentation | RapiDoc".to_owned()),
general: GeneralConfig {
spec_urls: vec![UrlObject::new("General", "../v1/openapi.json")],
..Default::default()
},
hide_show: HideShowConfig {
allow_spec_url_load: false,
allow_spec_file_load: false,
..Default::default()
},
..Default::default()
}),
);


let (route, spec) = openapi_get_routes_spec![get_with_lifetimes];


building_rocket.manage(Test).mount("/v1",route).mount("/v1/", vec![rocket_okapi::handlers::OpenApiHandler::new(spec).into_route(OpenApiSettings::new().json_path)])
}

struct Test;

#[openapi]
#[get("/get/<val>")]
fn get_with_lifetimes<'a>(state: &'a State<Test>, val: bool) -> String {
val.to_string()
}
4 changes: 2 additions & 2 deletions examples/nested/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "rapidoc" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["rapidoc"] }
serde = "1.0"
serde_json = "1.0"
9 changes: 6 additions & 3 deletions examples/openapi_attributes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "openapi_attributes"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
serde = "1.0"
9 changes: 6 additions & 3 deletions examples/raw_identifiers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "raw_identifiers"
version = "0.1.0"
authors = [ "Alex Payne <[email protected]>" ]
authors = ["Alex Payne <[email protected]>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "rapidoc", "swagger" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"rapidoc",
"swagger",
] }
11 changes: 9 additions & 2 deletions examples/secure_request_guard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ authors = [
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json", "secrets" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "rapidoc", "swagger", "secrets" ] }
rocket = { version = "0.5.1", default-features = false, features = [
"json",
"secrets",
] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"rapidoc",
"swagger",
"secrets",
] }
serde = "1.0"
tokio = "1.6"
serde_json = "1.0"
9 changes: 6 additions & 3 deletions examples/special-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "special-types"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
serde = "1.0"
9 changes: 6 additions & 3 deletions examples/streams/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "streams"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
] }
serde = "1.0"
15 changes: 11 additions & 4 deletions examples/uuid_usage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ authors = [
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json", "uuid" ] }
schemars = { version = "0.8", features = [ "uuid1" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc", "uuid" ] }
rocket = { version = "=0.5.1", default-features = false, features = [
"json",
"uuid",
] }
schemars = { version = "0.8", features = ["uuid1"] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
"uuid",
] }
serde = "1.0"
uuid = { version = "1.1.1", features = [ "v4" ] }
uuid = { version = "1.1.1", features = ["v4"] }
10 changes: 7 additions & 3 deletions examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[package]
name = "websocket"
version = "0.1.0"
authors = [ "Ralph Bisschops <[email protected]>" ]
authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_ws = "0.1.0"
rocket_okapi = { path = "../../rocket-okapi", features = [ "swagger", "rapidoc", "rocket_ws" ] }
rocket_okapi = { path = "../../rocket-okapi", features = [
"swagger",
"rapidoc",
"rocket_ws",
] }
serde = "1.0"
8 changes: 4 additions & 4 deletions rocket-okapi-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name = "rocket_okapi_codegen"
description = "Macros supporting rocket_okapi"
repository = "https://github.com/GREsau/okapi"
version = "0.8.0"
authors = [ "Graham Esau <[email protected]>" ]
authors = ["Graham Esau <[email protected]>"]
edition = "2021"
license = "MIT"
readme = "../README.md"
keywords = [ "rust", "openapi", "swagger", "rocket" ]
categories = [ "web-programming" ]
keywords = ["rust", "openapi", "swagger", "rocket"]
categories = ["web-programming"]

[lib]
proc-macro = true

[dependencies]
rocket_http = { version = "=0.5.0" }
rocket_http = { version = "0.5.1" }
darling = "0.13"
syn = "1.0"
proc-macro2 = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion rocket-okapi-codegen/src/openapi_attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ fn create_route_operation_fn(
}

let fn_name = get_add_operation_fn_name(&route_fn.sig.ident);
let generics = route_fn.sig.generics;
let path = route
.origin
.path()
Expand Down Expand Up @@ -322,7 +323,7 @@ fn create_route_operation_fn(

TokenStream::from(quote! {
#[doc(hidden)]
pub fn #fn_name(
pub fn #fn_name #generics(
gen: &mut ::rocket_okapi::gen::OpenApiGenerator,
operation_id: String,
) -> ::rocket_okapi::Result<()> {
Expand Down
28 changes: 14 additions & 14 deletions rocket-okapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name = "rocket_okapi"
description = "OpenAPI (AKA Swagger) document generation for Rocket applications"
repository = "https://github.com/GREsau/okapi"
version = "0.8.0"
authors = [ "Graham Esau <[email protected]>" ]
authors = ["Graham Esau <[email protected]>"]
edition = "2021"
license = "MIT"
readme = "../README.md"
keywords = [ "rust", "openapi", "swagger", "rocket" ]
categories = [ "web-programming" ]
keywords = ["rust", "openapi", "swagger", "rocket"]
categories = ["web-programming"]

[dependencies]
rocket = { version = "=0.5.0", default-features = false, features = [ "json" ] }
rocket = { version = "=0.5.1", default-features = false, features = ["json"] }
schemars = { version = "0.8.16" }
okapi = { version = "0.7.0", path = "../okapi" }
rocket_okapi_codegen = { version = "=0.8.0", path = "../rocket-okapi-codegen" }
Expand All @@ -24,33 +24,33 @@ log = "0.4"
rocket_dyn_templates = { version = "=0.1.0", optional = true }
rocket_db_pools = { version = "=0.1.0", optional = true }
rocket_sync_db_pools = { version = "=0.1.0", optional = true }
rocket_ws = { version = "=0.1.0", optional = true }
rocket_ws = { version = "0.1.1", optional = true }

[dev-dependencies]
rocket_sync_db_pools = { version = "0.1.0", features = [ "diesel_sqlite_pool" ] }
rocket_sync_db_pools = { version = "0.1.0", features = ["diesel_sqlite_pool"] }

[features]
default = [ "preserve_order" ]
default = ["preserve_order"]

# Preserve the order of items in schema and other part of the OpenAPI documentation.
preserve_order = [ "schemars/preserve_order", "okapi/preserve_order" ]
preserve_order = ["schemars/preserve_order", "okapi/preserve_order"]
# Feature to enable Swagger UI for rendering documentation
# Project: https://github.com/swagger-api/swagger-ui
swagger = [ ]
swagger = []
# Feature to enable RapiDoc for rendering documentation
# Project: https://github.com/mrin9/RapiDoc
rapidoc = [ ]
rapidoc = []
# Allow the use of UUIDs
uuid = [ "rocket/uuid", "schemars/uuid" ]
uuid = ["rocket/uuid", "schemars/uuid"]
# Re-export Rocket feature flag
# https://docs.rs/rocket/latest/rocket/serde/msgpack/struct.MsgPack.html
msgpack = [ "rocket/msgpack" ]
msgpack = ["rocket/msgpack"]
# Re-export Rocket feature flag
# https://rocket.rs/v0.5/guide/requests/#secret-key
secrets = [ "rocket/secrets" ]
secrets = ["rocket/secrets"]
# Re-export Rocket feature flag
# https://rocket.rs/v0.5/guide/configuration/#mutual-tls
mtls = [ "rocket/mtls" ]
mtls = ["rocket/mtls"]

[package.metadata.docs.rs]
all-features = true