Skip to content

feat: add unevaluatedItems lesson for closing tuples (#61)#210

Open
Avanish-Gupta-CSE wants to merge 2 commits intojson-schema-org:mainfrom
Avanish-Gupta-CSE:feat/issue-61-unevaluatedItems-lesson
Open

feat: add unevaluatedItems lesson for closing tuples (#61)#210
Avanish-Gupta-CSE wants to merge 2 commits intojson-schema-org:mainfrom
Avanish-Gupta-CSE:feat/issue-61-unevaluatedItems-lesson

Conversation

@Avanish-Gupta-CSE
Copy link

@Avanish-Gupta-CSE Avanish-Gupta-CSE commented Jan 27, 2026

What kind of change does this PR introduce?

Feature - Adds a new lesson for the unevaluatedItems keyword.

Issue Number:

Screenshots/videos:

N/A - This is a new lesson file (MDX content + code.ts with test cases).

If relevant, did you update the documentation?

N/A - This PR adds lesson content, not documentation.

Summary

Adds a new lesson demonstrating the proper use case for unevaluatedItems - closing a tuple defined in a referenced schema.

This addresses the issue where the original lesson could be solved with items instead of unevaluatedItems. The new lesson:

  • Uses $ref to reference a base tuple (coordinate pair with lat/long)
  • Demonstrates closing the tuple with unevaluatedItems: false
  • Explains why items cannot achieve this when using schema composition

This matches the approach approved by @jdesrosiers in the issue discussion.

Lesson Files Added:

  • content/07-Miscellaneous/02-Extending-Closed-Tuples-with-unevaluatedItems/instructions.mdx
  • content/07-Miscellaneous/02-Extending-Closed-Tuples-with-unevaluatedItems/code.ts

Test Cases: 9 comprehensive test cases covering valid coordinate tuples and invalid scenarios (extra items, wrong types).

Does this PR introduce a breaking change?

No.

)

This lesson demonstrates the proper use case for unevaluatedItems:
- Closing a tuple defined in a referenced schema using $ref
- Why items cannot achieve this with schema composition
- The difference between items and unevaluatedItems

Example: A coordinate tuple (lat, long) that needs to be closed
to prevent extra items like altitude.

Fixes json-schema-org#61
Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this is a correct and real world use case of JSON Schema. There's just one thing that I think can be worded better (details inline).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"any part of the schema" isn't quite right. Or, at least, it's a little misleading. I don't know the best way to explain it, but this example should illustrate what I mean.

{
  "allOf": [
    { "$ref": "#/$defs/coordinate" },
    { "unevaluatedItems": false }
  ],

  "$defs": {
    "coordinate": {
      "type": "array",
      "prefixItems": [
        { "type": "number" },
        { "type": "number" }
      ]
    }
  }
}

unevaluatedItems doesn't "see" the prefixItems in this case. It only "sees" the prefixItems "below" it in the schema. (Although because $ref allows you to jump around the schema it isn't always clear what "below" means). Hope that helps.

@Avanish-Gupta-CSE
Copy link
Author

Avanish-Gupta-CSE commented Jan 29, 2026

Thanks for the review !
I updated the wording to clarify that unevaluatedItems only uses annotations from the same evaluation path (subschemas "below" it) and noted the allOf-branch case. Pushed in c3755b4.

Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks better. Thanks for updating. I'll leave the other aspects of the review to the actual maintainers of this project.

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.

The unevaluatedItems lesson needs work

2 participants

Comments