Am using openapi 3.0.3 to autogenerate my Spring Boot based REST API...
Inside src/main/resources/openapi/schema/PurchaseOrder.yaml
:
openapi: '3.0.3'
info:
title: 'Purchase Order'
version: '1.0'
paths: {}
components:
schemas:
PurchaseOrder:
title: 'Purchase Order'
type: 'object'
properties:
account:
type: 'string'
description: Identifier for account making the purchase
example: 1
minLength: 1
pattern: '^\s-$'
So, I need it to include alphanumeric values but no whitespaces (tried using this pattern: '^\s-$'
) - can't have whitespaces at all...
When trying:
{
account: 'a b'
}
This is what I received as a JSON Response:
"validationErrors": [
{
"field": "account",
"message": "must match \"^\\s-$\""
}
]
This same validation error also happens when I try a valid JSON (containing more than one char and no whitespaces and no hyphens):
{
'account': 'ab'
}
This should have been valid and not thrown any validation errors...
How can I enforce no whitespaces and/or no hyphens at all using regex inside this yaml file?