Missing support for "YAML Schema" (spec 1.2)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Das Issue nennt keine Datei, keinen Test und keinen Einstiegspunkt. Beginne damit, Psychs öffentliche Parsing-API anhand von YAML 1.2, Kapitel 10, zu überprüfen, und definiere dann die erforderlichen Schema-Konstanten und das Verhalten; als erledigt gilt die Aufgabe, wenn Psych Unterstützung für das YAML-1.2-Schema bietet, die beim Parsen ausgewählt werden kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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?
- Vorherrschende Sprache
- Ruby
- Sterne
- 596
- Forks
- 224
- Ø Merge
- 8 Std. 38 Min.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ruby/psych
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsEvtl. vergeben @Halvanhelv hat das vor 46 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 55/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
up-for-grabs/up-for-grabs.net#6330 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 72/100
TheOdinProject/curriculum#31490 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
hotwired/turbo-rails#791 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
FinanceFlash/unvibecode#273 ·