Repository navigation
fix(to-json-schema): do not require optional items at the end of tuples #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -305,11 +305,22 @@ export function convertSchema( | |||||||
| case 'strict_tuple': { | ||||||||
| jsonSchema.type = 'array'; | ||||||||
|
|
||||||||
| // Get minimum number of items | ||||||||
| // Hint: Optional items at the end of a tuple can be omitted | ||||||||
| let minItems = valibotSchema.items.length; | ||||||||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||||||||
| while ( | ||||||||
| minItems > 0 && | ||||||||
| (valibotSchema.items[minItems - 1].type === 'optional' || | ||||||||
| valibotSchema.items[minItems - 1].type === 'nullish') | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Trailing Prompt for AI agents
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept |
||||||||
| ) { | ||||||||
| minItems--; | ||||||||
|
Comment on lines
+311
to
+316
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
| } | ||||||||
|
|
||||||||
| // If target is OpenAPI 3.0 | ||||||||
| if (config?.target === 'openapi-3.0') { | ||||||||
| // Uses anyOf pattern with minItems/maxItems | ||||||||
| jsonSchema.items = { anyOf: [] }; | ||||||||
| jsonSchema.minItems = valibotSchema.items.length; | ||||||||
| jsonSchema.minItems = minItems; | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||
| for (const item of valibotSchema.items) { | ||||||||
| // @ts-expect-error | ||||||||
| jsonSchema.items.anyOf.push( | ||||||||
|
|
@@ -341,7 +352,7 @@ export function convertSchema( | |||||||
| } else if (config?.target === 'draft-2020-12') { | ||||||||
| // Use prefixItems for draft-2020-12 | ||||||||
| jsonSchema.prefixItems = []; | ||||||||
| jsonSchema.minItems = valibotSchema.items.length; | ||||||||
| jsonSchema.minItems = minItems; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
| for (const item of valibotSchema.items) { | ||||||||
| jsonSchema.prefixItems.push( | ||||||||
| convertSchema({}, item as SchemaOrPipe, config, context) | ||||||||
|
|
@@ -364,7 +375,7 @@ export function convertSchema( | |||||||
| } else { | ||||||||
| // Use items array for draft-07 | ||||||||
| jsonSchema.items = []; | ||||||||
| jsonSchema.minItems = valibotSchema.items.length; | ||||||||
| jsonSchema.minItems = minItems; | ||||||||
| for (const item of valibotSchema.items) { | ||||||||
| jsonSchema.items.push( | ||||||||
| convertSchema({}, item as SchemaOrPipe, config, context) | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.