Closed aaronnickovich closed 3 days ago
It is not a use-case I am super familiar with, but happy to look at a PR.
Just thinking through some considerations: We would have to assume that all of the yaml documents in a given file conform to the same schema. I don't think we could deal with a situation where a file contains multiple yaml documents and they need to be validated against different schemas. At the moment everything is based on one schema being used to validate a file. I think that's a reasonable limitation.
Yes, customizing per-doc in a YAML file doesnt fit the philosophy of the schemastore which is based on the filename, path, and extension.
Also, most of the yaml schemas I see in the schemastore are supposed to be a single doc so it's an edge-case, of course.
For context, I am piloting an instance of https://backstage.io which is just a catalog of people, teams, software, and apis. Each team just maintains their own catalog-info.yaml file and each can contain somewhere between 1 - 6 docs. An example is here: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/acme/org.yaml
Anways, I'll work on it and open a PR in a few days.
I've just released v8r 4.0.0.
This release introduces some features relevant to this issue:
ValidationResult
. It is just an array of ValidationResult
objects https://github.com/chris48s/v8r/blob/e3f23b4d9364c4a9cd6e240d35e279e48a258016/CHANGELOG.md?plain=1#L5-L6 Crucially for this issue, this change relaxes the constraint that there was a one-to-one mapping between filename and result of validation.At the moment, it would still not be possible to implement this as a plugin. There are still changes to the internals required to implement support for formats like multi-doc yaml or ndjson which include multiple documents in a single file. However, in implementing the plugin system I have at least thought about this issue and designed it in a way that those changes would not require another backwards-compatibility break.
From where we are now, the extra changes required to the internals would be:
parseInputFile()
plugin hook to optionally return an array of Document
objects (at the moment it is expected to return a single Document
object)ValidationResult
object to also include an index for the internal document inside the file as well as the filenameThen if those modifications to internals are made, it would then be possible to write plugins (either userspace or core plugins) that return an array of document objects and v8r would correctly handle it.
I just released v8r v4.1.0 which includes this feature https://www.npmjs.com/package/v8r/v/4.1.0 https://chris48s.github.io/v8r/usage-examples/#files-containing-multiple-documents
I fell in love with LSPs using schemastore so I am trying to convince my devops team to use this project in their CI/CD for schema validation.
My target files was almost exclusively multidoc YAML files so I modified the cli.js and parser.js to support multidoc YAML files.
Would you want this functionality contributed back? If so, I can discuss further and open a PR.