Skip to content

feat(DCP-2527): add min/max validation for free_text and free_text_with_unit instructions#354

Merged
script-this merged 1 commit intomainfrom
DCP-2527-validation-min-max
Mar 16, 2026
Merged

feat(DCP-2527): add min/max validation for free_text and free_text_with_unit instructions#354
script-this merged 1 commit intomainfrom
DCP-2527-validation-min-max

Conversation

@script-this
Copy link
Copy Markdown
Contributor

@script-this script-this commented Mar 16, 2026

Summary

Adds optional validation field support for free_text and free_text_with_unit instruction types, enabling min/max bounds on user input. Validation logic is deferred to the backend — the CLI passes the field through and surfaces API errors directly.

Validation Schema

{
  "type": "number" | "string",
  "min": number | null,
  "max": number | null
}
  • free_text: validation is a top-level field on the instruction
  • free_text_with_unit: validation is per-unit_option (each unit can have different bounds)
  • type is required; min/max are nullable (null = unbounded in that direction)

Usage Examples

Collection JSON with free_text string validation (character count bounds):

{
  "order": 1,
  "type": "free_text",
  "description": "How was your experience completing this task?",
  "validation": {
    "type": "string",
    "min": 10,
    "max": 500
  }
}

Collection JSON with free_text_with_unit per-unit number validation:

{
  "order": 3,
  "type": "free_text_with_unit",
  "description": "What is your current weight?",
  "unit_options": [
    {
      "label": "KG",
      "value": "kg",
      "validation": { "type": "number", "min": 20, "max": 300 }
    },
    {
      "label": "Pounds",
      "value": "lbs",
      "validation": { "type": "number", "min": 44, "max": 660 }
    }
  ],
  "default_unit": "kg",
  "unit_position": "suffix"
}

Implementation

  • Added ValidationRule struct to model/collection.go and client/payloads.go
  • Added Validation field to Instruction, UnitOption, PageInstruction, and CollectionPageItem structs
  • Min/Max use *float64 without omitempty — backend requires explicit null (not field absence) for unbounded values
  • No CLI-side validation — backend is the single source of truth for validation rules
  • Updated example files with validation usage

Testing

Unit tests:

  • Passthrough tests for number and string validation on free_text instructions
  • Passthrough test for free_text_with_unit with per-unit-option validation
  • Validation with only type specified (no min/max)
  • Explicit null validation handled correctly

Manually verified against dev:

  • free_text with string validation (min/max char count) — created successfully
  • free_text_with_unit with per-unit number validation — created successfully
  • Unbounded max (null) — created successfully
  • Invalid validation type — backend error surfaced correctly
  • min > max — backend error surfaced correctly
  • DynamoDB records confirmed all validation fields persisted correctly

@prolific-snyk
Copy link
Copy Markdown

prolific-snyk commented Mar 16, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@script-this script-this force-pushed the DCP-2527-validation-min-max branch from a02a78f to 970b5e8 Compare March 16, 2026 14:57
…th_unit instructions

Add ValidationRule struct and Validation field to support optional
min/max bounds on free_text (instruction-level) and free_text_with_unit
(per unit_option) instruction types. Validation logic is deferred to
the backend; the CLI passes the field through and surfaces API errors.
@script-this script-this force-pushed the DCP-2527-validation-min-max branch from 970b5e8 to 77b7886 Compare March 16, 2026 15:23
@script-this script-this marked this pull request as ready for review March 16, 2026 15:42
@script-this script-this requested a review from a team as a code owner March 16, 2026 15:42
@script-this script-this added team-dct dct-ready-for-review Triggers Slack notification when PR is ready for review labels Mar 16, 2026
@script-this script-this merged commit 7a5c676 into main Mar 16, 2026
8 checks passed
@script-this script-this deleted the DCP-2527-validation-min-max branch March 16, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dct-ready-for-review Triggers Slack notification when PR is ready for review team-dct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants