oxidecomputer / oxidecomputer/typify

Bug when using `prefixItems` + `items: false` + `default` in JSON Schema

Open
#955 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

When defining a JSON Schema that combines prefixItems, items: false, and a default value for an array, and referencing it via $ref, the library fails to process the schema.
The schema is valid according to JSON Schema 2020-12, but triggers an internal error in the library.
Removing any one of these three elements prevents the bug.

Steps to Reproduce

Original schema causing the bug: schema_cat.json
Minimal schema that still triggers the bug:

{
  "$defs": {
    "T": {
      "type": "object",
      "properties": {
        "x": {
          "type": "array",
          "prefixItems": [
            { "type": "integer" }
          ],
          "items": false,
          "default": [0]
        }
      }
    }
  },
  "$ref": "#/$defs/T"
}

This works correctly (no error) when $ref is not used:

{
  "type": "object",
  "properties": {
    "x": {
      "type": "array",
      "prefixItems": [
        { "type": "integer" }
      ],
      "items": false,
      "default": [0]
    }
  }
}

Using typify::import_types! and passing in either schema fails at comptime with error: value does not conform to the given schema.

Expected Behavior

The library should correctly parse the schema and validate default values.

Observed Behavior

The library throws an error or fails to process the schema when all three conditions (prefixItems, items: false, default) are present and used via $ref.

Environment
  • typify 0.5.0
  • rustc 1.92.0

I think that's all I could find out via my testing, let me know if anything else could be of use in debugging this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the comptime failure with the minimal schema and typify::import_types!; compare it with the equivalent schema without $ref. Trace the schema import and default-value validation paths, then confirm that both forms parse successfully and validate the [0] default without an internal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.