Skip to content

Conversation

@mfori
Copy link
Member

@mfori mfori commented Nov 28, 2025

Input schema: propertyNames and patternProperties support

This is the last step required (by https://github.com/apify/apify-core/issues/24338) to deprecate our custom validation keywords patternKey and patternValue in 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 array fields, these are already (very easily) replaceable with the sub-schema. But for object fields these two works differently:

  • patternKey validates all object keys against the pattern regex
  • patternValue validates all object values against the pattern regex

...And there are validation keywords exactly for this use cases in the JSON schema spec.:

propertyNames

https://json-schema.org/understanding-json-schema/reference/object#propertyNames

{
  "type": "object",
  "propertyNames": {
    "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
  }
}

This validates all property names (keys) of the object against the pattern regex.

patternProperties

https://json-schema.org/understanding-json-schema/reference/object#patternProperties

{
  "type": "object",
  "patternProperties": {
    "^S_": { "type": "string" },
    "^I_": { "type": "integer" }
  }
}

This allows to validate a schema against all properties that match the pattern regex.

So to replace the patternValue behavior, we would need to define a schema like this:

{
  "type": "object",
  "patternProperties": {
    ".*": {
      "type": "string",
      "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
    }
  }
}

Pattern .* says that this schema should validate all properties.

⚠️ Important: The current implementation limits the schema of patternProperties exactly to this shape. So there has to be always a single object property named .* with properties type (only string) and pattern (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 the patternValue keyword.

…pertyNames` and `patternProperties` for object property
# Conflicts:
#	packages/json_schemas/schemas/input.schema.json
#	test/utilities.client.test.ts
@mfori mfori self-assigned this Nov 28, 2025
@mfori mfori added the t-console Issues with this label are in the ownership of the console team. label Nov 28, 2025
@github-actions github-actions bot added this to the 128th sprint - Console team milestone Nov 28, 2025
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Nov 28, 2025
@mfori mfori changed the title feat(input_schema): Replace patternKey and patternValue with propertyNames and patternProperties for object property feat(input_schema): Add propertyNames and patternProperties for object property Nov 28, 2025
@mfori mfori marked this pull request as ready for review November 28, 2025 10:53
Copilot finished reviewing on behalf of mfori November 28, 2025 10:57
Copy link

Copilot AI left a 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 propertyNames support to validate all object keys against a pattern regex
  • Added patternProperties support 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.

@jancurn
Copy link
Member

jancurn commented Dec 1, 2025

Looks good from a quick look, but I don't feel qualified to approve this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-console Issues with this label are in the ownership of the console team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants