Swagger API Documentation

Complete guide to generate and customize Swagger documentation in your PHP project.

Swagger is a powerful tool for documenting APIs. It provides a user-friendly interface for developers to interact with API endpoints and understand the request and response structures. This page provides a detailed guide on how to set up Swagger in your PHP project and generate API documentation.

With Swagger, you can easily create and maintain accurate documentation for your APIs. It allows you to define the structure of your API endpoints, including request and response schemas, authentication requirements, and available parameters. Swagger also provides a built-in testing interface.

By using Swagger, you improve the developer experience with clear documentation. It also reduces support time and ensures your documentation stays up-to-date as your API evolves.

To get started with Swagger in your PHP project, install the Swagger PHP library and configure it to generate docs using your code annotations.

Remember to keep your Swagger documentation up-to-date as you make changes to your API.

Advanced Usage and Customization

Use this command to generate Swagger docs for specific models from your schema.prisma file:

npm run create-swagger-docs
npm run create-swagger-docs Order
npm run create-swagger-docs Order User Client
    

When running the command, you will be prompted with:

  • Do you want to generate Swagger docs only?
  • Do you want to generate endpoints?
  • Do you want to generate PHP classes?

You can answer true or false for each option.

Generated Files Location

src/app/swagger-docs/apis/
    

A Swagger JSON file named pphp-swagger.json will be created or updated in this directory.

Configuration File

settings/prisma-schema-config.json
    

Example configuration:

{
  "swaggerDocsDir": "src/app/swagger-docs/apis",
  "skipDefaultName": ["autoincrement", "cuid", "uuid", "now"],
  "skipByPropertyValue": {
    "isUpdatedAt": true
  },
  "skipFields": [],
  "generateSwaggerDocsOnly": false,
  "generateEndpoints": true,
  "generatePhpClasses": true
}
    

๐Ÿ“š Useful Resources