Missing support for "YAML Schema" (spec 1.2)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
L'issue non indica alcun file, test o punto di ingresso. Inizia esaminando l'API pubblica di parsing di Psych in relazione al capitolo 10 di YAML 1.2, quindi definisci le costanti dello schema e il comportamento richiesti; il lavoro è completato quando Psych espone il supporto allo schema YAML 1.2, selezionabile durante il parsing.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- Ruby
- Stelle
- 597
- Fork
- 223
- Merge medio
- 14m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/psych
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsForse già presa @Halvanhelv l’ha presa 31 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
scanaislop/aislop#476 ·
I maintainer di solito rispondono entro 1 giorno
-
Dependencies view: `getParent` loops forever on untitled documents, extension host runs out of memoryForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
area/web interface
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
mastodon/mastodon#41000 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
zerocracy/judges-action#2743 ·
I maintainer di solito rispondono entro 8 giorni
-
Deno Runtime is discontinuedApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
endoflife-date/endoflife.date#11314 ·
I maintainer di solito rispondono entro 1 giorno