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

type requirement in metaschema-draft-07-unofficial-strict.json #4031

Open
Vampire opened this issue Aug 29, 2024 · 2 comments
Open

type requirement in metaschema-draft-07-unofficial-strict.json #4031

Vampire opened this issue Aug 29, 2024 · 2 comments
Labels
issue:bug Report errors or unexpected behavior (auto-generated by issue forms) question

Comments

@Vampire
Copy link
Contributor

Vampire commented Aug 29, 2024

Area with issue?

JSON Schema

✔️ Expected Behavior

This might either just be a question, or a bug report.
Sorry if it turns out to just be a question, but I didn't find a more appropriate place to ask as discussions are not enabled and no chat or similar is linkes anywhere.

I'm writing a schema right now.
I've sent it through the metaschema-draft-07-unofficial-strict.json.
This complained at some places that the type is missing.

I for example have

"list-item": {
  "title": "...",
  "description": "...",
  "allOf": [
    { "$ref": "#/definitions/list_item_type" },
    {
      "anyOf": [
        { "$ref": "#/definitions/simple_primitive_property" },
        { "$ref": "#/definitions/integer_with_named_values_property" },
        { "$ref": "#/definitions/enum_property" }
      ]
    }
  ]
}

All those ref-ed schemas define the type to be object.
If I validate a file against the schema where list-item is set to a string I correctly get a complaint from Ajv and IntelliJ that the type must be object.

But the metaschema-draft-07-unofficial-strict.json requires me to change this to

"list-item": {
  "title": "...",
  "description": "...",
  "type": "object",
  "allOf": [
    { "$ref": "#/definitions/list_item_type" },
    {
      "anyOf": [
        { "$ref": "#/definitions/simple_primitive_property" },
        { "$ref": "#/definitions/integer_with_named_values_property" },
        { "$ref": "#/definitions/enum_property" }
      ]
    }
  ]
}

This does not change much, except that the schemaPath in the Ajv output is different.

Is this expected and intentional?
Is this a shortcoming of the meta schema?
Can it just not know that the type would be coming from the ref-ed schema and thus has to complain to not miss other cases?

Are you making a PR for this?

No, someone else must create the PR.

@EmilyGraceSeville7cf
Copy link
Contributor

AFAIR I wanted to make type to be specified explicitly as much as possible. The idea behind it was to make the writing schema more straightforward, without a lot of references between subschemas, to let people read schema from top to bottom without a lot of jumps between schemas. I think it can be improved though 😄.

@hyperupcall
Copy link
Member

hyperupcall commented Aug 30, 2024

Yeah it's a shortcoming of the metaschema. In my opinion this is is a bug because it doesn't improve the text to be more readable or correct, since it does not change how the object is interpreted. (since for drafts 4-7, objects with $refs are treated like references and not schemas). And this makes the AJV schemaPath misleading. Doing this also makes the schemas less DRY and prone to go out of sync (and detecting this mismatch does not seem to be detectable with AJV strict mode).

@hyperupcall hyperupcall added the issue:bug Report errors or unexpected behavior (auto-generated by issue forms) label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue:bug Report errors or unexpected behavior (auto-generated by issue forms) question
Projects
None yet
Development

No branches or pull requests

3 participants