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
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

@gippy gippy removed the request for review from jancurn December 3, 2025 15:45
@mfori
Copy link
Member Author

mfori commented Dec 10, 2025

@metalwarrior665
Copy link
Member

Are there some real-world use-cases for this? I think we only used these for arrays where it is easily fixable already? Considering the complexity of the input schema, if we don't need a feature, we probably shouldn't introduce it.

A middle ground might be to just list the supported JSON schema features, rather than describing them from scratch in the main docs page.

@mfori
Copy link
Member Author

mfori commented Dec 11, 2025

Are there some real-world use-cases for this? I think we only used these for arrays where it is easily fixable already? Considering the complexity of the input schema, if we don't need a feature, we probably shouldn't introduce it.

We have the (patternKey and patternValue) feature for objects currently too, so I guess there is (was) some use case for it. And once we deprecate patternKey and patternValue, we need to provide Actors that use it some alternative.

@metalwarrior665
Copy link
Member

We have the (patternKey and patternValue) feature for objects currently too, so I guess there is (was) some use case for it.

But was it used in any existing Actor? Or one that has some public usage?

@mfori
Copy link
Member Author

mfori commented Dec 11, 2025

But was it used in any existing Actor? Or one that has some public usage?

Ok, I checked public Actors in the store, and none of them are using it for objects. So you think that we can just deprecate (and remove later) this feature without offering an alternative? And we can add it later if someone requests it.

I guess there had to be some use case for it, so it was implemented, but probably it's not relevant anymore since it's not used by public Actors.

Copy link
Member

@mtrunkat mtrunkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@metalwarrior665
Copy link
Member

So you think that we can just deprecate (and remove later) this feature without offering an alternative? And we can add it later if someone requests it

Yep

@gippy
Copy link
Member

gippy commented Dec 17, 2025

I have been thinking about this, and Lukas is probably right. If none of the current public Actors use the validation for keys/values of objects, then we can deprecate it/remove it. We did not have a reason when we added it initially in the first version of the input schema. It was added just because we were also adding the validation for arrays.

@mfori
Copy link
Member Author

mfori commented Dec 17, 2025

Ok, I'm making this draft (to be sure the branch is not deleted by the new job 😄), and we can add this later if requested. Thank you all.

@mfori mfori marked this pull request as draft December 17, 2025 21:18
@gippy gippy removed their request for review December 18, 2025 10:32
@fnesveda fnesveda removed their request for review December 18, 2025 15:41
@mfori mfori removed the request for review from metalwarrior665 December 19, 2025 08:15
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.

6 participants