kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Decoding of anyOf fails when parameter is required

Open silverwind opened this issue 3 years ago • 1 comments

With a query parameter defined like this:

parameters:
  time:
    name: time
    in: query
    required: true
    schema:
      type: string
      anyOf:
        - format: time
        - pattern: "^[1-9][0-9]*$"

Validation will fail with error decoding anyOf for parameter 'time' failed.

The code seems to fail because the parameter is required, but I don't see why it should fail as anyOf is defined as "data may be valid against one or more subschemas at the same time", so it's just a stronger form of indicating the requirement.

https://github.com/getkin/kin-openapi/blob/32445850faa0551385d614e844b344006c0a8f22/openapi3filter/req_resp_decoder.go#L270-L272

silverwind avatar Jul 22 '22 06:07 silverwind

one or more

It seems this path was not taken at least once, so current behavior makes sense to me. https://github.com/getkin/kin-openapi/blob/32445850faa0551385d614e844b344006c0a8f22/openapi3filter/req_resp_decoder.go#L266-L268

If you want more help, please share code in the form of a failing test.

fenollp avatar Jul 29 '22 15:07 fenollp