Query Parameter Criteria when NOT required


#1

Is there a way to set any criteria/validations for query paramters that are NOT required? I have tried many combinations is order to do this and can’t figure it out. I can set all criteria but it basically renders the parameter required.

I need the ability to accept a blank parameter value BUT validate it against criteria if a value is provided. For instance I’d like to know how to accept a date parameter but also allow it to be blank.

This possible?

qp1:
    type: date-only
    #minLength: 10
    #maxLength: 10
    example: "2017-01-01"
    required: false

Thanks for your time in advance.
Doug


#2

What do you use to render your spec? Maybe its only a tooling “feature”? For a blank value, you might want to look into the nil type.


#3

What you mean with “blank”? If you mean it is optional, then you need to use “required: false”. If the value can be null, then you need to say that the type is a union with nil and then in the json use the null value.

/:
  get:
    queryParameters: 
      nillableDate: 
        type: date-only | nil
        example: null
      optionalDate: 
        type: date-only
        required: false

#4

@dawalters
As per your requirement, you need to define it as an optional field.
queryParameters:
mydate:
type: date-only
required: false
In the below highlighted content, you can see that mydate is not mandatory. It will only accept date.
hope it will help.