-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contemplating on String #14
Comments
I think introspection would be awesome. We'll definitely want to think of something like that post-MVP, but it has MVP impacts we should be aware of now. You wrote: # declare Bar => String [ min_length => 3, max_length => 16 ];
sub operation_handler :returns (Bar) { ... }
say Bar->to_openapi;
So we would need something that could introspect a check to get the data you want. However, it would not produce XSD, OpenAPI definitions, or anything like that. Instead, it would just return a data structure, or an AST, and the consumer can write the custom transformation code they want. @tobyink has considered similar ideas in this discussion, but that was when I was considering releasing |
please note "syntax symbolic" about that example. Mentioned code should represent only description of behaviour, not an actual code. |
For what it's worth, |
@tobyink I know I tried to use it :-) IMHO I will be good exercise to write these specialized checks using |
I feel it is important for Perl to internally track the intention of whether a string is octets/raw or text/characters, much as we now as of 5.36.0 have it track whether or not a scalar is intended to be a boolean or not. I realize for legacy compatibility reasons that we'd likely need at least 3 options in the general case, which are definitely text, definitely raw, and don't-know, and it would be nice to be able to eliminate occurrences of the last one where possible. But any time for example an IO is done with an explicit encoding, we should know for sure, if it is raw the result is known octets and if it is eg UTF-8 or lots of others, it is characters. Also any strings derived from string literals in Perl source are also definitely text. So then combined with this internal notion we should have routines like builtin::is_text() and builtin::is_raw() or such as the reliable way for a program to assess what kind of thing it was given in a general context, similar to the existing builtin::is_bool() or whatever, and one can stop testing the utf8 flag or doing encoding tests etc to determine this. The encoding tests would still be relevant but in a different context, which is to take a string internally considered raw and convert it to text if applicable, say if we want that conversion to be a separate step than the actual IO. |
Pydantic https://docs.pydantic.dev/latest/why/#json-schema also has similar ideas with respect to JSON Schema / OpenAPI. |
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)
String
variantsrestrictions
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
base64Binary
JSON schema
string
type propertycontentEncoding: base64
content-type
It 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
anyURI
JSON schema
string
withformat
, one ofAlthough it is easy to write subcheck using
pattern
restriction, 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
The text was updated successfully, but these errors were encountered: