Skip to content

empty optional array with validation constraints is considered invalid #7111

@mathis-m

Description

@mathis-m

I know I'm late to the party, but I think this is relevant to this PR. I believe you can have a non-required string array param in the query, with minItems: 1 to represent "either don't pass it at all, or if you do it must include at least 1 item". Well, I think so anyway..
I know you can have a non-required, non-nullable parameter meaning "either don't provide it, or provide a non-null value, but never provide x: null". So I believe you can additionally constrain the array with minItems: 1 IIRC.

I am trying this in https://editor.swagger.io :

openapi: 3.0.3
info:
  title: Test
  version: 1.0.0
paths:
 /test:
   get:
     parameters: 
       - name: names
         in: query
         required: false
         schema:
           type: array
           minItems: 1
           items:
             type: string
     responses:
       200:
         description: OK

I would like to be able to test omitting the names parameter by not providing any elements, but swagger-ui tells me I must provide at least 1 value.

Should these minItems validation checks include whether or not the param is required? Or am I way off here and the spec doesn't allow that?

Originally posted by @dferretti in #7003 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions