better message for validation error of parameter against regex

Issue #362 new
Gabriele Cornacchia created an issue

in my use case, I simulate a request with three different parameters (one in query string, one in path, and one in headers) that don't match the regex provided.

In the validation report I only see this messages.

ERROR - ECMA 262 regex "^[0-9]{5}$" does not match input string "123": [], ERROR - ECMA 262 regex "^[0-
9]{6,10}$" does not match input string "123": [], ERROR - ECMA 262 regex "^[0-9]{6,10}$" does not match input string "123": []

In this way I cannot understand immediately the param that caused the error.

Is there a way to get also the name of the parameters that violates the rule (in addition to the value)? or is it possible to develop such enhancement?

Comments (2)

  1. James Navin

    Hi Gabriele,

    The validation report Message instances include additional MessageContext that will include additional information such as the operation and parameter that caused the validation error. I’d suggest taking a look at what information is included there and if there is anything missing we can look to add it.

    If you need to get more detailed information in your output you can implement your own ValidationReportFormat or try using e.g. the JsonValidationReportFormat which will output much more information than the basic String formatter.

    Hope that helps.

    Cheers,

    James

  2. Gabriele Cornacchia reporter

    Thank you @James,

    I worked on it and I found a way to inspect the message context and enrich the validation message.

    In only one case I cannot reach my goal:

    For a particular operation is defined a required response header which must adhere to a certain regex pattern.

    responses:
      '200':
        description: A paged array of pets
        headers:
          x-custom-headers:
            schema:
              type: string
              pattern: ^(?!\s*$).+
            required: true
    

    At runtime the response header is returned but not compliant to regex. I couldn’t find a way to retrieve the name of the wrong header and return it to the client.

    Do you have any tips on this?

  3. Log in to comment