Registry / http-networking / openapi-generator-cli

openapi-generator-cli

JSON →
library7.21.0pypypiunverified

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-cli
INSTALL
IMPORT
SIG · OPENAPI-GENERATOR-
O
openapi-generator-cli
http-networkingpythonv7.21.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

pip install openapi-generator-cli # Check installed version openapi-generator-cli version # Generate a Python client from a public OpenAPI specification # This will create a directory named 'my_python_client' containing the generated SDK openapi-generator-cli generate \ -i https://petstore.swagger.io/v2/swagger.json \ -g python \ -o my_python_client # To use the generated client (example, assuming 'my_python_client' was created): # cd my_python_client # pip install . # # Then in a Python script: # from openapi_client import api_client, configuration # from openapi_client.api import pet_api # # # Configure API key authorization: api_key # config = configuration.Configuration() # config.api_key['api_key'] = 'YOUR_API_KEY_HERE' # # # Create an API client # client = api_client.ApiClient(configuration=config) # api = pet_api.PetApi(client) # # # Example: List pets (assuming the generated client structure) # # try: # # all_pets = api.find_pets_by_status(status=['available']) # # print(all_pets) # # except Exception as e: # # print(f"Error: {e}")
openapi-generator-cli --version
Debug
Known issues
breakingThe OpenAPI Generator project frequently introduces breaking changes, often labeled 'with fallbacks', across its major and even minor releases. These changes can affect various generated languages (e.g., Spring Boot 3.x becoming default, changes in Rust, Go, C# generators). Always review release notes and thoroughly test your generated code after upgrading `openapi-generator-cli` to avoid unexpected behavior or compilation errors.
fix
Consult the official release notes (e.g., on GitHub) for specific breaking changes and their recommended migration paths. Implement robust testing for generated code.
affects: All versions, particularly major and minor releases (e.g., v7.12.0, v7.15.0, v7.17.0, v7.21.0)
gotchaThe `openapi-generator-cli` is a wrapper around a Java JAR and requires a Java Development Kit (JDK) version 11 or higher to be installed and available on your system's PATH. If Java is not correctly configured, the CLI commands will fail with an error. Alternatively, install with the `[jdk4py]` extra to bundle a Java runtime.
fix
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]`.
affects: All versions
gotchaThe quality, feature completeness, and ideological approach of generated code can vary significantly between different target languages (e.g., Python, Java, Go) and even between different generators for the same language (e.g., `python` vs `python-flask`). Users have reported instances where generated code does not compile, is outdated for current language versions, or deviates from expected patterns, requiring manual intervention or customization of templates.
fix
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.
affects: All versions
gotchaWhen using `openapi-generator-cli`, especially via the NPM wrapper (which the Python package behaves similarly to in terms of configuration), an `openapitools.json` file is generated. This file manages the downloaded OpenAPI Generator JAR version and specific generation configurations. It is crucial to include this file in your version control system (VCS) to ensure consistent generator versions and settings across different developer environments and CI/CD pipelines.
fix
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.
affects: All versions
Errors
Common errors & fixes
openapi-generator: command not found
The `openapi-generator-cli` executable is not found in your system's PATH, or you might be using an outdated command name.
fix
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).
Error: /bin/sh: java: not found
The `openapi-generator-cli` is a wrapper around a Java JAR, and this error indicates that the `java` executable is not found or accessible in your system's PATH.
fix
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.
openapi.yaml can't pass the openapi-generator-cli validate
This error means your OpenAPI Specification file (`openapi.yaml` or `.json`) contains errors or inconsistencies that prevent the generator from processing it correctly.
fix
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.
Download failed, because of: "Error: Unable to query repository..." or "Cannot get openapi-generator-cli version-manager list"
The `openapi-generator-cli` failed to download the necessary Java JAR file from the Maven repository, often due to network connectivity issues, proxy configurations, or problems accessing `search.maven.org`.
fix
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`.
Upgrade
Version history
7.21.0latest on PyPI · released Mar 25, 2026
Audit
Dependencies
pythonrequiredRequired Python version.
java-jdkrequiredRequires JDK 11 or higher to be installed and on system PATH, unless `jdk4py` extra is used.
Agent activity
9 hits · last 30 days
node
6
Resources
openapi-generator-cli — pip install openapi-generator-cli · libregistry