{"id":5348,"library":"openapi-generator-cli","title":"OpenAPI Generator CLI","description":"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.","status":"active","version":"7.21.0","language":"en","source_language":"en","source_url":"https://github.com/OpenAPITools/openapi-generator","tags":["openapi","code-generation","cli","sdk-generation","api-client","java"],"install":[{"cmd":"pip install openapi-generator-cli","lang":"bash","label":"Install base package"},{"cmd":"pip install openapi-generator-cli[jdk4py]","lang":"bash","label":"Install with `jdk4py` (embeds Java runtime)"}],"dependencies":[{"reason":"Required Python version.","package":"python","optional":false},{"reason":"Requires JDK 11 or higher to be installed and on system PATH, unless `jdk4py` extra is used.","package":"java-jdk","optional":false}],"imports":[],"quickstart":{"code":"pip install openapi-generator-cli\n\n# Check installed version\nopenapi-generator-cli version\n\n# Generate a Python client from a public OpenAPI specification\n# This will create a directory named 'my_python_client' containing the generated SDK\nopenapi-generator-cli generate \\\n  -i https://petstore.swagger.io/v2/swagger.json \\\n  -g python \\\n  -o my_python_client\n\n# To use the generated client (example, assuming 'my_python_client' was created):\n# cd my_python_client\n# pip install .\n#\n# Then in a Python script:\n# from openapi_client import api_client, configuration\n# from openapi_client.api import pet_api\n#\n# # Configure API key authorization: api_key\n# config = configuration.Configuration()\n# config.api_key['api_key'] = 'YOUR_API_KEY_HERE'\n#\n# # Create an API client\n# client = api_client.ApiClient(configuration=config)\n# api = pet_api.PetApi(client)\n#\n# # Example: List pets (assuming the generated client structure)\n# # try:\n# #     all_pets = api.find_pets_by_status(status=['available'])\n# #     print(all_pets)\n# # except Exception as e:\n# #     print(f\"Error: {e}\")","lang":"bash","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"All versions, particularly major and minor releases (e.g., v7.12.0, v7.15.0, v7.17.0, v7.21.0)"},{"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]`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}