Jentic OpenAPI Redocly Transformer Backend
Project description
jentic-openapi-transformer-redocly
A Python library that provides OpenAPI document bundling functionality using Redocly CLI. This package is part of the Jentic OpenAPI Tools ecosystem and implements the transformer backend pattern for bundling OpenAPI documents by resolving external references.
Features
- Multiple Input Formats: Support for file paths, URIs, and Python dictionaries
- External Reference Resolution: Automatically resolves
$refreferences across multiple files - Robust Error Handling: Comprehensive error reporting with detailed messages
- Timeout Configuration: Configurable timeout for long-running bundling operations
- Type Safety: Full type hints and comprehensive documentation
Installation
pip install jentic-openapi-transformer-redocly
Prerequisites:
- Node.js and npm (for Redocly CLI)
- Python 3.11+
The Redocly CLI will be automatically downloaded via npx on first use, or you can install it globally:
npm install -g @redocly/cli@2.15.1
Quick Start
Basic Usage
from jentic.apitools.openapi.transformer.bundler.backends.redocly import RedoclyBundlerBackend
# Create a bundler instance
bundler = RedoclyBundlerBackend()
# Bundle an OpenAPI document from a file path
result = bundler.bundle("/path/to/your/openapi.yaml")
print(result) # Bundled OpenAPI document as JSON string
Using with Dictionary Input
# Bundle an OpenAPI document from a Python dictionary
openapi_dict = {
"openapi": "3.0.3",
"info": {"title": "My API", "version": "1.0.0"},
"paths": {
"/users": {
"get": {
"responses": {"200": {"description": "Success"}}
}
}
}
}
result = bundler.bundle(openapi_dict)
parsed_result = json.loads(result)
Custom Configuration
# Custom Redocly CLI path and timeout
bundler = RedoclyBundlerBackend(
redocly_path="redocly", # Use global redocly installation
timeout=60.0 # 60 second timeout
)
result = bundler.bundle("https://petstore3.swagger.io/api/v3/openapi.json")
Advanced Usage
Error Handling
The bundler provides detailed error reporting for various failure scenarios:
from jentic.apitools.openapi.transformer.bundler.backends.redocly import RedoclyBundlerBackend
from jentic.apitools.openapi.common.subproc import SubprocessExecutionError
bundler = RedoclyBundlerBackend()
try:
result = bundler.bundle("/path/to/openapi.yaml")
except TypeError as e:
print(f"Unsupported document type: {e}")
except SubprocessExecutionError as e:
print(f"Redocly CLI execution failed: {e}")
except RuntimeError as e:
print(f"Bundling failed: {e}")
Supported Input Formats
The bundler accepts the following input formats (returned by accepts() method):
"uri": File paths or URIs pointing to OpenAPI documents"dict": Python dictionaries containing OpenAPI document data
Testing
Integration Tests
The integration tests require Redocly CLI to be available. They will be automatically skipped if Redocly is not installed.
Run the integration test:
uv run --package jentic-openapi-transformer-redocly pytest packages/jentic-openapi-transformer-redocly -v
API Reference
RedoclyBundler
class RedoclyBundlerBackend(BaseBundlerBackend):
def __init__(
self,
redocly_path: str = "npx --yes @redocly/cli@2.20.0",
timeout: float = 600.0,
allowed_base_dir: str | Path | None = None,
) -> None
Parameters:
redocly_path: Path to Redocly CLI executabletimeout: Maximum execution time in secondsallowed_base_dir: Optional base directory for path security validation. When set, all document paths are validated to be within this directory, providing defense against path traversal attacks. WhenNone(default), only file extension validation is performed (no base directory containment check). Recommended for web services or untrusted input (optional)
Methods:
accepts() -> list[str]: Returns supported document format identifiersbundle(document: str | dict, base_url: str | None = None) -> str: Bundles an OpenAPI document
Exceptions:
TypeError: Document type is not supportedRuntimeError: Redocly execution fails or produces invalid outputSubprocessExecutionError: Redocly times out or fails to startPathTraversalError: Document path attempts to escape allowed_base_dir (only whenallowed_base_diris set)InvalidExtensionError: Document path has disallowed file extension (always checked for filesystem paths)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jentic_openapi_transformer_redocly-1.0.0a45.tar.gz.
File metadata
- Download URL: jentic_openapi_transformer_redocly-1.0.0a45.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c14dccea5642c5fd44e04e708eb5cca1eb68e49b37da2564c88451a03e529bc6
|
|
| MD5 |
59575f1cf335e296c8662fbbdd506b3e
|
|
| BLAKE2b-256 |
140a8261098af86472159dbf910c3350f365e22c8e8b39448cd415f57f5f248e
|
Provenance
The following attestation bundles were made for jentic_openapi_transformer_redocly-1.0.0a45.tar.gz:
Publisher:
release.yml on jentic/jentic-openapi-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jentic_openapi_transformer_redocly-1.0.0a45.tar.gz -
Subject digest:
c14dccea5642c5fd44e04e708eb5cca1eb68e49b37da2564c88451a03e529bc6 - Sigstore transparency entry: 1066669008
- Sigstore integration time:
-
Permalink:
jentic/jentic-openapi-tools@119834da8b938509548f8e0b38a03db9bdc387b1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jentic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@119834da8b938509548f8e0b38a03db9bdc387b1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jentic_openapi_transformer_redocly-1.0.0a45-py3-none-any.whl.
File metadata
- Download URL: jentic_openapi_transformer_redocly-1.0.0a45-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d980d655d6981c7ea999c5b7a2f352d6dad42dffa7f96d1110d017b51110c03a
|
|
| MD5 |
234d46ee6647a153d1cecebe1fa5eebe
|
|
| BLAKE2b-256 |
fcdb79b60b5a2a7978cbd80b938c223fe8eacafed3495033284c62babc58b74d
|
Provenance
The following attestation bundles were made for jentic_openapi_transformer_redocly-1.0.0a45-py3-none-any.whl:
Publisher:
release.yml on jentic/jentic-openapi-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jentic_openapi_transformer_redocly-1.0.0a45-py3-none-any.whl -
Subject digest:
d980d655d6981c7ea999c5b7a2f352d6dad42dffa7f96d1110d017b51110c03a - Sigstore transparency entry: 1066669710
- Sigstore integration time:
-
Permalink:
jentic/jentic-openapi-tools@119834da8b938509548f8e0b38a03db9bdc387b1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jentic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@119834da8b938509548f8e0b38a03db9bdc387b1 -
Trigger Event:
workflow_dispatch
-
Statement type: