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

fix!: allowed to make required fields optional #1919

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 10 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/platform-test-suite/test/e2e/withdrawals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const { STATUSES: WITHDRAWAL_STATUSES } = require('dash/build/SDK/Client/Platfor
const createClientWithFundedWallet = require('../../lib/test/createClientWithFundedWallet');
const waitForSTPropagated = require('../../lib/waitForSTPropagated');

describe('Withdrawals', function withdrawalsTest() {
// TODO: temporarily disabled due to flakiness. This tests aren't important for now, since we are
// going to release v1.0.0 with withdrawals disabled.
describe.skip('Withdrawals', function withdrawalsTest() {
this.bail(true);

let client;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ rust_decimal_macros = "1.29.1"
indexmap = { version = "2.0.2", features = ["serde"] }
strum = { version = "0.25.0", features = ["derive"] }
json-schema-compatibility-validator = { path = '../rs-json-schema-compatibility-validator' }
once_cell = "1.19.0"

[dev-dependencies]
test-case = { version = "2.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,36 @@ use crate::data_contract::errors::{DataContractError, JsonSchemaError};
use crate::data_contract::JsonValue;
use crate::validation::SimpleValidationResult;
use crate::ProtocolError;
use json_schema_compatibility_validator::validate_schemas_compatibility;
use json_schema_compatibility_validator::{
validate_schemas_compatibility, CompatibilityRulesCollection, Options,
KEYWORD_COMPATIBILITY_RULES,
};
use once_cell::sync::Lazy;
use std::ops::Deref;

static OPTIONS: Lazy<Options> = Lazy::new(|| {
let mut required_rule = KEYWORD_COMPATIBILITY_RULES
.get("required")
.expect("required rule must be present")
.clone();

required_rule.allow_removal = false;
required_rule
.inner
.as_mut()
.expect("required rule must have inner rules")
.allow_removal = false;

Options {
override_rules: CompatibilityRulesCollection::from_iter([("required", required_rule)]),
}
});

pub(super) fn validate_schema_compatibility_v0(
original_schema: &JsonValue,
new_schema: &JsonValue,
) -> Result<SimpleValidationResult<IncompatibleJsonSchemaOperation>, ProtocolError> {
validate_schemas_compatibility(original_schema, new_schema)
validate_schemas_compatibility(original_schema, new_schema, OPTIONS.deref())
.map(|result| {
let errors = result
.into_changes()
Expand Down
1 change: 1 addition & 0 deletions packages/rs-json-schema-compatibility-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ once_cell = "1.19.0"
[dev-dependencies]
# enable "examples" for integration tests
json-schema-compatibility-validator = { path = ".", features = ["examples"] }
assert_matches = "1.5.0"

[features]
examples = []
3 changes: 2 additions & 1 deletion packages/rs-json-schema-compatibility-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ mod validate;
pub use crate::change::*;
pub use crate::rules::*;
pub use json_patch::{AddOperation, RemoveOperation, ReplaceOperation};
pub use validate::{validate_schemas_compatibility, CompatibilityValidationResult};
pub use validate::{validate_schemas_compatibility, CompatibilityValidationResult, Options};
pub use KEYWORD_COMPATIBILITY_RULES;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ mod value;
#[cfg(any(test, feature = "examples"))]
pub use compatibility_rules::CompatibilityRuleExample;
pub use compatibility_rules::{CompatibilityRules, IsReplacementAllowedCallback};
pub use rule_set::CompatibilityRulesCollection;
pub use rule_set::KEYWORD_COMPATIBILITY_RULES;
Loading
Loading