I currently have the openApiSpec for a spring type of
ExistingPaymentMethodRequest:
additionalProperties: false
type: object
required:
- tokenId
- transactionId
properties:
tokenId:
type: string
example: '8ac7a4a2869f37d50186a210aac05eb6'
pattern: '^[a-zA-Z0-9-]*$'
minLength: 1
maxLength: 200
transactionId:
type: string
format: uuid
example: 'b79cb3ba-745e-5d9a-8903-4a02327a7e09'
pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
minLength: 36
maxLength: 36
This produces a pojo via openApiGenerate of
data class ExistingPaymentMethodRequest(
@get:Pattern(regexp="^[a-zA-Z0-9-]*$")
@get:Size(min=1,max=200)
@get:JsonProperty("tokenId", required = true) val tokenId: kotlin.String,
@get:Pattern(regexp="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
@get:Size(min=36,max=36)
@get:JsonProperty("transactionId", required = true) val transactionId: java.util.UUID
)
Which throws an exception when I send a request
jakarta.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'jakarta.validation.constraints.Size' validating type 'java.util.UUID'. Check configuration for 'transactionId'
Which seems fairly reasonable given UUIDs have a fixed size. However removing the size/pattern restraints makes it fail the openApi audit by https://42crunch.com/
A string schema does not specify the maximum length for the accepted strings.
For more details, see the OpenAPI Specification.
What is the correct way to deal with this? Is there a way to make spring handle @Size and @Pattern on UUIDs? Or to force openapigenrator not to produce @Size and @Pattern on UUIDs?