-
Notifications
You must be signed in to change notification settings - Fork 497
Fix fundamental schema issue with required fields defined incorrectly on JsonSchemaType #480
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?
Conversation
const isRequired = | ||
parentSchema?.required?.includes(propertyName || "") ?? false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the isPropertyRequired
helper here and avoid the duplication.
const isRequired = | |
parentSchema?.required?.includes(propertyName || "") ?? false; | |
const isRequired = isPropertyRequired(propertyName, parentSchema); |
const isPropertyRequired = schema.required?.includes(key) ?? false; | ||
if (isPropertyRequired) { | ||
const value = generateDefaultValue(prop, key, schema); | ||
if (value !== undefined) { | ||
obj[key] = value; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isPropertyRequired = schema.required?.includes(key) ?? false; | |
if (isPropertyRequired) { | |
const value = generateDefaultValue(prop, key, schema); | |
if (value !== undefined) { | |
obj[key] = value; | |
} | |
} | |
if (isPropertyRequired(key, schema)) { | |
const value = generateDefaultValue(prop, key, schema); | |
if (value !== undefined) { | |
obj[key] = value; | |
} | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a couple of places where isPropertyRequired
helper can be used.
Fixes a critical schema architecture problem identified by @max-stytch where the
JsonSchemaType
definition violated the JSON Schema specification.JsonSchemaType
incorrectly definedrequired
asboolean
on individual properties instead ofstring[]
array on parent object schema, leading to unexpected behavior in some tools testing scenarios and several open issues.Motivation and Context
Related observed issues:
prop.required
logic throughout the codebaseHow Has This Been Tested?
Did some basic testing but still working on more methodically testing the different scenarios. Thought it would be worth opening now for visibility's sake.
Breaking Changes
Technically yes due to internal API changes, however these all restore the correct behavior behind the scenes and don't require any changes on the user side:
generateDefaultValue()
function signature changed to includepropertyName
andparentSchema
parametersJsonSchemaType.required
changed fromboolean
tostring[]
prop.required
logic needed updatesTypes of changes
Checklist