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:

  1. Read .component.yml.
  2. Parse YAML using Drupal core’s Yaml::parse() service.
  3. Convert to JSON-equivalent data.
  4. Pass the decoded data to the existing json_schema_validator validation pipeline.
Command icon 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

lukus created an issue. See original summary.

lukus’s picture

Issue summary: View changes
lukus’s picture

Thinking about this, might need to change the name to schema_validator though :)

ptmkenny’s picture

Yes, 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.

ptmkenny’s picture

So 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.

ptmkenny’s picture

I 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.

ptmkenny’s picture

Title: YAML validation » add support for YAML validation
ptmkenny’s picture

I am going to commit this now. If you have more suggestions for improvements feel free to open another issue.

  • ptmkenny committed e8020a75 on 1.0.x
    feat: #3548888 add support for YAML validation
    
    By: lukus
    By: ptmkenny
    
ptmkenny’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.