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

Structure validation error. #324

Closed
ygpark2 opened this issue Oct 21, 2016 · 2 comments
Closed

Structure validation error. #324

ygpark2 opened this issue Oct 21, 2016 · 2 comments

Comments

@ygpark2
Copy link

ygpark2 commented Oct 21, 2016

Schema

"responses": {
                    "200": {
                        "description": "",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "booking_events": {
                                    "$ref": "#/definitions/booking_event"
                                },
                                "event_creators": {
                                    "$ref": "#/definitions/event_creator"
                                },
                                "venues": {
                                    "$ref": "#/definitions/venue"
                                },
                                "booking_event_details": {
                                    "$ref": "#/definitions/booking_event_details"
                                },
                                "booking_event_packages": {
                                    "type": "array",
                                    "items": {
                                        "type": "object"
                                    }
                                },
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>      <------------ this section
                                "downloads": {
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/definitions/download_file"
                                    }
                                },
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
                                "highlights": {
                                    "type": "array",
                                    "items": {
                                        "type": "string"
                                    }
                                },
                                "to_brings": {
                                    "type": "array",
                                    "items": {
                                        "type": "string"
                                    }
                                },
                                "to_wears": {
                                    "type": "array",
                                    "items": {
                                        "type": "string"
                                    }
                                },
                                "pricings": {
                                    "type": "object",
                                    "properties": {
                                        "low": {
                                            "type": "boolean"
                                        },
                                        "high": {
                                            "type": "boolean"
                                        },
                                        "total": {
                                            "type": [
                                                "integer",
                                                "string"
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "201": {
                        "$ref": "#/responses/trait:success:201"
                    },
                    "401": {
                        "$ref": "#/responses/trait:success:401"
                    }
                }
........................................
"definitions": {
...........................
        "download_file": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "owner_id": {
                    "type": "integer"
                },
                "active": {
                    "type": "integer"
                },
                "type": {
                    "type": "string"
                },
                "key": {
                    "type": "string"
                },
                "is_main": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "filename": {
                    "type": "string"
                },
                "created": {
                    "type": "string",
                    "pattern": "^(2[0-9]{3})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]) (0[0-9]|1[0-9]|2[0123])\\:([012345][0-9])\\:([012345][0-9])$"
                },
                "modified": {
                    "type": "string",
                    "pattern": "^(2[0-9]{3})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]) (0[0-9]|1[0-9]|2[0123])\\:([012345][0-9])\\:([012345][0-9])$"
                },
                "encrypted_key": {
                    "type": "string"
                },
                "filepath": {
                    "type": "string"
                },
                "path": {
                    "type": "string"
                },
                "url": {
                    "type": "string"
                },
                "exists": {
                    "type": "boolean"
                },
                "size": {
                    "type": "integer"
                },
                "size_string": {
                    "type": "string"
                },
                "extension": {
                    "type": "string"
                }
            }
        },
.........................................
}

Response

{
    "success": true,
   ...........................................................................
    "booking_event_packages": [],
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    <---------- this section
    "downloads": [
        {
            "Doc": {
                "id": "123",
                "owner_id": "100",
                "active": "1",
                "type": "doc",
                "key": "dg46bv1i36uekrjq",
                "is_main": "0",
                "name": "bookings endpoint",
                "filename": "aus39y0rqvrzxsj8u423.txt",
                "created": "2016-10-17 15:50:50",
                "modified": "2016-10-17 15:50:50",
                "encrypted_key": "S9vLirwnAZB2WoSuVsnfOksSJ96zUdI9EuN31zQ_t1M5dA_W8F4GWOUGDEwGLzSho74ZaSL_9KrpJWM5r1e5osFBlwOrYB6Vyin-F2X4qAVGY57oV8wEPitQ25dGckTt",
                "filepath": "https:\/\/s3-ap-southeast-2.amazonaws.com\/emc-dev\/e0a64-docs\/100\/aus39y0rqvrzxsj8u423.txt",
                "path": "s3:\/\/emc-dev\/e0a64-docs\/100\/aus39y0rqvrzxsj8u423.txt",
                "url": "https:\/\/s3-ap-southeast-2.amazonaws.com\/emc-dev\/e0a64-docs\/100\/aus39y0rqvrzxsj8u423.txt",
                "exists": false,
                "size": 0,
                "size_string": "0 bytes",
                "extension": "txt"
            }
        }
    ],
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    "highlights": [
        "one",
        "two"
    ],
    "to_brings": [
        "hello",
        "goodbye"
    ],
    "to_wears": [
        "apples",
        "pears"
    ],
    "pricings": {
        "low": false,
        "high": false,
        "total": 0
    }
}

This is the code to validate the above schema and response.

$validator = new Validator
$validator->reset();
$validator->check($jsonResponse, $expectedSchema);
$validator->isValid();

As you can see above, the download section's structure is definately different. In the schema, downloads have an array of object while the response have an object with key name Doc. Thus, I believe that json-schema library should detect this error. But it seems to only detect the data type errors.

How can I detect this type of error? or is this type of error impossible to detect in json-schema library?

Please give me a small clue to resolve this issue.

Thank you.

@shmax
Copy link
Collaborator

shmax commented Oct 27, 2016

If you want it to catch the error, make this change to your definition:

"download_file": {
            "type": "object",
            "additionalProperties":false,
            "properties": {

@DannyvdSluijs
Copy link
Collaborator

@ygpark2 in an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume this is a rather old issue, which sadly was left unanswered, and can be closed? Feel free to close it yourself with some comments if helpful.

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

4 participants