Skip to content

Commit ef3580f

Browse files
committed
docs: document contact object
1 parent 90da962 commit ef3580f

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

crates/oas3/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Add `spec::Contact::validate_email()` method.
56
- Expose the `spec::ClientCredentialsFlow::token_url` field.
67
- Rename `Error::{SemVerError => Semver}` variant.
78

crates/oas3/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use std::{fs::File, io::Read, path::Path};
2121
mod error;
2222
pub mod spec;
2323

24-
pub use error::Error;
25-
pub use spec::Spec;
24+
pub use self::error::Error;
25+
pub use self::spec::Spec;
2626

2727
/// Version 3.1.0 of the OpenAPI specification.
2828
///

crates/oas3/src/spec/contact.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
use std::collections::BTreeMap;
22

3+
use derive_more::derive::{Display, Error};
34
use serde::{Deserialize, Serialize};
45
use url::Url;
56

67
use super::spec_extensions;
78

9+
/// Error raised when contact info contains an email field which is not a valid email.
10+
#[derive(Debug, Display, Error)]
11+
#[display("Email address is not valid")]
12+
#[non_exhaustive]
13+
pub struct InvalidEmail;
14+
815
/// Contact information for the exposed API.
916
///
1017
/// See <https://github.com/OAI/OpenAPI-Specification/blob/HEAD/versions/3.1.0.md#contact-object>.
1118
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
1219
pub struct Contact {
20+
/// Identifying name of the contact person/organization.
1321
#[serde(skip_serializing_if = "Option::is_none")]
1422
pub name: Option<String>,
1523

24+
/// URL pointing to the contact information.
1625
#[serde(skip_serializing_if = "Option::is_none")]
1726
pub url: Option<Url>,
1827

19-
// TODO: Make sure the email is a valid email
28+
/// Email address of the contact person/organization.
29+
///
30+
/// Use [`validate_email()`](Self::validate_email) after deserializing to check that email
31+
/// address provided is valid.
2032
#[serde(skip_serializing_if = "Option::is_none")]
2133
pub email: Option<String>,
2234

@@ -28,3 +40,18 @@ pub struct Contact {
2840
#[serde(flatten, with = "spec_extensions")]
2941
pub extensions: BTreeMap<String, serde_json::Value>,
3042
}
43+
44+
impl Contact {
45+
/// Validates email address field.
46+
pub fn validate_email(&self) -> Result<(), InvalidEmail> {
47+
let Some(email) = &self.email else {
48+
return Ok(());
49+
};
50+
51+
if email.contains("@") {
52+
Ok(())
53+
} else {
54+
Err(InvalidEmail)
55+
}
56+
}
57+
}

crates/oas3/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub struct Spec {
149149
}
150150

151151
impl Spec {
152+
/// Validates spec version field.
152153
pub fn validate_version(&self) -> Result<semver::Version, Error> {
153154
let spec_version = &self.openapi;
154155
let sem_ver = semver::Version::parse(spec_version)?;

justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ update-readmes:
3535
[group("lint")]
3636
clippy:
3737
cargo clippy --workspace --all-targets --no-default-features
38-
cargo clippy --workspace --all-targets --no-default-features --all-features
38+
cargo clippy --workspace --all-targets --all-features
3939
cargo hack --feature-powerset clippy --workspace --all-targets
4040

4141
# Downgrade dev-dependencies necessary to run MSRV checks/tests.

0 commit comments

Comments
 (0)