Forum Discussion

fardin's avatar
fardin
Visitor
5 years ago

Case Insensitive String parameter in schema of openApi

I have an open API spec with a parameter like this:  - name: platform in: query description: "Platform of the application" required: true schema: type: string enum: - "desktop" - "online" when I ge...
  • HKosova's avatar
    5 years ago

    Here's a copy of my answer to the same question on Stack Overflow:

     

    Enums are case-sensitive. To have a case-insensitive schema, you can use a regular expression pattern instead:

    - name: platform
      in: query
      description: 'Platform of the application. Possible values: `desktop` or `online` (case-insensitive)'
      required: true
      schema:
        type: string
        pattern: '^[Dd][Ee][Ss][Kk][Tt][Oo][Pp]|[Oo][Nn][Ll][Ii][Nn][Ee]$'

    Note that pattern is the pattern itself and does not support JavaScript regex literal syntax (/abc/i), which means you cannot specify flags like i (case insensitive search). As a result you need to specify both uppercase and lowercase letters in the pattern itself.


    Alternatively, specify the possible values in the description rather than in pattern/enum, and verify the parameter values on the back end.