Swagger's code generation for a Spring server has an option called useBeanValidation, but I can't figure out how to use it. I couldn't find any documentation telling me which validations it supports, so I decided to try it out myself. The OpenAPI spec's description of the properties of a schema object lists these properties:
title
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxLength
minLength
pattern
maxItems
minItems
uniqueItems
maxProperties
minProperties
required
enum
So I tried adding some of these properties to fields of an Object I created. Here's the relevant portion of my .yaml file:
components:
schemas:
Dummy:
type: object
properties:
iMinMax:
type: integer
format: int32
minimum: 0
maximum: 100
dMinMaxEx:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: false
exclusiveMaximum: true
dMinExMaxEx:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: true
exclusiveMaximum: true
dMinExMax:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: true
exclusiveMaximum: false
sArray:
type: array
items:
type: string
minItems: 5
maxItems: 10
uniqueItems: true
sLen:
type: string
format: text
minLength: 5
maxLength: 10
I turned on the bean validation option of the Spring code generator and generated server code, but it didn't have any effect. The code it generated was exactly the same as with the option turned off. Does anyone know how to use Swagger's Bean Validation option?