How to Automatically Generate Documentation from Your Prisma Schema

Sep 8, 2024 | Programming

If you’re looking to make your Prisma development process even smoother, you’re in for a treat! The Prisma Documentation Generator allows you to automatically create a reference from your Prisma schema each time you run the Prisma generation command. This handy package keeps your documentation up-to-date without any manual effort – let’s dive right in!

Getting Started

To kick things off, you will need to install the Prisma Documentation Generator. Here’s how you can do it step by step:

  • Install the package via npm:
    npm install -D prisma-docs-generator
  • Add the generator to your Prisma schema configuration:
    generator docs {
      provider = "node node_modules/prisma-docs-generator"
    }
  • Run the following command to trigger the generator:
    npx prisma generate
  • This will create a docs folder in your Prisma project.
  • Finally, serve the generated documentation using:
    npx prisma-docs-generator serve

Options for Customization

Once you’ve set up the generator, you may want to customize the generated documentation. Here’s how:

Specifying Output Location

You can indicate where the generated documentation will be saved by using the output property:

generator docs {
  provider = "node node_modules/prisma-docs-generator"
  output = "./docs"
}

Include Relationship Fields

Do you want to include or exclude relation fields in your documentation? You can set the includeRelationFields property accordingly. By default, this is set to true:

generator docs {
  provider = "node node_modules/prisma-docs-generator"
  includeRelationFields = false
}

Command Line Interface (CLI)

This package also offers a Command Line Interface (CLI) that can serve the documentation effectively. As of now, it includes the following command:

Serve Command

To serve the static HTML generated by the documentation generator:

npx prisma-docs-generator serve

You can change the server port by using the –port option or simply -p!

Troubleshooting

If you run into issues while using the Prisma Documentation Generator, consider the following troubleshooting tips:

  • Ensure you have entered the correct path to your Prisma schema in the provider option.
  • Make sure you have the required permissions to create files in your specified output directory.
  • If the documentation does not generate, double-check your schema configuration and run the generation command again.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox