Skip to main content

Jentic OpenAPI Transformer

Project description

jentic-openapi-transformer

A Python library for transforming and bundling OpenAPI documents. This package is part of the Jentic OpenAPI Tools ecosystem and provides a flexible, extensible architecture for OpenAPI document transformation with support for pluggable backends.

Features

  • Pluggable Backend Architecture: Support for multiple bundling strategies via entry points
  • Multiple Input Formats: Accept OpenAPI documents as file paths, URIs, or Python dictionaries
  • Flexible Output Types: Return bundled documents as JSON strings or Python dictionaries
  • Type Safety: Full type hints with overloaded methods for precise return types
  • Extensible Design: Easy integration of third-party bundling backends

Installation

pip install jentic-openapi-transformer

Prerequisites:

  • Python 3.11+

Optional Backends:

For advanced bundling with external reference resolution:

pip install jentic-openapi-transformer-redocly

Quick Start

Basic Bundling

from jentic.apitools.openapi.transformer.bundler.core import OpenAPIBundler

# Create a bundler with the default backend
bundler = OpenAPIBundler()

# Bundle from a file URI and return as dictionary
result = bundler.bundle("file:///path/to/openapi.yaml", return_type=dict)
print(result["info"]["title"])

# Bundle from a file URI and return as JSON string
json_result = bundler.bundle("file:///path/to/openapi.yaml", return_type=str)
print(json_result)

Bundle from Dictionary

# Bundle an OpenAPI document from a Python dictionary
openapi_doc = {
    "openapi": "3.1.0",
    "info": {"title": "My API", "version": "1.0.0"},
    "paths": {
        "/users": {
            "get": {
                "summary": "Get users",
                "responses": {"200": {"description": "Success"}}
            }
        }
    }
}

result = bundler.bundle(openapi_doc, return_type=dict)

Using Different Backends

# Use the default backend (no external reference resolution)
bundler = OpenAPIBundler("default")
result = bundler.bundle("/path/to/openapi.yaml", return_type=dict)

# Use the Redocly backend (requires jentic-openapi-transformer-redocly)
bundler = OpenAPIBundler("redocly")
result = bundler.bundle("/path/to/openapi.yaml", return_type=dict)

Configuration Options

Backend Selection

# Use default backend by name
bundler = OpenAPIBundler("default")

# Pass a backend instance directly
from jentic.apitools.openapi.transformer.bundler.backends.default import DefaultBundlerBackend
backend = DefaultBundlerBackend()
bundler = OpenAPIBundler(backend=backend)

# Pass a backend class
bundler = OpenAPIBundler(backend=DefaultBundlerBackend)

Custom Parser

from jentic.apitools.openapi.parser.core import OpenAPIParser

# Use a custom parser instance
parser = OpenAPIParser()
bundler = OpenAPIBundler(parser=parser)

Return Type Control

# Return as dictionary (typed)
dict_result: dict = bundler.bundle(document, return_type=dict)

# Return as JSON string (typed)
str_result: str = bundler.bundle(document, return_type=str)

# Return as plain (auto-detected type)
plain_result = bundler.bundle(document)

Strict Mode

# Enable strict type checking for return type
try:
    result = bundler.bundle(document, return_type=dict, strict=True)
except TypeError as e:
    print(f"Type mismatch: {e}")

Testing

Run the test suite:

uv run --package jentic-openapi-transformer pytest packages/jentic-openapi-transformer -v

Integration Tests

The package includes integration tests for backend discovery and bundling. Tests requiring external backends (like Redocly) will be automatically skipped if the backend package is not installed.

API Reference

OpenAPIBundler

class OpenAPIBundler:
    def __init__(
        self,
        backend: str | BaseBundlerBackend | Type[BaseBundlerBackend] | None = None,
        parser: OpenAPIParser | None = None,
    ) -> None

Parameters:

  • backend: Backend name, instance, or class. Defaults to "default"
  • parser: Custom OpenAPIParser instance (optional)

Methods:

  • bundle(document: str | dict, base_url: str | None = None, *, return_type: type[T] | None = None, strict: bool = False) -> T
    • Bundles an OpenAPI document with specified return type
    • document: File path, URI, JSON/YAML string, or dictionary
    • base_url: Optional base URL for resolving relative references
    • return_type: Desired output type (str, dict, or None for auto)
    • strict: Enable strict return type validation

Available Backends

base

Abstract base class for custom bundler backends. Not for direct use.

default

Basic bundling backend without external reference resolution. Suitable for single-file OpenAPI documents.

redocly (Optional)

Advanced bundling backend using Redocly CLI with full reference resolution across multiple files.

Install: pip install jentic-openapi-transformer-redocly

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

jentic_openapi_transformer-1.0.0a48.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jentic_openapi_transformer-1.0.0a48-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file jentic_openapi_transformer-1.0.0a48.tar.gz.

File metadata

File hashes

Hashes for jentic_openapi_transformer-1.0.0a48.tar.gz
Algorithm Hash digest
SHA256 c64ef5f313f86c93669567f84b7e2f0d8cf855a49675c636c688342a64045e92
MD5 0e77482dba8ac3a235e93e3c75551006
BLAKE2b-256 df71678e9b621a44d2fa973a6e4ae5de06c8b2719ee701e5e316276aaa7867de

See more details on using hashes here.

Provenance

The following attestation bundles were made for jentic_openapi_transformer-1.0.0a48.tar.gz:

Publisher: release.yml on jentic/jentic-openapi-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jentic_openapi_transformer-1.0.0a48-py3-none-any.whl.

File metadata

File hashes

Hashes for jentic_openapi_transformer-1.0.0a48-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac730672894f66a3375b5233d13f690341bfb4c3f2711df8f9baaf42d85d36f
MD5 8eceec294d8bec73bcae23a34ae8eda3
BLAKE2b-256 1ca071b2bc5ebf0aea95c559b0613fac9fa271cfe775f3f0e5145189b8042d0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for jentic_openapi_transformer-1.0.0a48-py3-none-any.whl:

Publisher: release.yml on jentic/jentic-openapi-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page