Open Fleshgrinder opened 1 month ago
Currently the plugin handles multiple documents as an array. How do popular deserializers handle multiple documents?
The majority I know offer two functions. One to deserialize a single document and another to deserialize multiple (returning some kind of list). The problem here is that a JSON schema is meant to describe a single document, but in YAML we can have multiple documents in a single file.
I think that the library should always assume multiple documents in a single YAML file and validate each separately. A JSON schema cannot disable this YAML functionality anyway.
So multiple documents are treated as a list (array), right? But does the schema expect object? Are there any popular schema definitions and use cases that use multiple documents?
Each document has its own schema. It needs to be thought of like a tar file. One file containing many others. Hence, a schema applies per document within a YAML file, not per YAML file.
I don't think it's very widespread. Using a single file with multiple documents always results in unnecessary merge conflicts. The only one case I have at hand where it seems to be a thing is Backstage's catalog-info.yaml
(example).
Each document would need to be treated like a separate file and validated individually. This begs the question of how to choose the schema. Obviously it's desirable to have the ability for a single schema to apply to all documents within. This can be achieved via the ESlint config, and via YAML comments (once implemented). Individual schemas can be achieved via a $schema
in each document.
That said, I've never seen the need for individual schemas, hence, having only one would IMHO be good enough. Still, it's how YAML works...
YAML has support for multiple documents via the document start
---
and (optional) document end...
markers. Trying to validate a YAML with multiple documents currently fails with: