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

feat: don't require full top-level validation in non-cyclic-non-top-level refs #162

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

ChALkeR
Copy link
Contributor

@ChALkeR ChALkeR commented Aug 8, 2023

Refs: #161 (comment)

This will allow e.g. this to compile in strong mode:

  {
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    allOf: [
      {
        $ref: '#/definitions/base',
      },
    ],
    definitions: {
      base: {
        required: [],
        properties: {
          version: {
            const: '2',
          },
        },
        type: 'object',
       //  unevaluatedProperties: false,
      },
    },
    properties: {
      type: {
        const: 'acknowledge',
      },
    },
    required: ['type'],
    type: 'object',
    unevaluatedProperties: false,
  }

@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 6 times, most recently from e629094 to 8241ba2 Compare August 8, 2023 22:47
@ChALkeR ChALkeR changed the title wip: don't ensure full top-level validation in refs feat: don't require full top-level validation in not top-level refs Aug 8, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 8, 2023

Codecov Report

Merging #162 (3167a72) into master (287f3a8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Files Changed Coverage Δ
src/compile.js 99.26% <100.00%> (+<0.01%) ⬆️

@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 2 times, most recently from 45d7ad4 to c5831fe Compare August 8, 2023 22:58
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 8, 2023

@RichAyotte this should be ready now

@ChALkeR ChALkeR marked this pull request as ready for review August 8, 2023 22:59
@RichAyotte
Copy link

RichAyotte commented Aug 9, 2023

I've checkout the branch and ran a few tests and observed a few new behaviours.

When a $ref is specified without unevaluatedProperties, I get the following error: [requireValidation] additionalProperties or unevaluatedProperties should be specified at #/properties/bh1

      "properties": {
        "kind": {
          "const": "double_baking_evidence"
        },
        "bh1": {
          "$ref": "#/definitions/TezosBlockHeader"
        },
        "bh2": {
          "$ref": "#/definitions/TezosBlockHeader"
        }

Adding unevaluatedProperties to each item resolves the issue.

      "properties": {
        "kind": {
          "const": "double_baking_evidence"
        },
        "bh1": {
          "unevaluatedProperties": false,
          "$ref": "#/definitions/TezosBlockHeader"
        },
        "bh2": {
          "unevaluatedProperties": false,
          "$ref": "#/definitions/TezosBlockHeader"
        }
      }

The second new behaviour is with items. The errors are [requireValidation] items rule should be specified at #/oneOf/3/items and [requireValidation] items rule should be specified at #/oneOf/3/properties/args/items for the following:

    "MichelineMichelsonV1Expression": {
      "type": ["array", "object"],
      "oneOf": [
       ...// removed 3 irrelevant items here
        {
          "type": "array",
          "items": {
            "$ref": "#/definitions/MichelineMichelsonV1Expression"
          }
        },
        {
          "type": "object",
          "properties": {
            "prim": {
              "type": "string",
              "maxLength": 256,
              "format": "anyString"
            },
            "args": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/MichelineMichelsonV1Expression"
              }
            },
            "annots": {
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 256,
                "format": "anyString"
              }
            }
          }
        }
      ]
    }

@RichAyotte
Copy link

I forgot to add, the changes here resolve issue #161 🚀

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

Re: refs -- thanks!

Yes, this did change the behavior -- previously, all $refs were checked to be fully validating everything on their own, and now that check was removed, but together with corresponding assumption that $refs fully validate everything`.

I'll take a closer look at/investigate schemas that were previously compiling and now don't due to this.

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

Yes, I see a regression on

validator(
  {
    $schema: 'http://json-schema.org/draft-07/schema#',
    $defs: {
      A: {
        type: ['array', 'object'],
        oneOf: [
          {
            type: 'array',
            items: {
              $ref: '#/$defs/A'
            }
          },
          {
            type: 'object',
            required: [],
            additionalProperties: false,
            properties: {}
          }
        ]
      }
    },
    $ref: '#/$defs/A'
  },
  { mode: 'strong' }
)

Looks like we need actual propagation for cyclic refs.

I assume that bh1/bh2 in the first example are also cyclic? Because there should be proper tracing for non-cyclic refs that works independent on the change here.

@RichAyotte
Copy link

I'm not sure what cyclic means here but here's the bh1/bh2 sample with more context.

    "TezosDoubleBakingEvidenceOperation": {
      "type": "object",
      "allOf": [{ "$ref": "#/definitions/TezosBaseOperation" }],
      "required": ["kind", "bh1", "bh2"],
      "properties": {
        "kind": {
          "const": "double_baking_evidence"
        },
        "bh1": {
          "unevaluatedProperties": false,
          "$ref": "#/definitions/TezosBlockHeader"
        },
        "bh2": {
          "unevaluatedProperties": false,
          "$ref": "#/definitions/TezosBlockHeader"
        }
      }
    },

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

That doesn't look like a regression.

Perhaps we could enable the new behavior as an opt-in or only on non-cyclic refs to avoid regressions

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

@RichAyotte updated

@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 3 times, most recently from 8ba7df8 to 3167a72 Compare August 9, 2023 04:39
@ChALkeR ChALkeR changed the title feat: don't require full top-level validation in not top-level refs feat: don't require full top-level validation in non-cyclic-non-top-level refs Aug 9, 2023
@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 6 times, most recently from c2f743a to d9f4f2b Compare August 9, 2023 12:29
@RichAyotte
Copy link

Everything looks really good now and all my tests pass. Thanks for putting this patch together so quickly 🙏

@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 3 times, most recently from b1b3fef to 113ef14 Compare August 9, 2023 13:51
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

@RichAyotte I added more tests/safeguards and fixed an issue that detected.
This should be ready/final now.

@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch 2 times, most recently from bf925e6 to 4e90ceb Compare August 9, 2023 13:59
This will allow application of partial refs that would be revalidated
separately on the top-level.
@ChALkeR ChALkeR force-pushed the chalker/ref-not-full-validation branch from 4e90ceb to dc6f3ce Compare August 9, 2023 13:59
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

(lint fixes / code formatting only in the last pushes)

@ChALkeR ChALkeR self-assigned this Aug 9, 2023
@RichAyotte
Copy link

Everything still looks good 👍

@ChALkeR ChALkeR merged commit f61aeb8 into master Aug 9, 2023
10 checks passed
@ChALkeR ChALkeR deleted the chalker/ref-not-full-validation branch August 9, 2023 14:06
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

Merged and published as @exodus/[email protected].

@ChALkeR
Copy link
Contributor Author

ChALkeR commented Aug 9, 2023

Upd: use @exodus/[email protected] instead 🤦🏻 (I should have tested the unrelated commit before including it in the release)

@RichAyotte
Copy link

I'm glad you found it and I just tested with v1.2.2 and it works well.

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

Successfully merging this pull request may close these issues.

3 participants