Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automated validation for JSON schemas #230

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

ajlende
Copy link
Collaborator

@ajlende ajlende commented Jul 16, 2024

Description

Adds a GitHub action for validating JSON files with schemas that are modified in a PR.

Validating only the changed files allows for themes to be incrementally fixed without blocking other themes.

Expand to see the full list of existing errors.
[
  {
    file: './atlas/theme.json',
    schema: 'https://schemas.wp.org/wp/6.3/theme.json',
    error: [
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/properties/spacing/properties/blockGap/oneOf/0/type',
        keyword: 'type',
        params: { type: 'string' },
        message: 'must be string'
      },
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/definitions/refComplete/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      },
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/properties/spacing/properties/blockGap/oneOf',
        keyword: 'oneOf',
        params: { passingSchemas: null },
        message: 'must match exactly one schema in oneOf'
      },
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/properties/spacing/properties/blockGap/oneOf/0/type',
        keyword: 'type',
        params: { type: 'string' },
        message: 'must be string'
      },
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/definitions/refComplete/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      },
      {
        instancePath: '/styles/blocks/core~1navigation/spacing/blockGap',
        schemaPath: '#/properties/spacing/properties/blockGap/oneOf',
        keyword: 'oneOf',
        params: { passingSchemas: null },
        message: 'must match exactly one schema in oneOf'
      }
    ]
  },
  {
    file: './blue-note/theme.json',
    schema: 'https://schemas.wp.org/wp/6.2/theme.json',
    error: [
      {
        instancePath: '/styles/elements',
        schemaPath: '#/additionalProperties',
        keyword: 'additionalProperties',
        params: { additionalProperty: 'textarea' },
        message: 'must NOT have additional properties'
      },
      {
        instancePath: '/styles/elements',
        schemaPath: '#/additionalProperties',
        keyword: 'additionalProperties',
        params: { additionalProperty: 'input' },
        message: 'must NOT have additional properties'
      }
    ]
  },
  {
    file: './stacks/theme.json',
    schema: 'https://schemas.wp.org/trunk/theme.json',
    error: [
      {
        instancePath: '/version',
        schemaPath: '#/properties/version/const',
        keyword: 'const',
        params: { allowedValue: 3 },
        message: 'must be equal to constant'
      },
      {
        instancePath: '/styles/elements/h1/typography/lineHeight',
        schemaPath: '#/properties/typography/properties/lineHeight/oneOf/0/type',
        keyword: 'type',
        params: { type: 'string' },
        message: 'must be string'
      },
      {
        instancePath: '/styles/elements/h1/typography/lineHeight',
        schemaPath: '#/definitions/refComplete/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      },
      {
        instancePath: '/styles/elements/h1/typography/lineHeight',
        schemaPath: '#/properties/typography/properties/lineHeight/oneOf',
        keyword: 'oneOf',
        params: { passingSchemas: null },
        message: 'must match exactly one schema in oneOf'
      },
      {
        instancePath: '/styles/elements/h2/typography/lineHeight',
        schemaPath: '#/properties/typography/properties/lineHeight/oneOf/0/type',
        keyword: 'type',
        params: { type: 'string' },
        message: 'must be string'
      },
      {
        instancePath: '/styles/elements/h2/typography/lineHeight',
        schemaPath: '#/definitions/refComplete/type',
        keyword: 'type',
        params: { type: 'object' },
        message: 'must be object'
      },
      {
        instancePath: '/styles/elements/h2/typography/lineHeight',
        schemaPath: '#/properties/typography/properties/lineHeight/oneOf',
        keyword: 'oneOf',
        params: { passingSchemas: null },
        message: 'must match exactly one schema in oneOf'
      }
    ]
  },
  {
    file: './tt1-blocks/theme.json',
    schema: undefined,
    error: [
      {
        instancePath: '',
        schemaPath: '#/required',
        keyword: 'required',
        params: { missingProperty: '$schema' },
        message: "must have required property '$schema'"
      }
    ]
  }
]

Screenshot

I made some test changes so you could see an example of failing changes in #231.

image

Testing

This can be tested locally with https://github.com/nektos/act.

act -s GITHUB_TOKEN="$(gh auth token)" pull_request -j validate-schema

@ajlende ajlende added the enhancement New feature or request label Jul 16, 2024
@ajlende ajlende self-assigned this Jul 16, 2024
@ajlende ajlende force-pushed the add/github-ci-validation branch 16 times, most recently from a4e4474 to a2a5272 Compare July 30, 2024 23:11
@ajlende ajlende changed the title Add automated validation for json schemas Add automated validation for JSON schemas Jul 31, 2024
@ajlende ajlende marked this pull request as ready for review July 31, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant