Repository navigation
apify run and the schema commands ignore inputSchema and outputSchema in actor.json #1534
Description
Problem
actor.json accepts inputSchema and outputSchema as aliases of input and output, and the docs say they can be used interchangeably. The platform build copies a set inputSchema over input, and a set outputSchema over output, before it resolves any schema. When both keys are set, the alias wins. Every template in apify/actor-templates now uses the aliases (apify/actor-templates#822).
The CLI reads only the base keys:
readInputSchemainsrc/lib/input_schema.tsreads onlyinput. Wheninputis unset, it falls back to.actor/INPUT_SCHEMA.json,./INPUT_SCHEMA.json,.actor/input_schema.json, and./input_schema.json.readOutputSchemain the same file, and the output schema check inapify validate-schema, read onlyoutputand have no fallback.
Affected commands:
apify run: validates the input and fills in defaults from the input schema.apify validate-schema: validates the input and output schemas.apify actor generate-schema-types: generates input and output types.apify edit-input-schema(hidden): opens the input schema in the editor.apify createandapify init: prefillINPUT.jsonfrom the input schema.
Example: a fresh project from the js-cypress template sets "inputSchema": "./input_schema.json" and "outputSchema": "./output_schema.json". The CLI finds the input schema only because .actor/input_schema.json is one of its fallback paths. It does not find the output schema: apify validate-schema skips it, and apify actor generate-schema-types writes no output types. The same holds for every template.
When inputSchema points anywhere else, for example "./schemas/input.json", or holds an inline schema, the CLI finds no input schema:
apify runruns without input validation or defaults.apify validate-schemaskips the input schema.apify actor generate-schema-typesfails withInput schema has not been found at .actor/INPUT_SCHEMA.json.apify edit-input-schemaopens an empty schema at.actor/INPUT_SCHEMA.jsoninstead of the configured file.
When both inputSchema and input are set, or an old INPUT_SCHEMA.json is still in the project, the CLI uses a different file than the platform.
What we want
-
readInputSchemaresolvesinputSchemafirst when it is set, theninput, exactly as the platform does. It falls back to the default paths only when neither is set. An empty string counts as unset, as on the platform. -
readOutputSchemaand the output schema check inapify validate-schemaresolveoutputSchemafirst, thenoutput. - Both aliases accept a path relative to
.actor/or an inline schema object, like the base keys. - When both the alias and the base key are set, the alias wins without an error. The docs do not state a precedence, but the platform build applies this one and accepts both keys.
How it's tested
A new test/local/lib/input-schema.test.ts for the readers in src/lib/input_schema.ts, which have no unit tests today:
readInputSchema:inputSchemaas a path outside the default locations returns that file;inputSchemaas an inline object returns the object; with bothinputSchemaandinputset, it returns theinputSchemaschema; an emptyinputSchemafalls through toinput; onlyinputset and neither set keep today's behavior;inputSchemapointing at a missing file warns, or throws withthrowOnMissing.readOutputSchema:outputSchemaas a path and as an inline object; with both set, it returns theoutputSchemaschema; onlyoutputset keeps today's behavior.
Command cases:
test/local/commands/validate-schema.test.ts: a project withinputSchemaandoutputSchemavalidates both schemas.test/local/commands/actor/generate-schema-types.test.ts: a project withinputSchemaandoutputSchemageneratesinput.tsandoutput.ts.
Links
- Found while reviewing the
actor.jsonpath checks forapify push(feat: validateactor.jsonpaths beforeapify pushuploads anything #1503), which already treat the alias as the winning key. - Docs: Actor definition file (
actor.json)
Activity