-
Notifications
You must be signed in to change notification settings - Fork 11
feat(input_schema): Add propertyNames and patternProperties for object property
#580
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: master
Are you sure you want to change the base?
Conversation
…pertyNames` and `patternProperties` for object property
# Conflicts: # packages/json_schemas/schemas/input.schema.json # test/utilities.client.test.ts
patternKey and patternValue with propertyNames and patternProperties for object propertypropertyNames and patternProperties for object property
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.
Pull request overview
This PR adds support for propertyNames and patternProperties keywords to the input schema, enabling validation of object property names and values according to JSON Schema specification. These keywords are intended to replace the deprecated custom validation keywords patternKey and patternValue.
Key Changes:
- Added
propertyNamessupport to validate all object keys against a pattern regex - Added
patternPropertiessupport to validate all object values matching a pattern (currently limited to.*pattern with string type) - Extended validation logic to check regex patterns for the new keywords
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/json_schemas/schemas/input.schema.json | Adds JSON schema definitions for propertyNames and patternProperties, with references added to object field definitions |
| packages/input_schema/src/types.ts | Adds TypeScript type definitions for the new properties in ObjectFieldDefinition |
| packages/input_schema/src/input_schema.ts | Implements validation logic for regex patterns in new properties and adds error handling for propertyNames validation errors |
| packages/input_schema/src/intl.ts | Adds internationalization string for property name validation errors |
| test/input_schema.test.ts | Adds comprehensive tests for validating the new keywords, including error cases and type restrictions |
| test/utilities.client.test.ts | Adds integration tests verifying runtime validation behavior for both new keywords |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Looks good from a quick look, but I don't feel qualified to approve this PR |
Input schema:
propertyNamesandpatternPropertiessupportThis is the last step required (by https://github.com/apify/apify-core/issues/24338) to deprecate our custom validation keywords
patternKeyandpatternValuein the input schema, because they are not part of the JSON schema spec.More info about the deprecation is here: https://www.notion.so/apify/Deprecation-of-our-custom-validation-keywords-in-the-input-schema-2a9f39950a22800d9252ed2a6ee7521c?source=copy_link
Currently, for
arrayfields, these are already (very easily) replaceable with the sub-schema. But for object fields these two works differently:patternKeyvalidates all object keys against the pattern regexpatternValuevalidates all object values against the pattern regex...And there are validation keywords exactly for this use cases in the JSON schema spec.:
propertyNameshttps://json-schema.org/understanding-json-schema/reference/object#propertyNames
This validates all property names (keys) of the object against the pattern regex.
patternPropertieshttps://json-schema.org/understanding-json-schema/reference/object#patternProperties
This allows to validate a schema against all properties that match the pattern regex.
So to replace the
patternValuebehavior, we would need to define a schema like this:Pattern
.*says that this schema should validate all properties.patternPropertiesexactly to this shape. So there has to be always a single object property named.*with propertiestype(onlystring) andpattern(validates whether it's compilable regex). This can be relaxed later if there are use cases for that (define a different pattern to match properties, define a different validation keywords then pattern), but for now this is only for replacement of thepatternValuekeyword.