work-hub-server/openspec/changes/archive/2026-06-04-add-shared-schema-package/specs/validation/spec.md
Nicolas HOARAU 9190908062 docs: archive completed changes
Archive add-shared-schema-package and swap-superstruct-valibot changes to openspec/changes/archive/
2026-06-04 12:49:12 +04:00

1.5 KiB

ADDED Requirements

Requirement: Define Superstruct validators for data shapes

The package SHALL export Superstruct schema definitions for validating runtime data shapes (request payloads, configuration objects, etc.).

Scenario: Validator validates correct data

  • WHEN data matching the schema is passed to the validator
  • THEN the validator SHALL return the validated data without throwing

Scenario: Validator rejects invalid data

  • WHEN data not matching the schema is passed to the validator
  • THEN the validator SHALL throw a StructError with details about the validation failure

Requirement: Validator composability

Superstruct schemas SHALL be composable — schemas can reference other schemas for nested object validation.

Scenario: Nested object validation

  • WHEN a schema defines a nested object field using another Superstruct schema
  • THEN the nested schema SHALL be applied during validation of the parent

Requirement: Optional and default fields

Superstruct schemas SHALL support optional fields (optional()) and fields with default values (defaulted()) for partial updates or configuration defaults.

Scenario: Optional field omitted

  • WHEN an optional field is omitted from input data
  • THEN the validator SHALL accept the data and not require the field

Scenario: Default value applied

  • WHEN a field with a default value is omitted from input data
  • THEN the validator SHALL apply the default value in the returned data