Skip to content

feat: validate enum values for properties and collections#204

Open
crisnahine wants to merge 3 commits intoseuros:masterfrom
crisnahine:fix/enum-validation-for-properties-and-collections
Open

feat: validate enum values for properties and collections#204
crisnahine wants to merge 3 commits intoseuros:masterfrom
crisnahine:fix/enum-validation-for-properties-and-collections

Conversation

@crisnahine
Copy link
Copy Markdown
Contributor

rebased and fixed version of #184 by @dark-panda.

adds enum validation for property and collection DSL on tools. properties use ActiveModel inclusion validation, collections use a custom ArrayEnumValidator that checks each item.

fix from the original: collection_definition.merge!(opts) was putting enum at the array level in the JSON Schema output. in JSON Schema, enum on an array means the entire value must be one of the listed values — not that each item should be. moved it to items where it belongs:

# before (wrong — enum on array level)
{ type: "array", items: { type: "string" }, enum: ["apple", "banana", "cherry"] }

# after (correct — enum on items)
{ type: "array", items: { type: "string", enum: ["apple", "banana", "cherry"] } }

also added nil guard in ArrayEnumValidator and cleaned up a stale comment.

dark-panda and others added 3 commits April 8, 2026 23:53
the original had collection_definition.merge!(opts) which put enum
at the array level. in JSON Schema, enum on an array means the entire
value must match — not that each item must be in the list. moved enum
to items where it belongs.

also: nil guard in ArrayEnumValidator, stale comment cleanup.
ArrayEnumValidator was placed after `return unless required`, so
non-required collections with enum never got validated. Moved it
before the guard. Also removed dead `allow_nil: !required` (always
false after the required guard).
@crisnahine crisnahine force-pushed the fix/enum-validation-for-properties-and-collections branch from 0291153 to f6fee3b Compare April 9, 2026 00:59
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