Skip to content

Commit

Permalink
build: update to openapiv3
Browse files Browse the repository at this point in the history
There's a breaking change on the crate which does not expose the fields as pub
and so we need to use our own patch for now.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Jun 30, 2024
1 parent b20eeab commit 1a9c3ec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[patch.crates-io]
openapiv3 = { git = "https://github.com/paperclip-rs/openapiv3.git", branch = "oauth2flow" }

[package]
name = "paperclip"
version = "0.9.0"
Expand Down Expand Up @@ -40,7 +43,7 @@ url_dep = { version = ">=1.7,<3", package = "url" }
thiserror = "1.0"
anyhow = "1.0"
once_cell = "1.4"
openapiv3 = { version = "1.0.3", optional = true }
openapiv3 = { version = "2.0", optional = true }

[dev-dependencies]
actix-rt1 = { version = "1.0", package = "actix-rt" }
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ actix-web-validator2 = { version = "2.2", optional = true, package = "actix-web-
actix-web-validator3 = { version = "3.0", optional = true, package = "actix-web-validator" }
validator12 = { version = "0.12", features = ["derive"], optional = true, package = "validator" }
validator14 = { version = "0.14", features = ["derive"], optional = true, package = "validator" }
openapiv3 = { version = "1.0.3", optional = true }
openapiv3 = { version = "2.0", optional = true }

[features]
# actix-web support
Expand Down
1 change: 1 addition & 0 deletions core/src/v3/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl From<v2::Operation<v2::DefaultParameterRaw, v2::DefaultResponseRaw>> for op
},
servers: vec![],
extensions: Default::default(),
callbacks: Default::default(),
}
}
}
4 changes: 3 additions & 1 deletion core/src/v3/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ pub(crate) fn non_body_parameter_to_v3_parameter(
max_length: v2.max_length.map(|v| v as usize),
}))
}
v2::DataType::Boolean => openapiv3::SchemaKind::Type(openapiv3::Type::Boolean {}),
v2::DataType::Boolean => {
openapiv3::SchemaKind::Type(openapiv3::Type::Boolean(Default::default()))
}
v2::DataType::Array => {
openapiv3::SchemaKind::Type(openapiv3::Type::Array(openapiv3::ArrayType {
items: v2.items.as_ref().map(|items| items.clone().into()),
Expand Down
8 changes: 6 additions & 2 deletions core/src/v3/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ fn v2_data_type_to_v3(
max_length: None,
}))
}
v2::DataType::Boolean => openapiv3::SchemaKind::Type(openapiv3::Type::Boolean {}),
v2::DataType::Boolean => {
openapiv3::SchemaKind::Type(openapiv3::Type::Boolean(Default::default()))
}
v2::DataType::Array => {
openapiv3::SchemaKind::Type(openapiv3::Type::Array(openapiv3::ArrayType {
items: items.as_ref().map(|items| items.deref().clone().into()),
Expand Down Expand Up @@ -323,7 +325,9 @@ impl From<v2::Items> for openapiv3::ReferenceOr<Box<openapiv3::Schema>> {
max_length: v2.max_length.map(|v| v as usize),
}))
}
v2::DataType::Boolean => openapiv3::SchemaKind::Type(openapiv3::Type::Boolean {}),
v2::DataType::Boolean => {
openapiv3::SchemaKind::Type(openapiv3::Type::Boolean(Default::default()))
}
v2::DataType::Array => {
openapiv3::SchemaKind::Type(openapiv3::Type::Array(openapiv3::ArrayType {
items: v2.items.map(|items| items.deref().clone().into()),
Expand Down
17 changes: 13 additions & 4 deletions core/src/v3/security_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl From<v2::SecurityScheme> for openapiv3::SecurityScheme {
scheme: "basic".to_string(),
bearer_format: None,
description: v2.description,
extensions: Default::default(),
},
"apiKey" => openapiv3::SecurityScheme::APIKey {
location: match v2.in_.unwrap_or_default().as_str() {
Expand All @@ -25,46 +26,53 @@ impl From<v2::SecurityScheme> for openapiv3::SecurityScheme {
},
name: v2.name.unwrap_or_default(),
description: v2.description,
extensions: Default::default(),
},
"oauth2" => {
let flow = v2.flow.unwrap_or_default();
openapiv3::SecurityScheme::OAuth2 {
flows: openapiv3::OAuth2Flows {
implicit: match flow.as_str() {
"implicit" => Some(openapiv3::OAuth2Flow::Implicit {
"implicit" => Some(openapiv3::ImplicitOAuth2Flow {
authorization_url: v2.auth_url.clone().unwrap_or_default(),
refresh_url: None,
scopes: to_indexmap!(v2),
extensions: Default::default(),
}),
_ => None,
},
password: match flow.as_str() {
"password" => Some(openapiv3::OAuth2Flow::Password {
"password" => Some(openapiv3::PasswordOAuth2Flow {
refresh_url: None,
token_url: v2.token_url.clone().unwrap_or_default(),
scopes: to_indexmap!(v2),
extensions: Default::default(),
}),
_ => None,
},
client_credentials: match flow.as_str() {
"application" => Some(openapiv3::OAuth2Flow::ClientCredentials {
"application" => Some(openapiv3::ClientCredentialsOAuth2Flow {
refresh_url: None,
token_url: v2.token_url.clone().unwrap_or_default(),
scopes: to_indexmap!(v2),
extensions: Default::default(),
}),
_ => None,
},
authorization_code: match flow.as_str() {
"accessCode" => Some(openapiv3::OAuth2Flow::AuthorizationCode {
"accessCode" => Some(openapiv3::AuthorizationCodeOAuth2Flow {
authorization_url: v2.auth_url.clone().unwrap_or_default(),
token_url: v2.token_url.clone().unwrap_or_default(),
refresh_url: None,
scopes: to_indexmap!(v2),
extensions: Default::default(),
}),
_ => None,
},
extensions: Default::default(),
},
description: v2.description,
extensions: Default::default(),
}
}
type_ => {
Expand All @@ -73,6 +81,7 @@ impl From<v2::SecurityScheme> for openapiv3::SecurityScheme {
scheme: "invalid".to_string(),
bearer_format: None,
description: v2.description,
extensions: Default::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/actix-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ actix-web4 = { version = "4", default-features = false, optional = true, package
mime_guess = { version = "2.0.4", default-features = false }
serde_json = "1.0"
once_cell = "1.4"
openapiv3 = { version = "1.0.3", optional = true }
openapiv3 = { version = "2.0", optional = true }
include_dir = { version = "0.7.2", optional = true }
tinytemplate = { version = "1.1", optional = true }

Expand Down

0 comments on commit 1a9c3ec

Please sign in to comment.