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

How to validate object with set of sub-objects #248

Open
tarto-dev opened this issue Jan 26, 2017 · 0 comments
Open

How to validate object with set of sub-objects #248

tarto-dev opened this issue Jan 26, 2017 · 0 comments

Comments

@tarto-dev
Copy link

tarto-dev commented Jan 26, 2017

Hello, I'm writing tests for API validation, and TV4 is very useful for this, but I can't find out how to check this JSon structure :
JSON SOURCE:

{  
   "count":5,
   "version":"1.0",
   "19":{  
      "prestationId":6225,
      "luluId":32,
      "craftsmanId":null,
      "status":"accepted"
   },
   "20":{  
      "prestationId":6225,
      "luluId":64,
      "craftsmanId":null,
      "status":"inactive"
   },
}

TV4 implementation

var schema = {
        "type": "object",
                "required": [],
                "properties": {
                    "prestationId": {
                        "type": "integer"
                    },
                    "luluId": {
                        "type": "integer"
                    },
                    "craftsmanId": {
                        "type": ["integer", "null"]
                    },
                    "status": {
                        "type": { "enum" : [ 'pending', 'accepted', 'refused', 'deleted', 'inactive'] }
                    },
                },
                "additionalProperties": false
    };

    var data = JSON.parse(responseBody);
    var result = tv4.validateResult(data, schema);

I just want to watch & validate sub-arrays, not the main one. I've try with $refs but it seems don't work with me.

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

1 participant