The `openapi-generator-cli` Python package provides a command-line interface (CLI) for the OpenAPI Generator, a robust tool that automatically generates API client libraries (SDKs), server stubs, documentation, and configuration from an OpenAPI Specification (supporting both 2.0 and 3.x). The Python package acts as a thin wrapper around the official Java-based OpenAPI Generator, downloading and executing the appropriate JAR file. It maintains an active development pace, with new versions often released daily to mirror updates in the core Java project, typically including numerous enhancements, bug fixes, and sometimes breaking changes with fallbacks.
pip install openapi-generator-cliNo compatibility data collected yet for this library.
This quickstart demonstrates how to install the `openapi-generator-cli` and use it to generate a Python client library from a public OpenAPI Specification. The `openapi-generator-cli` itself is a command-line tool, and direct Python imports are not typically used for the generator. Instead, you execute the CLI command to produce source code (e.g., an SDK) in a chosen language, which you then integrate into your project and import as a separate library. Replace `https://petstore.swagger.io/v2/swagger.json` with your own OpenAPI spec URL or file path, and adjust the generator (`-g python`) and output directory (`-o my_python_client`) as needed. The commented Python code provides an example of how a *generated* Python client might be used.
Consult the official release notes (e.g., on GitHub) for specific breaking changes and their recommended migration paths. Implement robust testing for generated code.
Ensure JDK 11+ is installed and configured in your system's PATH. Verify with `java -version`. Or, install the Python package with `pip install openapi-generator-cli[jdk4py]`.
Evaluate the generated code for your specific target language and framework. Consider custom templates or post-generation processing if the default output doesn't meet your needs. Be prepared for potential manual adjustments.
Add `openapitools.json` to your `.gitignore` if you are managing the version and config manually, or ensure it is committed to VCS to maintain consistency across team members and deployment environments.
Ensure `openapi-generator-cli` is installed globally via npm (`npm install -g @openapitools/openapi-generator-cli`) or that its installation directory is in your system's PATH. Also, ensure you are using `openapi-generator-cli` instead of `openapi-generator` (the command was renamed).
Install a Java Development Kit (JDK), version 11 or higher, and ensure that the `java` executable is added to your system's PATH environment variable.
Review your OpenAPI specification for syntax errors, missing definitions, incorrect path parameters, or malformed schemas. Use an OpenAPI validator tool (like `openapi-generator-cli validate` or online validators) to pinpoint and fix the specific issues.
Check your internet connection and proxy settings. If behind a corporate proxy, configure `npm` or your environment variables (HTTP_PROXY, HTTPS_PROXY) correctly. Alternatively, you can manually download the JAR file and configure `openapi-generator-cli` to use a local version via the `openapitools.json` configuration file, specifying `storageDir` and `version`.