Reputation: 21
I have some string parameters with specified format
in my OpenAPI documentation.
email:
type: string
format: email
hostname:
type: string
format: hostname
path:
type: string
format: uri
I want to define maxLength to protect from harmful queries. Do I have to do it or does format already define the maximum length?
Upvotes: 2
Views: 4273
Reputation: 621
For some of the formats the length of its value is defined. You can refer https://github.com/OAI/OpenAPI-Specification/issues/607#issue-142290879 to get the RFC definition for these formats. Apart from those if you think you need to have your predefined max/min length for the string value you can add them or you can use pattern keyword as well if you want to introduce any custom formats in your API definition. Using format has its own advantage and disadvantages.
Advantage
Disadvantage
Upvotes: 1