openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

feat: Added config formatFilename to allow more custom formatting of filenames

Open Cellule opened this issue 1 year ago • 0 comments

I have a special need where I want to add .gen at the end of the files that are always regenerated by the codegen. Instead of baking that logic into this lib, I thought that allowing to provide a custom formatter would be generic enough and I can do a mapping on my side like this

const formatFilename = (filename: string) => {
      filename = _.kebabCase(filename);
      const needsDotGen = [
        `${filenamePrefix}-components`,
        `${filenamePrefix}-request-bodies`,
        `${filenamePrefix}-schemas`,
        `${filenamePrefix}-parametersF`,
        `${filenamePrefix}-responses`,
      ].includes(filename);
      return `${filename}${needsDotGen ? ".gen" : ""}`;
    };

    const { schemasFiles } = await generateSchemaTypes(context, {
      filenamePrefix,
      formatFilename,
    });
    await generateReactQueryComponents(context, {
      schemasFiles,
      filenamePrefix,
      formatFilename,
    });

Cellule avatar Mar 14 '24 18:03 Cellule