Skip to content

Commit 8a61a60

Browse files
authored
use custom models correctly (#11)
* use custom models correctly * include in generated docs
1 parent 95f10b3 commit 8a61a60

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ impl fmt::Display for Error {
5757
}
5858

5959
mod error;
60-
mod openapi;
60+
pub mod models;
61+
pub mod openapi;
6162

6263
pub mod passage_flex;
6364
pub use passage_flex::PassageFlex;

src/models/app_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
3+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
44
pub struct AppInfo {
55
#[serde(rename = "auth_origin")]
66
pub auth_origin: String,

src/models/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod app_info;
2+
mod user_info;
3+
4+
pub use app_info::AppInfo;
5+
pub use user_info::UserInfo;

src/models/user_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
3+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
44
pub struct UserInfo {
55
#[serde(rename = "created_at")]
66
pub created_at: String,
@@ -14,16 +14,16 @@ pub struct UserInfo {
1414
#[serde(rename = "login_count")]
1515
pub login_count: i32,
1616
#[serde(rename = "status")]
17-
pub status: models::UserStatus,
17+
pub status: crate::openapi::models::UserStatus,
1818
#[serde(rename = "updated_at")]
1919
pub updated_at: String,
2020
#[serde(rename = "user_metadata", deserialize_with = "Option::deserialize")]
2121
pub user_metadata: Option<serde_json::Value>,
2222
#[serde(rename = "webauthn")]
2323
pub webauthn: bool,
2424
#[serde(rename = "webauthn_devices")]
25-
pub webauthn_devices: Vec<models::WebAuthnDevices>,
25+
pub webauthn_devices: Vec<crate::openapi::models::WebAuthnDevices>,
2626
/// List of credential types that have been used for authentication
2727
#[serde(rename = "webauthn_types")]
28-
pub webauthn_types: Vec<models::WebAuthnType>,
28+
pub webauthn_types: Vec<crate::openapi::models::WebAuthnType>,
2929
}

src/passage_flex.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use crate::models::{AppInfo, UserInfo};
12
use crate::openapi::apis::configuration::Configuration;
23
use crate::openapi::apis::{
34
apps_api, authenticate_api, transactions_api, user_devices_api, users_api,
45
};
5-
use crate::openapi::models;
66
use crate::Error;
7-
use models::{AppInfo, UserInfo};
87

98
pub struct PassageFlex {
109
app_id: String,
@@ -86,7 +85,13 @@ impl PassageFlex {
8685
pub async fn get_app(&self) -> Result<Box<AppInfo>, Error> {
8786
apps_api::get_app(&self.configuration)
8887
.await
89-
.map(|response| response.app)
88+
.map(|response| {
89+
Box::new(AppInfo {
90+
auth_origin: response.app.auth_origin,
91+
id: response.app.id,
92+
name: response.app.name,
93+
})
94+
})
9095
.map_err(Into::into)
9196
}
9297

@@ -126,7 +131,7 @@ impl PassageFlex {
126131
) -> Result<String, Error> {
127132
transactions_api::create_register_transaction(
128133
&self.configuration,
129-
models::CreateTransactionRegisterRequest {
134+
crate::openapi::models::CreateTransactionRegisterRequest {
130135
external_id,
131136
passkey_display_name,
132137
},
@@ -169,7 +174,7 @@ impl PassageFlex {
169174
) -> Result<String, Error> {
170175
transactions_api::create_authenticate_transaction(
171176
&self.configuration,
172-
models::CreateTransactionAuthenticateRequest { external_id },
177+
crate::openapi::models::CreateTransactionAuthenticateRequest { external_id },
173178
)
174179
.await
175180
.map(|response| response.transaction_id)
@@ -206,10 +211,13 @@ impl PassageFlex {
206211
/// }
207212
/// ```
208213
pub async fn verify_nonce(&self, nonce: String) -> Result<String, Error> {
209-
authenticate_api::authenticate_verify_nonce(&self.configuration, models::Nonce { nonce })
210-
.await
211-
.map(|response| response.external_id)
212-
.map_err(Into::into)
214+
authenticate_api::authenticate_verify_nonce(
215+
&self.configuration,
216+
crate::openapi::models::Nonce { nonce },
217+
)
218+
.await
219+
.map(|response| response.external_id)
220+
.map_err(Into::into)
213221
}
214222

215223
/// Get a user's ID in Passage by their external ID
@@ -303,7 +311,7 @@ impl PassageFlex {
303311
pub async fn get_devices(
304312
&self,
305313
external_id: String,
306-
) -> Result<Vec<models::WebAuthnDevices>, Error> {
314+
) -> Result<Vec<crate::openapi::models::WebAuthnDevices>, Error> {
307315
let user_id = self.get_id(external_id).await?;
308316
user_devices_api::list_user_devices(&self.configuration, &user_id)
309317
.await
@@ -386,7 +394,21 @@ impl PassageFlex {
386394
pub async fn get_user_by_id(&self, user_id: String) -> Result<Box<UserInfo>, Error> {
387395
users_api::get_user(&self.configuration, &user_id)
388396
.await
389-
.map(|response| response.user)
397+
.map(|response| {
398+
Box::new(UserInfo {
399+
created_at: response.user.created_at,
400+
external_id: response.user.external_id,
401+
id: response.user.id,
402+
last_login_at: response.user.last_login_at,
403+
login_count: response.user.login_count,
404+
status: response.user.status,
405+
updated_at: response.user.updated_at,
406+
user_metadata: response.user.user_metadata,
407+
webauthn: response.user.webauthn,
408+
webauthn_devices: response.user.webauthn_devices,
409+
webauthn_types: response.user.webauthn_types,
410+
})
411+
})
390412
.map_err(Into::into)
391413
}
392414
}

0 commit comments

Comments
 (0)