prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

Old fields with colons in API ID path not supported #39

Closed SudoCat closed 1 year ago

SudoCat commented 1 year ago

The tool generates invalid syntax when the Prismic repository contains invalid API ID Paths.

Historically, it was possible to create a field with the API ID Path including colon characters, e.g. general::banners.

(The project I am working on has many, many legacy fields using this syntax, for better or worse. Updating them all is not viable, as it would require broad code changes.)

Versions

Reproduction

It is no longer possible to create fields with : in the name anymore, so a new test case cannot be produced.

Steps to reproduce

  1. Start with an old prismic repository, containing models with fields whose API ID contain colon characters, e.g. general::banners
  2. Setup the code generation according to the documentation, using PRISMIC_CUSTOM_TYPES_API_TOKEN to generate from the repository
  3. Run the cli tool

What is expected?

Valid TypeScript type defintiions, where fields containing colons are escaped as strings, e.g.

"general::banners": prismicT.GroupField<Simplify<GlobalContentDocumentDataGeneralBannersItem>>;

What is actually happening?

Invalid syntax is generated, as these keys are not safely escaped.

/**
 * Visible banners field in *Global Content*
 *
 * - **Field Type**: Group
 * - **Placeholder**: *None*
 * - **API ID Path**: global_content."general::banners"[]
 * - **Tab**: General
 * - **Documentation**: https://prismic.io/docs/core-concepts/group
 *
 */
general: ;
banners: prismicT.GroupField<Simplify<GlobalContentDocumentDataGeneralBannersItem>>;
angeloashmore commented 1 year ago

Thank you for the report and PR, @SudoCat!

This bug is fixed in v0.1.6.