Query Parameter Criteria when NOT required


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?

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

Thanks for your time in advance.


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.


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.

        type: date-only | nil
        example: null
        type: date-only
        required: false


As per your requirement, you need to define it as an optional field.
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.