Parsing ValidationReport message ?

Issue #300 resolved
Former user created an issue

Hi ! Is parsing the text message of the ValidationReport the only way to obtain the list of missing required properties in a request ? Same question for extracting the path of a wrongly typed property ? And last question, why the path not using JsonPath syntax ?

Thx a lot ! Marco

Comments (5)

  1. James Navin

    Hi Marco,

    At the moment the best approach is probably to look at the MessageContext attached to the Message objects returned in the ValidationReport. This will let you access things like the underlying io.swagger.v3.oas.models.Operation that was being validated to generate the message.

    If you have specific use cases in mind please feel free to elaborate - it’s quite likely we can/should enhance this API to allow you access to more information.

    Cheers,

    James

  2. marc.levisse

    Hi, in fact the actual ImmutableMessage in the ValidationReport is containing the JsonNode “pointer” in the message text :

    In SchemaValidator.java :

    final String message =
                    (pointer.isEmpty() ? "" : "[Path '" + pointer + "'] ")
                            + capitalize(processingMessage.get("message").textValue());
    

    I guess (my need 😉) it should be useful to provide the pointer in a separate attribute of the ValidationReport.Message object so as to be able to access it directly to allow customizing the ValidationReport output.

    Actually, I would still have to translate this JsonPointer to JsonPath (dot) notation (i.e. $.store.book[0].title instead of jackson’s JsonPointer format /store/book/0/title but that not very hard)

    My use case is replacing, in an existing public api, current hardcoded validations for required/missing properties, enum validations etc., by the use of your OpenAPIValidationFilter. That’s why I would need to customize the report output to fit current api output (and I would really love to avoid having to parse ValidationReport text messages 😉 )

  3. James Navin

    I’ve added optional Pointers to the message context that give the JsonPointer to the instance (the thing being validated) and schema (the schema being used to do the validation). If this doesn’t meet your needs please let me know.

  4. marc.levisse

    Thx a lot ! I’ll check that asap !

    [edit] Upgraded to 2.18.0 and that’s seems to do part of the job !

    In fact I still have one case not handled :

    if my request body misses some required json properties

    The message (text) :

    Object has missing required properties (["technicalName","ttl","userName"])
    

    The pointers :

    instance: "/"
    schema: ""
    

    I don’t know if we can have an array of missing properties, here should be :

    [
      "technicalName", 
      "ttl", 
      "userName"
    ]
    

    (once again, not to have to parse the message)

    I’ll try to fix that myself with the library locally so as not to provide you with one feedback at a time 😉

    (when ready, I’ll make a PR)

  5. Log in to comment