work-hub-server/openspec/changes/add-shared-schema-package/specs/validation/spec.md
Nicolas HOARAU d1dbf3fe77 docs(schema): Documentation of first change
Creation of specs for openspec and opencode to start working
2026-06-04 10:58:36 +04:00

39 lines
1.5 KiB
Markdown

## 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