⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Implement a command for generating type definitions from schemas #993

@vladfrangu

Description

@vladfrangu

We want to have a command to generate (currently only) TypeScript definitions for the input.json (and in the future from output schema, or dataset/key value store schemas)

For an idea of how such an implementation can be done, see https://github.com/apify-projects/types-from-schema-generator

The command name I'd say should be apify actor generate-types / actor generate-types (cc @B4nan)

It should have the following flags:

  • output: path to a directory where the files generated should be outputted, default ./.generated/actor/ (actual path in code is gonna be resolve(cwd(), output), followed by mkdir(), then storing in there). char: o
  • strict: whether generated interfaces should have an index definition ([key: string]: unknown if this is set to false), default true. char: s
  • [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. @B4nan lets discuss if we want this. char: i

When generating the files, the filename should ideally be the filename of the input schema, but with the appropriate language. So for example, if you're generating a file from ./my_schema.json, the result should be ./my_schema.ts

All generated files should have the following headers for TS:

// biome-ignore-all lint: Automatically generated file
/* eslint-disable -- Automatically generated file */

/**
 * This file was automatically generated by the actor CLI.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
 * and run `actor generate-types` to regenerate this file.
 *
 * Don't forget to add this file to the ignore list of your formatters and linters.
 */

Metadata

Metadata

Assignees

Labels

t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions