Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Auto-generated Comments to Top of Generated Files #1510

Closed
amikofalvy opened this issue Mar 2, 2025 · 2 comments
Closed
Labels
enhancement New feature or request PR welcome Feature Request approved

Comments

@amikofalvy
Copy link
Contributor

What problem will this feature address?

This feature will clearly indicate which files are auto-generated, preventing contributors from unintentionally editing generated files directly, which can lead to overwritten changes or merge conflicts.

Describe the solution you'd like

Introduce a new optional parameter to the OpenAPI.generateFiles function, e.g., addGeneratedComment, accepting:

  • true (default): Inserts a standardized comment.
  • false: No comment is added.
  • string: Inserts a custom provided comment.

Example usage with current generate-docs.mjs script:

await OpenAPI.generateFiles({
  schemaPath: './openapi.json',
  output: './docs/openapi',
  addGeneratedComment: true, // or provide a custom string
});

Default standardized comment:

// Comment format for MDX files
{/*
  This file was auto-generated by Fuma Docs.
  Do not edit this file directly. Any changes should be made by running the generation command again.
*/}

Describe alternatives you've considered

  • Initially, I considered not making this feature configurable, but I realized it might disrupt workflows of existing users who prefer not to have additional comments in their generated files.
  • Secondly, I considered making the configuration a simple boolean. However, providing a string option for custom messages makes the feature more versatile. Users can include specific instructions or commands (e.g., pnpm build or pnpm run generate) tailored to their project needs.
  • Lastly, I thought about the complexity of overloading the configuration type. Ultimately, I found that a clear and simple true | false | string option strikes a good balance, catering both to straightforward use cases and more advanced configurations without added complexity.

Additional context

Examples from similar tools:

  • GraphQL Code Generator:
    // THIS IS A GENERATED FILE, DO NOT EDIT!
  • Prisma Client:
    // This file was automatically generated by Prisma.
    // Do not edit this file directly.
  • Next.js:
    // Automatically generated by Next.js. Do not modify.
  • OpenAPI Generator:
    // Code generated by OpenAPI Generator. DO NOT EDIT.

I'm happy to contribute this feature myself if the maintainers approve. Thanks for creating and maintaining such a useful tool!

@amikofalvy amikofalvy added the enhancement New feature or request label Mar 2, 2025
@fuma-nama
Copy link
Owner

Sounds good! I didn't consider that because it was supposedly a process happen at production build, welcome for PR ;)

Note that MDX uses a different syntax for comments:

{/* Comment */}

@fuma-nama fuma-nama added the PR welcome Feature Request approved label Mar 2, 2025
@amikofalvy
Copy link
Contributor Author

I propose a solution in #1512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR welcome Feature Request approved
Projects
None yet
Development

No branches or pull requests

2 participants