Search code examples
phpautoloadswagger-codegenopenapi

How can I create an autoload file for PHP code generated by Swagger Code Generator?


I've used the Swagger Code Generator (to be exact, the updated version which is compatible with OpenApi 3.0.0 named openapi-generator-cli) to generate some PHP code from an OpenAPI.yaml file.

The code generation did work, but I'm missing the autoload to use the generated code. How can I generate that autoload file?


Solution

  • The generated files don't include the vendor folder which contains the dependencies stated in the composer.json file. To isntall them, just do composer install in the root directory of your generated package. If you don't have composer installed in your $PATH variable, have a look the composer docs to install it properly. Then you can just require_once('/path/to/OpenAPIClient-php/vendor/autoload.php'); and be on your way.