Forum Discussion

chichepo's avatar
chichepo
Frequent Contributor
3 years ago
Solved

Pattern vs. nullable

Hello the community,

 

I got this schema definition in my OpenAPI 3.0.3 Yaml file:

 

username:
   type: string
   pattern: "^[a-zA-Z]{10}$"
   example: John

 

 

For some reason, I can't use allOf but I need to support a possible null value.

So I wrote:

 

username:
    type: string
    pattern: "^[a-zA-Z]{10}$"
    nullable: true
    example: John

 

 

Does it make sense to add nullable: true since I can change the regex to include null/empty value? (i.e.: '^[a-zA-Z]{3}$|^$')

Will "nullable" contradict the pattern, if it does not include null value as well?

Without allOf, how the pattern regex and the sub type "nullable" are connected?

 

Thank you for your comments

  • Agreed. You have this covered I think !!


    ---
    Micheál Higgins | Senior Solutions Architect
    m: +353.86.235.4599
    e: micheal.higgins@smartbear.com
    [cid:image001.png@01D8C370.AE509620]<>

    smartbear.com<>
    [cid:image002.png@01D8C370.AE509620]<> [cid:image003.png@01D8C370.AE509620] <> [cid:image004.png@01D8C370.AE509620] <> [cid:image005.png@01D8C370.AE509620] <>



    We hope you found this email of interest; however, click here if you wish to unsubscribe<> or manage your email preferences. Privacy Policy.<>

    Disclaimer

    The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.