fix(select): add empty string as option when not required#40
Open
Dominik Kadera (dominikkadera) wants to merge 4 commits intomainfrom
Open
fix(select): add empty string as option when not required#40Dominik Kadera (dominikkadera) wants to merge 4 commits intomainfrom
Dominik Kadera (dominikkadera) wants to merge 4 commits intomainfrom
Conversation
Copilot started reviewing on behalf of
Dominik Kadera (dominikkadera)
March 6, 2026 12:51
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for using '' as the “no selection” value for non-required select-like fields to better align generated JSON Schema with common form submission semantics, while updating tests and roundtrip behavior accordingly.
Changes:
- Update JSON Schema generation to prepend
''as an allowed option for non-required select-like fields and setdefault: ''(plus a standard description when none is provided). - Update validator logic to treat
''as an empty value (and handle placeholder-nested selects with''as “no selection”). - Add/adjust Jest test coverage (including a new spec file) for schema generation, validation, and roundtrip behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/forman.ts |
Injects empty-string option/default/description for non-required select-like fields; changes placeholder-nested injected option from null to ''. |
src/validator.ts |
Treats '' as an empty value and extends placeholder-nested select handling to support ''. |
src/json.ts |
Attempts to prevent roundtrip leakage by filtering out injected '' option and hiding the injected description when converting back to Forman schema. |
test/empty-select-option.spec.ts |
New tests for schema generation, validation, and roundtrip behavior around optional empty-string select options. |
test/placeholder-nested.spec.ts |
Updates placeholder-nested schema expectations to use '' and adds validation coverage for empty-string. |
test/validator-extended.spec.ts |
Updates expectations so optional empty file path '' is treated as valid. |
test/test.spec.ts |
Updates expected schema fragments to include default: '' and description for optional select-like fields. |
test/directives/rpc.spec.ts |
Updates expected JSON schema output for RPC-backed selects to include default: '' and description. |
test/directives/nested.spec.ts |
Updates expected nested directive schemas to include empty option/default/description for non-required select-like fields. |
test/directives/grouped.spec.ts |
Updates expected grouped select schemas to include empty option/default/description. |
test/composites/udttype.spec.ts |
Updates expected option count and default for udttype composite select output. |
test/composites/__snapshots__/udttype.spec.ts.snap |
Snapshot updated for injected empty option/default in udttype output. |
Comments suppressed due to low confidence (1)
src/validator.ts:318
- This change makes
''behave like “no value” for all optional fields (not just selects): the validator returnsvalid: trueearly and skips type checks and field-level validations (pattern/min/max/etc). If the intent is only to support empty-string for non-required selects (and path-like selectors), consider narrowing this condition to those field types; otherwise, add focused tests that assert the new empty-string semantics for other optional field types with validations.
if (value == null || value === '') {
// When a select field has placeholder.nested, null/'' means "no selection" and we need to validate the nested fields
if (normalizedField.type === 'select' && hasPlaceholderNested(normalizedField)) {
return handleSelectType(value, normalizedField, context);
}
return {
valid: true,
errors: [],
};
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for
''to be valid option of non-required selects as it prevents mishaps with JSON Schema alignments.