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

Support embedded/referenced object validation #12

Closed
mavarazy opened this issue Aug 10, 2017 · 3 comments
Closed

Support embedded/referenced object validation #12

mavarazy opened this issue Aug 10, 2017 · 3 comments
Assignees
Milestone

Comments

@mavarazy
Copy link
Contributor

Currently this objects are ignored by the validator

@mavarazy mavarazy added this to the Release 0.2.0 milestone Aug 10, 2017
@mavarazy mavarazy self-assigned this Aug 10, 2017
@CodestarGames
Copy link

CodestarGames commented Sep 9, 2017

Will this allow for referencing other nested properties in the form object? I'm currently trying to figure out how to compare two properties I have on an object that I have a schema for.

var diffPercent = function(first, second){
    return (second-first)/first * 100;
}

predicate.decreasedByMoreThanPercent = predicate.curry((val, params) => {
    return predicate.num(val) &&
        predicate.num(params.average) &&
        predicate.num(params.target) &&
        predicate.less(val, params.average) &&
        predicate.greaterEq(Math.abs(diffPercent(val, params.average)), params.target);
});

var rules = [{
    conditions: {
        cost: {
            decreasedByMoreThanPercent: {
                average: "averages_monthly.cost",
                target: 20
            }
        }
    },
    event: {
        type: "whatever",
        params: {
            field: "something"
        },
    }
}];

var schema = {
    definitions: {
        averages_monthly: {
            type: "object",
            properties: {
                cost: { type: "number" }
            }
        }
    },
    properties: {
        cost: { type: 'number' },
        averages_monthly: {
            $ref: "#/definitions/averages_monthly"
        }
    }
};

var formData = {
    cost: 50,
    averages_monthly: {
        cost: 100
    }
}

@mavarazy
Copy link
Contributor Author

mavarazy commented Sep 9, 2017

@CodestarGames As I understand you want to have a condition looking something like

 conditions: {
     cost: {
        decreasedByMoreThanPercent: {
             average: "averages_monthly.cost",
             target: 20
         }
     }
 }

This specific issue, is not for that. This is for validating references like "averages_monthly.cost", that averages_monthly actually has a cost field. This can be a good feature, I'll open a separate issue to address this.

@mavarazy
Copy link
Contributor Author

@CodestarGames I've fixed #14, so now it should work, by appending $ to the field definition, like this.

 conditions: {
     cost: {
        decreasedByMoreThanPercent: {
             average: "$averages_monthly.cost",
             target: 20
         }
     }
 }

The fix is in the latest release 0.1.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants