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

Build time throw for Github Workflow schema #158

Closed
Aplietexe opened this issue Apr 7, 2023 · 6 comments
Closed

Build time throw for Github Workflow schema #158

Aplietexe opened this issue Apr 7, 2023 · 6 comments
Labels
question Issues that look for answers.

Comments

@Aplietexe
Copy link

When trying to use the GitHub Workflow schema from schemastore, an error is thrown at build time:

Error: Unprocessed keywords: ["properties"] at #/properties/on/oneOf/2/properties/branch_protection_rule

Perhaps it is because "properties" is present although branch_protection_rule is either an object or null. In any case, that is fine according to the metaschema, and seems to be a common practice to reduce duplication.

Example:

import { validator } from '@exodus/schemasafe'
// https://json.schemastore.org/github-workflow.json
import schema from './schema.js'

validator(schema)

schema.js simply export defaults the schema from the link.

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 27, 2023

There is an option to silence schema mistakes: https://github.com/ExodusMovement/schemasafe/blob/master/doc/Options.md#options-for-relaxing-coherence-checks

Does the schema succeed in lax mode?
validator(schema, { allowUnusedKeywords: true }) (and validator(schema, { mode: 'lax' })) seems to pass, I re-checked.

@ChALkeR ChALkeR added the question Issues that look for answers. label Jul 27, 2023
@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 27, 2023

Ah. Upon a closer look, the mistake in the schema is a significant one!
This schema is invalid and doesn't do what it's supposed to do.

Consider the following parts of the schema you provided:

"$schema": "http://json-schema.org/draft-07/schema#",
            "branch_protection_rule": {
              "$comment": "https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#branch_protection_rule",
              "$ref": "#/definitions/eventObject",
              "description": "Runs your workflow anytime the branch_protection_rule event occurs. More than one activity type triggers this event.",
              "properties": {
                "types": {
                  "$ref": "#/definitions/types",
                  "items": {
                    "type": "string",
                    "enum": ["created", "edited", "deleted"]
                  },
                  "default": ["created", "edited", "deleted"]
                }
              }

But in draft-07, unlike later ones, $ref makes all sibling keywords ignored: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3

image

Upstream testsuite: https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/8cdfac41e37527795879e480a483997cbd6188f3/tests/draft7/ref.json#L145-L177

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 27, 2023

The proper fix is to update the schema version to "$schema": "https://json-schema.org/draft/2019-09/schema" or later, otherwise any compliant validator MUST ignore the sibling property keywords and those don't actually validate anything. Schemasafe just makes that mistake visible by default.

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 27, 2023

@Aplietexe I reported this bug here: SchemaStore/schemastore#3102

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 27, 2023

Closing as answered, this is a problem with schemastore schemas being incorrect (though technically valid, but not doing what they are intended to do).

This check can be silenced via options, but I wouldn't recommend that -- a proper way would be to actually fix the schema.

@ChALkeR ChALkeR closed this as completed Jul 27, 2023
@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 28, 2023

A separate linter mode is introduced in 1.1.0/1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants