Title: Automating Postman to Swagger with Version Control in Laravel Vapor
Hey folks! 👋 I wanted to share a neat workflow I've implemented for our Laravel Vapor project that automates the generation and upload of Swagger documentation with each Git tag, all seamlessly integrated with Postman. 🚀
With every push to a dev/*
tag, GitHub Actions springs into action:
- Checkout Code: Pulls in the latest source code.
- Setup Node and PHP: Configures the environment.
- Require Vapor CLI: Installs the Vapor CLI globally.
- Install Project Dependencies: Uses Composer to fetch dependencies.
- Deploy Environment: Vapor deploys our development environment with the commit details.
The magic happens during the build steps:
- Convert Postman to OpenAPI: Downloads the Postman collection, removes unnecessary headers, and converts it to OpenAPI format.
- Upload to SwaggerHub: The resulting Swagger file is then uploaded to SwaggerHub, ensuring our API documentation is always up-to-date.
This JavaScript script cleans up the Postman collection and leverages the postman-to-openapi
package to perform the conversion. The OpenAPI file is then saved for deployment.
This PHP script is the backbone of SwaggerHub integration:
- Create a New Version: Dynamically creates a new SwaggerHub version with each Git tag.
- Upload to SwaggerHub: Sends an HTTP request to upload the OpenAPI file, ensuring our Swagger documentation is versioned and available.
- Postman Integration: We automate the download of a Postman collection on each deployment.
- SwaggerHub Integration: With each Git tag, we generate a new Swagger version, ensuring version control and easy navigation in SwaggerHub.
The result? A fully automated pipeline where Swagger documentation evolves with our codebase, providing clear versioning and consistency. No more manual updates needed! 🌐✨
Feel free to adapt and integrate this workflow into your Laravel Vapor projects. Happy coding! 🚀👨💻
el3zahaby | @egyjs |