Skip to content

fix: data field in DataTransferRequest objects is optional #134

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

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
24 changes: 22 additions & 2 deletions src/tests/schema_validation/v2_0_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,30 @@
assert!(compiled.is_valid(&instance));
}
#[test]
fn validate_data_transfer_request_no_data() {
let test = DataTransferRequest {
message_id: Some("message_id".to_string()),
data: None,
vendor_id: "vendor_id".to_string(),
};
let schema = include_str!("schemas/v2.0.1/DataTransferRequest.json");
let schema = serde_json::from_str(schema).unwrap();
let instance = serde_json::to_value(test).unwrap();
let compiled = Validator::new(&schema).expect("A valid schema");
let result = compiled.validate(&instance);
if let Err(errors) = result {
for error in errors {
println!("Validation error: {}", error);
println!("Instance path: {}", error.instance_path);
}

Check warning on line 889 in src/tests/schema_validation/v2_0_1.rs

View check run for this annotation

Codecov / codecov/patch

src/tests/schema_validation/v2_0_1.rs#L886-L889

Added lines #L886 - L889 were not covered by tests
}
assert!(compiled.is_valid(&instance));
}
#[test]
fn validate_data_transfer_request() {
let test = DataTransferRequest {
message_id: Some("message_id".to_string()),
data: "data".to_string(),
data: Some("data".to_string()),
vendor_id: "vendor_id".to_string(),
};
let schema = include_str!("schemas/v2.0.1/DataTransferRequest.json");
Expand All @@ -894,7 +914,7 @@
fn validate_data_transfer_response() {
let test = DataTransferResponse {
status: DataTransferStatusEnumType::Accepted,
data: "".to_string(),
data: None,
status_info: Some(StatusInfoType {
reason_code: "".to_string(),
additional_info: Some("".to_string()),
Expand Down
6 changes: 4 additions & 2 deletions src/v2_0_1/messages/datatransfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub struct DataTransferRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub message_id: Option<String>,
/// Data without specified length or format. This needs to be decided by both parties (Open to implementation).
pub data: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
/// This identifies the Vendor specific implementation
#[validate(length(min = 0, max = 255))]
pub vendor_id: String,
Expand All @@ -26,7 +27,8 @@ pub struct DataTransferResponse {
/// This indicates the success or failure of the data transfer.
pub status: DataTransferStatusEnumType,
/// Data without specified length or format, in response to request.
pub data: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
/// Detailed status information.
#[serde(skip_serializing_if = "Option::is_none")]
pub status_info: Option<StatusInfoType>,
Expand Down
Loading