cancel
Showing results for 
Search instead for 
Did you mean: 

Case Insensitive String parameter in schema of openApi

SOLVED
Highlighted
Visitor

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 get the "platform" parameter from URL , it can be like this :

platform=online or 
platform=ONLINE or 
platform=Online or 
platform=onLine  or ... any other format

but when I am going to use it , it is only valid if the parameter is all lower case like "platform=online", obviously to match the enum value.

how can I make schema to be the case insensitive and understand all types of passed parameters?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Case Insensitive String parameter in schema of openApi

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.


Helen Kosova
SmartBear Technical Writer
________________________

 Join the virtual SmartBear Connect user conference on April 27-28! Get your free virtual ticket today!

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: Case Insensitive String parameter in schema of openApi

Never come across such case.
Please see if the below is helpful:
https://stackoverflow.com/questions/28332924/case-insensitive-matching-of-a-string-to-a-java-enum


Regards,
Rao.
Highlighted
Moderator

Re: Case Insensitive String parameter in schema of openApi

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.


Helen Kosova
SmartBear Technical Writer
________________________

 Join the virtual SmartBear Connect user conference on April 27-28! Get your free virtual ticket today!

View solution in original post