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

fix: typebox object schemas without properties key #903

Merged

Conversation

0xthierry
Copy link
Contributor

This PR fixes a TypeError in hasAdditionalProperties when handling intersection types that include a TypeBox Record. The function fails when processing schemas that have type: "object" but no properties key.

Issue

When using an intersection (Type.Intersect) with a Record type from TypeBox, the generated schema is a valid JSON Schema object using allOf, but lacks a properties key in some of its subschemas. This causes hasAdditionalProperties to throw a TypeError when attempting to access the properties field.

Example schema that triggers the bug:

{
  "allOf": [
    {
      "type": "object",
      "properties": {
        "a": {
          "type": "string"
        }
      },
      "required": ["a"]
    },
    {
      "type": "object",
      "patternProperties": {
        "^(0|[1-9][0-9]*)$": {
          "type": "string"
        }
      }
    }
  ]
}

Tests

Added test case for intersection of object + record types
Verified handling of schemas with missing properties key

@SaltyAom SaltyAom merged commit a3ed6c1 into elysiajs:main Oct 31, 2024
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.

2 participants