Skip to content

Comments

feat(actor): adds actor types generation#1000

Open
l2ysho wants to merge 36 commits intomasterfrom
993-implement-a-command-for-generating-type-definitions-from-schemas
Open

feat(actor): adds actor types generation#1000
l2ysho wants to merge 36 commits intomasterfrom
993-implement-a-command-for-generating-type-definitions-from-schemas

Conversation

@l2ysho
Copy link
Contributor

@l2ysho l2ysho commented Jan 19, 2026

"backlog"
  • [can optionally be done] language: the language to generate the types for (currently only TypeScript, but ideally structure the code in a way where we can easily add in new languages). char: l
  • [optional, nice to have, can be for future work] [input/output/dataset/key-value-store]-schema: path to a specific schema to generate types for
  • [don't implement this until we discuss it] add-to-ignore: whether the cli should add the generated files to files like .prettierignore or the biome config, default: false.

Draft summary

apify actor generate-schema-types --help

Generate TypeScript types from Actor schemas.

USAGE
  $ actor generate-schema-types [path] [--all-optional] [-o <value>] [--strict]

ARGUMENTS
  path  Optional path to the input schema file. If not provided, searches default locations.

FLAGS
      --all-optional    Mark all properties as optional in generated types.
  -o, --output=<value>  Directory where the generated files should be outputted. Defaults to src/.generated/actor/ to stay within the typical tsconfig rootDir.
      --strict          Whether generated interfaces should be strict (no index signature [key: string]: unknown).

DESCRIPTION
  Generate TypeScript types from Actor schemas.

  Generates types from the input schema and, when no custom path is provided,
  also from the dataset schema defined in '.actor/actor.json' under "storages.dataset".

  Reads the input schema from one of these locations (in priority order):
    1. Object in '.actor/actor.json' under "input" key
    2. JSON file path in '.actor/actor.json' "input" key
    3. .actor/INPUT_SCHEMA.json
    4. INPUT_SCHEMA.json

  Optionally specify custom schema path to use.

TO DO:

  • [slack-feedback] mention in docs that default output path is src due to tsconfig
  • [slack-feedback] actor generate-schema -> generate-schema-types to keep consistency with actor validate-schema?
  • [slack-feedback] do not export the individual fields, not useful as you can do Input['field']
    - this must be done manually, json-schema-to-typescript does not support this
  • [slack-feedback] inline primitive types to make it less verbose (the comments above inlined fields still display in editor)
    - this must be done manually, json-schema-to-typescript does not support this
  • output types
  • key-value-store types
  • how to resolve unknown[] problem? (As long as the items: { type: string } propagates to string[] type, let's just go that way.)

feedback from @B4nan

Must fix

  • Verify biome-ignore-all actually works or remove it
  • Handle Promise.all failure gracefully — partial success should still produce output

Should fix

  • Extract schema transform functions to src/lib/schema-transforms.ts
  • Add unit tests for stripTitles
  • Handle missing JSON Schema keywords in stripTitles

Nice to have

  • Reduce deep clone overhead
  • Deduplicate readOutputSchema logic
  • Clean up import style, unused defaults

@l2ysho l2ysho linked an issue Jan 19, 2026 that may be closed by this pull request
@github-actions github-actions bot added this to the 132nd sprint - Tooling team milestone Jan 19, 2026
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Jan 19, 2026
@l2ysho l2ysho force-pushed the 993-implement-a-command-for-generating-type-definitions-from-schemas branch from bbaf98e to dcc207c Compare January 21, 2026 13:18
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Jan 21, 2026
Comment on lines 1 to 2
import { readFile } from 'node:fs/promises';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really just starting point of tests. No complex scenarios.

});

expect(lastErrorMessage()).toMatch(/Generated types written to/);
expect(lastErrorMessage()).toMatch(/\.generated\/actor\/complex\.ts/);
Copy link
Member

Choose a reason for hiding this comment

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

use path.join and i think you can do .toInclude or just expect(lastErrorMessage().includes()).toBeTruthy()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@l2ysho
Copy link
Contributor Author

l2ysho commented Feb 11, 2026

as JuanGalilea mentioned, all properties are optional even if they have default present in definition. There is already opened PR in json-schema-to-typescript to address this, in the meantime, I pushed temporary fix 01d1ccc

@l2ysho l2ysho marked this pull request as ready for review February 16, 2026 22:14
@l2ysho l2ysho requested a review from TC-MO as a code owner February 16, 2026 22:14
@l2ysho
Copy link
Contributor Author

l2ysho commented Feb 17, 2026

ready for review

  • input and dataset schemas generated
  • some feedback from slack addressed
  • other feedback in summary, If we agree to do It I will create an issues
  • I will update summary when review done

@vladfrangu @B4nan

export class ActorGenerateSchemaTypesCommand extends ApifyCommand<typeof ActorGenerateSchemaTypesCommand> {
static override name = 'generate-schema-types' as const;

static override hiddenAliases = ['generate-types'];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want this too as an alias? CC @B4nan @patrikbraborec

Suggested change
static override hiddenAliases = ['generate-types'];
static override hiddenAliases = ['generate-types', 'generate'];

description:
'Directory where the generated files should be outputted. Defaults to src/.generated/actor/ to stay within the typical tsconfig rootDir.',
required: false,
default: 'src/.generated/actor/',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default: 'src/.generated/actor/',
default: join('src', 'generated', 'actor'),

Comment on lines 203 to 207
if (datasetSchemaPath) {
info({ message: `Generating types from dataset schema at ${datasetSchemaPath}` });
} else {
info({ message: `Generating types from dataset schema embedded in '${LOCAL_CONFIG_PATH}'` });
}
Copy link
Member

Choose a reason for hiding this comment

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

Do check if Dataset also has to be capitalized, like how Actor has to be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to other places in code it should be capitalized

@l2ysho
Copy link
Contributor Author

l2ysho commented Feb 18, 2026

some updates

  • output/kvs schemas added and marked as experimental alongside with dataset
  • only one type exported from generated files with inline definitions (no ts-morh used now, just striped title before compilation, so far so good, if some problem occurs we can update)

@l2ysho l2ysho requested review from B4nan and vladfrangu February 20, 2026 14:50
Comment on lines +22 to +23
// biome-ignore-all lint: generated
// biome-ignore-all format: generated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

must be inline, format is available in >2.4.0
biome playground example cc @B4nan

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a command for generating type definitions from schemas

3 participants