Skip to content

Mechanism to access metadata about included types and generated output #227

@CharlieDigital

Description

@CharlieDigital

Problem

The OnAfterGeneration hook and the Generate result provides a list of the output files but does not provide the metadata about the generation. Namely:

  • Which types were included in the generation
  • Metadata such as the name of the class/interface that was generated for the type

Reasoning

My use case is that after generating the TypeScript models, I would like to generate additional code manually.

Consider this case:

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export interface Message1 {
    text: string;
}

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export interface Message2 {
    text: string;
}

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export * from './message1';
export * from './message2';

Now I would like to reflect on the types that were included and manually produce another file:

import { Message1, Message2 } from "./index";

type MessageType = 'message-type-1' | 'message-type-2'

type MessageBase<T extends MessageType> = {
    type: T;
};

type MessageType1 = Message1 & MessageBase<'message-type-1'>;

type MessageType2 = Message2 & MessageBase<'message-type-2'>;

type Message<T extends MessageType> =
  // prettier-ignore
  T extends 'message-type-1' ? MessageType1 :
  T extends 'message-type-2' ? MessageType2 :
  never

The FileContentGenerated is close, but it only contains the fully rendered file contents and not the parts that may be relevant like the name of the class (which may have been customized with an attribute). It would be great to be able to access this metadata for additional file generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions