The current development branch for the rt-5gms-application-function contains openapi-generator templates that include some extra validation for number ranges.
One thing they do not currently validate are the values for string types which can have:
a regex pattern match associated with them (ECMA 262 regex).
a format type.
date, date-time, password, byte (base64 encoded) or binary (file reference) are the specified OpenAPI types.
a minLength to define the minimum number of characters.
a maxLength to define the maximum number of characters.
Design
The storage of string should be a char* unless the string has a format of byte or binary, in which case the storage shall be a void* for the data and a size_t representing the length. When byte is used as the format the string will be base64 decoded into the void* data block and the decoded length stored in the size_t.
The validation when checking a string type variable shall:
check the string length (strlen()) or data block size_t value against minLength and/or maxLength, if available, and generate a parse error is the range check fails.
if pattern is defined:
At the top level of the file a static regex pointer variable will be defined, using the structure and property name, which is initially set to NULL.
When parsing:
If the top level regex pointer is NULL then the regex is compiled and an exit tidy-up routine registered.
Use the compiled regex to match the string value and generate a parse error if it fails.
If format is defined:
When date, check the string matches regex "^\d{4}-\d{2}-\d{2}$".
When date-time, check the string matches regex "^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d+)?(?:Z|[-+]\d{2}:\d{2})$".
When password do nothing.
When byte then check that string is a valid base64 string (only correct base 64 symbols and correct number of = signs at the end for preceding number of base64 symbols).
When binary do nothing.
When any other value log a warning about not understanding the format and ignore format validation.
A tidy up function should also be included which will free any compiled regex structures that will be automatically registered as an atexit function.
Description
The current
development
branch for the rt-5gms-application-function contains openapi-generator templates that include some extra validation for number ranges.One thing they do not currently validate are the values for string types which can have:
pattern
match associated with them (ECMA 262 regex).format
type.date
,date-time
,password
,byte
(base64 encoded) orbinary
(file reference) are the specified OpenAPI types.minLength
to define the minimum number of characters.maxLength
to define the maximum number of characters.Design
The storage of string should be a
char*
unless the string has aformat
ofbyte
orbinary
, in which case the storage shall be avoid*
for the data and asize_t
representing the length. Whenbyte
is used as theformat
the string will be base64 decoded into thevoid*
data block and the decoded length stored in thesize_t
.The validation when checking a string type variable shall:
strlen()
) or data blocksize_t
value againstminLength
and/ormaxLength
, if available, and generate a parse error is the range check fails.pattern
is defined:format
is defined:date
, check the string matches regex "^\d{4}-\d{2}-\d{2}$".date-time
, check the string matches regex "^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d+)?(?:Z|[-+]\d{2}:\d{2})$".password
do nothing.byte
then check that string is a valid base64 string (only correct base 64 symbols and correct number of = signs at the end for preceding number of base64 symbols).binary
do nothing.A tidy up function should also be included which will free any compiled regex structures that will be automatically registered as an
atexit
function.