Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/input_schema/src/input_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { inputSchema as schema } from '@apify/json_schemas';

import { m } from './intl';
import type {
ArrayFieldDefinition,
CommonResourceFieldDefinition,
FieldDefinition,
InputSchema,
InputSchemaBaseChecked,
ObjectFieldDefinition,
StringFieldDefinition,
} from './types';
import { ensureAjvSupportsDraft2019, validateRegexpPattern } from './utilities';
Expand Down Expand Up @@ -313,16 +311,24 @@ function validateField(
fieldKey: string,
isSubField = false,
): asserts fieldSchema is FieldDefinition {
// The deprecated patternKey/patternValue properties are no longer supported. They would fail
// the schema definition validation below anyway, but this check gives a clear error message
// with a link to migration instructions.
Comment thread
mfori marked this conversation as resolved.
// TODO: Remove this check (and the deprecatedProperty message) once schemas have had enough
// time to migrate and the generic "property is not allowed" error is a good enough response.
for (const property of ['patternKey', 'patternValue']) {
if (property in fieldSchema) {
const message = m('inputSchema.validation.deprecatedProperty', { fieldKey, property });
throw new Error(`Input schema is not valid (${message})`);
}
}

// Validate against schema definition first.
validateFieldAgainstSchemaDefinition(validator, fieldSchema, fieldKey, isSubField);

// Validate regex patterns if defined.
// Validate regex pattern if defined.
const { pattern } = fieldSchema as Partial<StringFieldDefinition>;
const { patternKey, patternValue } = fieldSchema as Partial<ObjectFieldDefinition & ArrayFieldDefinition>;

if (pattern) validateRegexpPattern(pattern, `${fieldKey}.pattern`);
if (patternKey) validateRegexpPattern(patternKey, `${fieldKey}.patternKey`);
if (patternValue) validateRegexpPattern(patternValue, `${fieldKey}.patternValue`);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/input_schema/src/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const intlStrings = {
'Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings.',
'inputSchema.validation.secretFieldSchemaChanged':
'The field schema.properties.{fieldKey} is a secret field, but its schema has changed. Please update the value in the input editor.',
'inputSchema.validation.deprecatedProperty':
'Property schema.properties.{fieldKey}.{property} is deprecated and no longer supported. Please remove it from the input schema. ' +
'See https://docs.apify.com/platform/actors/development/actor-definition/input-schema/specification/v1#deprecation-of-patternkey-and-patternvalue for migration instructions.',
'inputSchema.validation.regexpNotValid':
'The regular expression "{pattern}" in field schema.properties.{fieldKey} must be valid.',
'inputSchema.validation.regexpNotSafe':
Expand Down
4 changes: 4 additions & 0 deletions packages/input_schema/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export type NumberFieldDefinition = CommonFieldDefinition<number> & {
export type ObjectFieldDefinition = CommonFieldDefinition<object> & {
type: 'object';
editor: 'json' | 'proxy' | 'schemaBased' | 'hidden';
/** @deprecated Rejected in new input schemas, but may still be present in stored schemas of existing builds. TODO: Remove once those no longer need to be supported. */
patternKey?: string;
/** @deprecated Rejected in new input schemas, but may still be present in stored schemas of existing builds. TODO: Remove once those no longer need to be supported. */
patternValue?: string;
maxProperties?: number;
minProperties?: number;
Expand All @@ -81,7 +83,9 @@ export type ArrayFieldDefinition = CommonFieldDefinition<unknown[]> & {
| 'hidden';
placeholderKey?: string;
placeholderValue?: string;
/** @deprecated Rejected in new input schemas, but may still be present in stored schemas of existing builds. TODO: Remove once those no longer need to be supported. */
patternKey?: string;
/** @deprecated Rejected in new input schemas, but may still be present in stored schemas of existing builds. TODO: Remove once those no longer need to be supported. */
patternValue?: string;
maxItems?: number;
minItems?: number;
Expand Down
6 changes: 5 additions & 1 deletion packages/input_schema/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ function validateProxyField(

/**
* Uses AJV validator to validate input with input schema and then
* does custom validation for our own properties (nullable, patternKey, patternValue)
* does custom validation for our own properties (nullable, patternKey, patternValue).
*
* Note: patternKey/patternValue are deprecated and rejected by `validateInputSchema`,
* but they are still validated here so that inputs of existing builds keep working.
Comment thread
mfori marked this conversation as resolved.
* TODO: Remove their validation once stored schemas of existing builds no longer need to be supported.
* @param validator Initialized AJV validator
* @param inputSchema Valid input schema in object
* @param input Input object to be validated
Expand Down
36 changes: 0 additions & 36 deletions packages/json_schemas/output/actor.ide.json
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"isSecret": {
"enum": [
false
Expand Down Expand Up @@ -1355,12 +1349,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -1514,12 +1502,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -2904,12 +2886,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"errorMessage": {
"$ref": "#/definitions/input-ide-json-2212166aa408babb6120b85f1282521a/definitions/errorMessage"
}
Expand Down Expand Up @@ -3421,12 +3397,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -4995,12 +4965,6 @@
},
"maxProperties": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
36 changes: 0 additions & 36 deletions packages/json_schemas/output/input.ide.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"isSecret": {
"enum": [
false
Expand Down Expand Up @@ -1055,12 +1049,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -1214,12 +1202,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -2604,12 +2586,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"errorMessage": {
"$ref": "#/definitions/errorMessage"
}
Expand Down Expand Up @@ -3121,12 +3097,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -4695,12 +4665,6 @@
},
"maxProperties": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
36 changes: 0 additions & 36 deletions packages/json_schemas/output/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"isSecret": {
"enum": [
false
Expand Down Expand Up @@ -1056,12 +1050,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -1215,12 +1203,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -2605,12 +2587,6 @@
"placeholderValue": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"errorMessage": {
"$ref": "#/definitions/errorMessage"
}
Expand Down Expand Up @@ -3122,12 +3098,6 @@
"x-intellij-html-description": "<p>Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.</p>",
"markdownDescription": "Sample value of this field for the Actor to be displayed when Actor is published in Apify Store."
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
},
"nullable": {
"type": "boolean",
"description": "Specifies whether null is an allowed value.",
Expand Down Expand Up @@ -4696,12 +4666,6 @@
},
"maxProperties": {
"type": "string"
},
"patternKey": {
"type": "string"
},
"patternValue": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,6 @@
Placeholder displayed in value field when no value is provided. Works only with `keyValue` and `stringList`
editors.
</AddDescription>
<AddDescription json-path="/definitions/arrayProperty/else/properties/patternKey" format="markdown">
Regular expression that will be used to validate the keys of items in the array. Works only with `keyValue`
editor.
</AddDescription>
<AddDescription json-path="/definitions/arrayProperty/else/properties/patternValue" format="markdown">
Regular expression that will be used to validate the values of items in the array. Works only with `keyValue`
and `stringList` editors.
</AddDescription>
<AddDescription json-path="/definitions/objectProperty/properties/type" format="markdown">
Allowed type for the input value. Cannot be mixed.
</AddDescription>
Expand All @@ -392,12 +384,6 @@
<AddDescription json-path="/definitions/objectProperty/properties/example" format="markdown">
Sample value of this field for the Actor to be displayed when Actor is published in Apify Store.
</AddDescription>
<AddDescription json-path="/definitions/objectProperty/properties/patternKey" format="markdown">
Regular expression that will be used to validate the keys of the object.
</AddDescription>
<AddDescription json-path="/definitions/objectProperty/properties/patternValue" format="markdown">
Regular expression that will be used to validate the values of object.
</AddDescription>
<AddDescription json-path="/definitions/objectProperty/properties/nullable" format="markdown">
Specifies whether null is an allowed value.
</AddDescription>
Expand Down
Loading
Loading