Skip to content

Inconsistent Parameter Validation Behavior in libopenapi-validator v0.4.0 #140

@wsqyouth

Description

@wsqyouth

Description:

I've encountered an inconsistency in parameter validation when using libopenapi-validator version v0.4.0. Specifically, there are differences in how validation errors are reported for different types of illegal parameter scenarios:

  • Enum Value Mismatch:
    When providing parameter values that do not match the expected enum values, the validation error response is generated, but the ValidationError.SchemaValidationErrors field is empty.
    Image

  • Exceeding Maximum Range:
    Conversely, when a parameter exceeds its maximum allowable value, the validation error response includes details within the ValidationError.SchemaValidationErrors field.
    Image

Upon reviewing the source code, I noticed that within the validateSimpleParam method, there is preliminary validation only for illegal values, whereas other validation types utilize the ValidateSingleParameterSchema function. This discrepancy results in the ValidationError.SchemaValidationErrors field not being populated consistently.
github.com/pb33f/[email protected]/parameters/query_parameters.go:232
Image

Suggestion:

I believe that this inconsistent behavior can make it challenging for users to handle validation errors uniformly.
It would be beneficial to use ValidateSingleParameterSchema for all types of parameter validations, ensuring that the response behavior is consistent across different scenarios.

Your feedback and thoughts on this matter would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions