Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Empty strings not allowed #154

Closed erezarnon closed 1 year ago

erezarnon commented 1 year ago

In API parameters definition (Notice there is not minLength or pattern):

- name: q
        in: query
        schema:
          type: string

Call enforcer.request({query: {q: ''}}) and receive the following error

Request has one or more errors
  In query parameters
    at: q
      Unable to parse value
        Empty value not allowed

Expected behavior: An empty string should be accepted

Gi60s commented 1 year ago

Hey @erezarnon. Thanks for the issue.

I haven't had a chance to look into this too much yet, but I'm guessing that you need to specify the allowEmptyValue on your parameter definition. This value defaults to false, so at first glance I believe this is what's wrong.

Here are the docs: https://spec.openapis.org/oas/latest.html#parameter-object

Let me know if this resolves the issue for you.

erezarnon commented 1 year ago

Yes, resolved. My googling didn't turn that up, thank you.

Gi60s commented 1 year ago

I'm glad that I could help out. Happy coding!