Problem/Motivation
Some schema definitions in the ecosystem (e.g. SDC .component.yml files) are stored in YAML format instead of JSON.
Currently, the json_schema_validator module only supports JSON input, which makes direct validation of .yml-based schemas impossible without additional conversion.
Proposed resolution
Extend json_schema_validator (or provide an option) to also support validating YAML-based files.
Suggested approach:
- Read
.component.yml. - Parse YAML using Drupal core’s
Yaml::parse()service. - Convert to JSON-equivalent data.
- Pass the decoded data to the existing
json_schema_validatorvalidation pipeline.
Issue fork json_schema_validator-3548888
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
lukusComment #3
lukusThinking about this, might need to change the name to
schema_validatorthough :)Comment #4
ptmkenny commentedYes, this seems like a good feature request. I think we can keep the name because we are validating against a JSON schema even if the content is YML.
I'm not up-to-date on this, but core is also adding config schema validation. We should probably check what approach they are using; core may be providing more tools to make this easier for everyone.
Comment #5
ptmkenny commentedSo it seems like config validation isn't doing much with JSON Schema, but single directory components do use JSON schema validation with justinrainbow... which still doesn't fully support JSON schema v7, and doesn't support newer schemas at all.
Therefore, I will continue to work on this module.
Comment #6
ptmkenny commentedI think the way to implement this is to create a new interface that provides all the same methods as JsonSchemaValidatorInterface but allows YAML (file or raw YAML) input. That way, if you're working with JSON, you can call the JSON interface directly, and if you're working with YAML, you can call the YAML interface. In either case, the methods are the same.
Comment #8
ptmkenny commentedComment #9
ptmkenny commentedI am going to commit this now. If you have more suggestions for improvements feel free to open another issue.
Comment #11
ptmkenny commented