How to surface "nested" validation errors in discriminator fails?

Issue #104 resolved
Andrew Thompson created an issue

We are validating some JSON and receiving this error.

[Path '/0'] Err.swaggerv2.discriminator.fail

This is "correct" because the JSON does indeed look like

[ {stuff} , { stuff} ]

And the 'stuff' has a discriminator in it, so the problem is with the path /0

The underlying problem is easy enough to see in the debugger. It's the classic problem with discriminator, all-of and additional properties.

But, I don't see any of that detail in the ValidatorReport we print the error messages from, just this top level error.

So is there any way to print all the errors, including the nested ones?

Comments (4)

  1. James Navin

    The v2.0 branch has a new JsonValidationReportFormat which outputs more details of the validation errors. This will become the default output for validation errors in v2.0.0. It should output the "nested" discriminator validation errors as additionalInfo.

    If you get a chance would be great to confirm that that meets your needs, or what other information might be needed.

  2. Pascal Schumacher

    Hi,

    we are using swagger-request-validator-core version 2.11.0.

    It looks like there still is useful information lost when building the report message.

    ImmutableMessage#toString prints:

    ERROR - [Path '/productOrderItem/0/appointment'] Failed validation of discriminator schema '/components/schemas/Appointment': []

    But debuging into SchemaValidator#validate reveals that com.github.fge.jsonschema.core.report.ProcessingMessage contains more helpful information for the same error:

    error: failed validation of discriminator schema '/components/schemas/Appointment'
        level: "error"
        schema: "/components/schemas/Appointment"
        instance: {"pointer":"/productOrderItem/0/appointment"}
        domain: "validation"
        keyword: "discriminator"
        key: "err.swaggerv2.discriminator.fail"
        report: [{
                "level": "error",
                "schema": {
                    "loadingURI": "#",
                    "pointer": "/components/schemas/Appointment"
                },
                "instance": {
                    "pointer": "/productOrderItem/0/appointment"
                },
                "domain": "validation",
                "keyword": "additionalProperties",
                "message": "object instance has properties which are not allowed by the schema: [\"@type\",\"validFor\"]",
                "unwanted": ["@type", "validFor"]
            }, {
                "level": "error",
                "schema": {
                    "loadingURI": "#",
                    "pointer": "/components/schemas/Appointment"
                },
                "instance": {
                    "pointer": "/productOrderItem/0/appointment"
                },
                "domain": "validation",
                "keyword": "allOf",
                "message": "instance failed to match all required schemas (matched only 1 out of 2)",
                "matched": 1,
                "nrSchemas": 2,
                "reports": {
                    "/components/schemas/Appointment/allOf/0": [],
                    "/components/schemas/Appointment/allOf/1": [{
                            "level": "error",
                            "schema": {
                                "loadingURI": "#",
                                "pointer": "/components/schemas/Appointment/allOf/1"
                            },
                            "instance": {
                                "pointer": "/productOrderItem/0/appointment"
                            },
                            "domain": "validation",
                            "keyword": "additionalProperties",
                            "message": "object instance has properties which are not allowed by the schema: [\"@type\"]",
                            "unwanted": ["@type"]
                        }
                    ]
                }
            }
        ]
    

    Should I create a new issue for this?

  3. Log in to comment