Missing support for "YAML Schema" (spec 1.2)
还没有人认领这个 Issue。
评估
调研方向
该 issue 没有指定文件、测试或入口点。首先根据 YAML 1.2 第 10 章检查 Psych 的公共解析 API,然后定义所需的 schema 常量和行为;完成的标准是 Psych 提供可在解析期间选择的 YAML 1.2 schema 支持。
由索引模型根据 Issue 内容生成。
描述
Hi!
Let me open a new thread to discuss a solution to some of the annoyingly recurring issues.
Parsing of Date, right?.. #262 huge thread, #393, #483, from the oldest #137 to new generation #672, #676; there's more.
Datetime in the same bucket.
Parsing of Symbol — far from a hardcore Ruby-head myself — but I see it in the same bucket, too.
The thing is: spec 1.2 solves it all. Let me explain.
Spec TL;DR
I'll reword from Chapter 10 of the spec, the last chapter.
It defines:
- Failsafe Schema,
- JSON Schema,
- Core Schema,
- and hints at Other Schemas.
To simplify, think of "YAML Schema" as a list of classes (yaml "tags") that are allowed to de/serialize.
The FAILSAFE_SCHEMA comprises tags [map, seq, str].
The JSON_SCHEMA comprises tags [null, bool, int, float] plus those from FAILSAFE_SCHEMA.
The CORE_SCHEMA comprises the same tags as JSON_SCHEMA. (Find exact difference in the spec.)
Why did I change to ALL_CAPS?.. Because these are supposed to be in yaml library API. ⚠️
Example
I'd recently hit an issue trying to validate a bunch of yamls containing... dates, you guessed it — against a pre-existing json-schema.
Used json_schemer, nice library. Long story short, https://github.com/davishmcclurg/json_schemer/issues/203 — it didn't work well. I found no better solution than a filthy monkey-patch.
It's because of a basic impedance mismatch:
- The best json-schema can do, is
{"type": "string", "format": "date"}. Reference if you don't believe me. (Although should be obvious: there's no concept ofDatetype in JSON, justregexesABNF).- The validator library fully supports that.
- YAML, however, has a notion of
datetag (type) — which is distinct fromstrtag (a string). That's whyfield: "2024-12-27"andfield: 2024-12-27do not — and should not! — have the same meaning and behavior.- The validator library blows up when verifying
{"type": "string", "format": "date"}on#<Date: 2024-12-26 ((2460671j,0s,0n),+0s,-Infj)>parsed from yaml, saying… is not a string. It indeed, correctly, isn't.
- The validator library blows up when verifying
What gives
Now, a bit of cross-pollination.
JavaScript folks had hit the exact same conundrum, not so long ago. https://github.com/ajv-validator/ajv-cli/issues/122
How did they solve it?.. Well, their yaml library supports ✨ YAML Schemas! ✨
So their fix was literally a single-line change that switched the validator's parser to CORE_SCHEMA. YAML-native date tag no more; date validation issues no more; solved, done!
Now, I can't do the same using Psych, can I?
Will I?
- 主要语言
- Ruby
- 星标
- 597
- 派生
- 223
- 平均合并
- 14 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/psych 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Documentation
难度 1/5 1 小时以内 新手友好度 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings可能已有人在做 @Halvanhelv 于 31 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 52/100
相似的 Issue
-
area/web interface
难度 2/5 1-3 小时 新手友好度 62/100
mastodon/mastodon#41009 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
yegor256/ellipsized#131 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 78/100