Skip to content

Required properties with default values are treated as optional during validation #705

@endrit-gjocaj

Description

@endrit-gjocaj

Summary

In Corvus.JsonSchema, a property that is missing but has a default value can cause validation to pass, even when that property is listed in required.
But per JSON Schema, default is an annotation and must not be used during validation.

Reference (JSON Schema annotations):
https://json-schema.org/understanding-json-schema/reference/annotations

Expected

If a property is in required, validation should fail when the property is not present in the instance JSON - regardless of default.

Actual

If the missing required property has a default, validation passes (as if it were optional).

This makes: required + default behave like optional + default

Reproduction Scenarios

  1. Not required, no default values
    Request:
{
  "externalProperties": {}
}

✅ Validation passes
✅ External Properties empty
✔️ Correct behavior

  1. Not required, with default values
    Request:
{
  "externalProperties": {}
}

✅ Validation passes
✅ External Properties empty
✔️ Correct behavior

  1. Required, no default values
    Request:
{
  "externalProperties": {}
}

❌ Validation fails
❌ External Properties not created
✔️ Correct behavior

  1. Required, with default values
    Request:
{
  "externalProperties": {}
}

✅ Validation passes
❌ External Properties empty
❌ Incorrect behavior

Scenario 4 behaves the same as scenario 2, but it should behave the same as scenario 3.

Why this matters

This breaks JSON Schema semantics because default should be documentation-only and must not change validation behavior.

Scenarios with screenshots:

Scenario 3

Image Image Image

Scenario 4

Image Image Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions