Motivation / Goal
Nowadays common usage of Perl programs is some kind of backend. There it usually needs 3 types of checks (better word here will be contract)
- description of API I/O (mostly checks corresponding with JSON Schema (openapi) or XML Schema (XML over HTTP, XML/RPC, SOAP)
- description of internal representation
- description of storage representation (usually SQL)
It will be nice to have Perl checks / contracts specified that way so it will be possible to generate external descriptions directly from Perl definition.
Example: (syntax symbolic)
# declare Bar => String [ min_length => 3, max_length => 16 ];
sub operation_handler :returns (Bar) { ... }
say Bar->to_openapi;
# - <...>
# - type: string
# - max-length: 16
# - min-length: 3
say Bar->to_xsd;
# <xs:simpleType>
# <xs:restriction base="xs:string">
# <xs:maxLength value="16"/>
# <xs:minLength value="3"/>
# </xs:restriction>
# </xs:simpleType>
String variants
restrictions
Typical String restrictions (I like more XML schema's word facet) are
- min-length
- max-length
- pattern
There restrictions are supported by both JSON and XML schema as well (though they don't support perl regex).
It will be nice to support named restrictions, eg:
Str [ min_length => 10 ];
Str [ min_length (10) ];
Str :min_length (10);
binary vs text
It will be nice to be able to declare whether value is generic binary string or text string, eg:
Str - string treated as utf-8
Binary - generic binary string
XML schema
- supported by dedicated type
base64Binary
JSON schema
- supported by
string type property contentEncoding: base64
- supports also
content-type
It will be nice to be able to specify context encoding and related implicit coercions to/from internal encoding:
Binary :encoding (base64);
Binary :encoding (uuencode);
Binary :encoding (deflate);
Str :encoding (Latin-2);
documentation
It will be nice to be able to specify some description of check, eg:
Str :abstract (This is abstract);
Str :abstract_uri (https://...)
common derived checks (subtypes)
URI
XML schema
JSON schema
string with format, one of
- uri
- uri-reference
- iri
- iri-reference
Although it is easy to write subcheck using pattern restriction, it will be IMHO handy to provide built-in checks:
Date / time
XML schema
- date
- dateTime
- duration
- gDay
- gMonth
- gMonthDay
- gYear
- gYearMonth
- time
JSON schema
- date-time
- date
- time
- duration
It will be nice to provide also date/time related checks with possible encodings
- strict ISO 8601
- relaxed variant allowing space as date-time separator (default?)
- misc national format
Value represented by these checks may be dual valued, once there will good enough implementation of datetime object.
other useful checks
- UUID (JSON schema: uuid)
- Identifier (XML schema: token / ID / Name)
Motivation / Goal
Nowadays common usage of Perl programs is some kind of backend. There it usually needs 3 types of
checks(better word here will becontract)It will be nice to have Perl checks / contracts specified that way so it will be possible to generate external descriptions directly from Perl definition.
Example: (syntax symbolic)
Stringvariantsrestrictions
Typical String restrictions (I like more XML schema's word
facet) areThere restrictions are supported by both JSON and XML schema as well (though they don't support perl regex).
It will be nice to support named restrictions, eg:
binary vs text
It will be nice to be able to declare whether value is generic binary string or text string, eg:
Str- string treated as utf-8Binary- generic binary stringXML schema
base64BinaryJSON schema
stringtype propertycontentEncoding: base64content-typeIt will be nice to be able to specify context encoding and related implicit coercions to/from internal encoding:
documentation
It will be nice to be able to specify some description of check, eg:
common derived checks (subtypes)
URI
XML schema
anyURIJSON schema
stringwithformat, one ofAlthough it is easy to write subcheck using
patternrestriction, it will be IMHO handy to provide built-in checks:Date / time
XML schema
JSON schema
It will be nice to provide also date/time related checks with possible encodings
Value represented by these checks may be dual valued, once there will good enough implementation of datetime object.
other useful checks