Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty optional array with validation constraints is considered invalid #7111

Closed
mathis-m opened this issue Mar 24, 2021 · 3 comments · Fixed by #7112
Closed

empty optional array with validation constraints is considered invalid #7111

mathis-m opened this issue Mar 24, 2021 · 3 comments · Fixed by #7112

Comments

@mathis-m
Copy link
Contributor

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)

@mathis-m
Copy link
Contributor Author

Actually I may be off on what I'm talking about anyways - I was initially reading this older PR #6878, but poking through this PR I do see some null/required checking going on. Maybe editor.swagger.io is not running this code yet (is there an easy way to see what version it is running?).
Tomorrow I'll try just running swagger-ui locally on this version and see if it still is happening.

Originally posted by @dferretti in #7003 (comment)

@mathis-m
Copy link
Contributor Author

mathis-m commented Mar 24, 2021

@dferretti had a look at how it is handled for type: string minLength:
https://editor.swagger.io/?url=https://gist.githubusercontent.com/mathis-m/416a5796511d27cc7a6160bc9f9866fa/raw/4c8968e09386b67318c29827831c84994cf86d03/WZOi9WH0TP.txt

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

It allows optional or minLength of 2 both is valid.

@tim-lai
Copy link
Contributor

tim-lai commented Mar 24, 2021

is there an easy way to see what version it is running?

Yes, open the developer console, and type window.versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants