Skip to content

Commit 9976113

Browse files
committed
feat: handle sub-schema validation
1 parent 27b206c commit 9976113

File tree

7 files changed

+49
-15
lines changed

7 files changed

+49
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"dependencies": {
6767
"@apify/actor-templates": "^0.1.5",
6868
"@apify/consts": "^2.36.0",
69-
"@apify/input_schema": "^3.12.0",
69+
"@apify/input_schema": "^3.17.0",
7070
"@apify/utilities": "^2.15.1",
7171
"@crawlee/memory-storage": "^3.12.0",
7272
"@root/walk": "~1.1.0",

src/commands/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getAjvValidator, getDefaultsFromInputSchema, readInputSchema } from '..
2929
import { error, info, warning } from '../lib/outputs.js';
3030
import { replaceSecretsValue } from '../lib/secrets.js';
3131
import {
32-
Ajv,
32+
Ajv2019,
3333
checkIfStorageIsEmpty,
3434
getLocalInput,
3535
getLocalKeyValueStorePath,
@@ -436,7 +436,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
436436
}
437437

438438
// Step 1: validate the input schema
439-
const validator = new Ajv({ strict: false, unicodeRegExp: false });
439+
const validator = new Ajv2019({ strict: false, unicodeRegExp: false });
440440
validateInputSchema(validator, inputSchema); // This one throws an error in a case of invalid schema.
441441

442442
const defaults = getDefaultsFromInputSchema(inputSchema);

src/commands/validate-schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Args } from '../lib/command-framework/args.js';
77
import { LOCAL_CONFIG_PATH } from '../lib/consts.js';
88
import { readInputSchema } from '../lib/input_schema.js';
99
import { info, success } from '../lib/outputs.js';
10-
import { Ajv } from '../lib/utils.js';
10+
import { Ajv2019 } from '../lib/utils.js';
1111

1212
export class ValidateInputSchemaCommand extends ApifyCommand<typeof ValidateInputSchemaCommand> {
1313
static override name = 'validate-schema' as const;
@@ -45,7 +45,7 @@ export class ValidateInputSchemaCommand extends ApifyCommand<typeof ValidateInpu
4545
info({ message: `Validating input schema embedded in '${LOCAL_CONFIG_PATH}'` });
4646
}
4747

48-
const validator = new Ajv({ strict: false });
48+
const validator = new Ajv2019({ strict: false });
4949
validateInputSchema(validator, inputSchema); // This one throws an error in a case of invalid schema.
5050
success({ message: 'Input schema is valid.' });
5151
}

src/lib/input_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { validateInputSchema } from '@apify/input_schema';
99

1010
import { ACTOR_SPECIFICATION_FOLDER } from './consts.js';
1111
import { warning } from './outputs.js';
12-
import { Ajv, getJsonFileContent, getLocalConfig, getLocalKeyValueStorePath } from './utils.js';
12+
import { Ajv2019, getJsonFileContent, getLocalConfig, getLocalKeyValueStorePath } from './utils.js';
1313

1414
const DEFAULT_INPUT_SCHEMA_PATHS = [
1515
'.actor/INPUT_SCHEMA.json',
@@ -85,7 +85,7 @@ export const createPrefilledInputFileFromInputSchema = async (actorFolderDir: st
8585
* It is not possible to install the package here because it is private
8686
* We should move it to @apify/input_schema and use it from there.
8787
*/
88-
const validator = new Ajv({ strict: false });
88+
const validator = new Ajv2019({ strict: false });
8989
validateInputSchema(validator, inputSchema);
9090

9191
// inputFile = _.mapObject(inputSchema.properties as any, (fieldSchema) =>

src/lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { finished } from 'node:stream/promises';
99
import { DurationFormatter as SapphireDurationFormatter, TimeTypes } from '@sapphire/duration';
1010
import { Timestamp } from '@sapphire/timestamp';
1111
import AdmZip from 'adm-zip';
12-
import _Ajv from 'ajv';
12+
import _Ajv2019 from 'ajv/dist/2019.js';
1313
import { type ActorRun, ApifyClient, type ApifyClientOptions, type Build } from 'apify-client';
1414
import archiver from 'archiver';
1515
import { AxiosHeaders } from 'axios';
@@ -47,7 +47,7 @@ import type { AuthJSON } from './types.js';
4747

4848
// Export AJV properly: https://github.com/ajv-validator/ajv/issues/2132
4949
// Welcome to the state of JavaScript/TypeScript and CJS/ESM interop.
50-
export const Ajv = _Ajv as unknown as typeof import('ajv').default;
50+
export const Ajv2019 = _Ajv2019 as unknown as typeof import('ajv/dist/2019.js').default;
5151

5252
export const httpsGet = async (url: string) => {
5353
return new Promise<IncomingMessage>((resolve, reject) => {

test/__setup__/input-schemas/valid.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,29 @@
5656
"default": false,
5757
"groupCaption": "Options",
5858
"groupDescription": "Various options for this Actor"
59-
}
59+
},
60+
"person": {
61+
"title": "Person",
62+
"type": "object",
63+
"description": "An example of a nested object",
64+
"editor": "schemaBased",
65+
"properties": {
66+
"firstName": {
67+
"type": "string",
68+
"title": "First Name",
69+
"description": "First name of the person",
70+
"editor": "textfield"
71+
},
72+
"lastName": {
73+
"type": "string",
74+
"title": "Last Name",
75+
"description": "Last name of the person",
76+
"editor": "textfield"
77+
}
78+
},
79+
"additionalProperties": false,
80+
"required": ["lastName"]
81+
}
6082
},
6183
"required": ["queries"]
6284
}

yarn.lock

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ __metadata:
4949
languageName: node
5050
linkType: hard
5151

52-
"@apify/input_schema@npm:^3.12.0":
53-
version: 3.15.2
54-
resolution: "@apify/input_schema@npm:3.15.2"
52+
"@apify/input_schema@npm:^3.17.0":
53+
version: 3.17.0
54+
resolution: "@apify/input_schema@npm:3.17.0"
5555
dependencies:
5656
"@apify/consts": "npm:^2.43.0"
57+
"@apify/input_secrets": "npm:^1.2.1"
5758
acorn-loose: "npm:^8.4.0"
5859
countries-list: "npm:^3.0.0"
5960
peerDependencies:
6061
ajv: ^8.0.0
61-
checksum: 10c0/4f75e00eb2fe94879b4caa5b3d208dc638890e41ddb22843b605a924b5db4d89e95d29c8f961cc6e180fece8be8abdacee40ad04df5b0abbfc22c08f22a59e40
62+
checksum: 10c0/9d6a761f2bfb91cecd4d84a4094eda6a7c512bcbc98d875441062c88a3a1e83260bf90d113b8d0063457cd8a37d205d95138584267c8ee69e8bb863719164109
6263
languageName: node
6364
linkType: hard
6465

@@ -73,6 +74,17 @@ __metadata:
7374
languageName: node
7475
linkType: hard
7576

77+
"@apify/input_secrets@npm:^1.2.1":
78+
version: 1.2.1
79+
resolution: "@apify/input_secrets@npm:1.2.1"
80+
dependencies:
81+
"@apify/log": "npm:^2.5.20"
82+
"@apify/utilities": "npm:^2.16.2"
83+
ow: "npm:^0.28.2"
84+
checksum: 10c0/0494940e807d33acc2779576a2fe4610bb359e535e8da31d3d06c5b2e6efda20a775711fcb51a1be0ed672116bee286bc00341d31135c9c27fcbe5b7f9f24a2d
85+
languageName: node
86+
linkType: hard
87+
7688
"@apify/log@npm:^2.2.6, @apify/log@npm:^2.4.0, @apify/log@npm:^2.4.3, @apify/log@npm:^2.5.20":
7789
version: 2.5.20
7890
resolution: "@apify/log@npm:2.5.20"
@@ -2465,7 +2477,7 @@ __metadata:
24652477
"@apify/actor-templates": "npm:^0.1.5"
24662478
"@apify/consts": "npm:^2.36.0"
24672479
"@apify/eslint-config": "npm:^1.0.0"
2468-
"@apify/input_schema": "npm:^3.12.0"
2480+
"@apify/input_schema": "npm:^3.17.0"
24692481
"@apify/tsconfig": "npm:^0.1.1"
24702482
"@apify/utilities": "npm:^2.15.1"
24712483
"@biomejs/biome": "npm:^2.0.0"

0 commit comments

Comments
 (0)