Skip to content
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

[RFC] More visibility for YAML::Schema::FailSafe #13821

Open
straight-shoota opened this issue Sep 20, 2023 · 0 comments
Open

[RFC] More visibility for YAML::Schema::FailSafe #13821

straight-shoota opened this issue Sep 20, 2023 · 0 comments

Comments

@straight-shoota
Copy link
Member

Crystal's YAML parser supports the failsafe schema, but it's quite hidden in YAML::Schema::FailSafe and not mentioned anywhere else. In contrast, the Core schema is prominently used by YAML.parse.

Now the API docs for YAML should certainly at least mention this alternative schema.

But I think there should also be an easier option for using it. Compared to the short code YAML.parse(yaml), YAML::Schema::FailSafe.parse(yaml) is quite bulky and resides two nested namespaces deeper.

I'd like to introduce an easily accessible API for the failsafe schema directly on YAML for convenience.
Options for this are:

  • an additional overload which accepts a parameter: YAML.parse(yaml, schema: :fail_safe)
  • a separate method: YAML.parse_fail_safe(yaml)

Failsafe is the smallest sibling of the YAML schemas and a tiny subset of the Core schema. It only supports mapping, list, and string types. This makes it much more sane than its bigger siblings (for example, it doesn't interpret Norway as a Boolean). It's entirely sufficient for many use cases of parsing a dynamic YAML structure (YAML::Any). I think it should often be preferred over the Core schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant