Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

benzene-openapi

An OpenAPI 3.1 document derived from a Benzene Python handler registry — a sibling projection to the JSON Schema this port already derives and to the Cloud Service Profile's ServiceSpec. Depends on benzene-core (schemas + registry) and benzene-http (the /benzene/invoke base and the status mapping).

pip install benzene-openapi

Benzene is message-topic-based, not REST, so there is nothing to hand a Swagger UI or a client generator out of the box. openapi_document closes that gap: it projects the same registry the spec and mesh descriptor read into a standard OpenAPI document, reusing benzene.core.json_schema for every payload schema — never re-deriving one.

from dataclasses import dataclass

from benzene.core import Registry
from benzene.openapi import openapi_document


@dataclass
class PlaceOrder:
    sku: str
    quantity: int


@dataclass
class OrderPlaced:
    order_id: str


registry = Registry().register(
    "orders:place", handler, request_type=PlaceOrder, response_type=OrderPlaced
)

document = openapi_document(registry, title="Orders", version="2.1.0")

Each registered (topic, version) becomes one POST operation under the profile's well-known invoke base (/benzene/invoke/{topic}, with a /{version} segment for a versioned handler), and every Benzene failure status is mapped to its HTTP code through benzene.http.to_http:

{
  "openapi": "3.1.0",
  "info": { "title": "Orders", "version": "2.1.0" },
  "paths": {
    "/benzene/invoke/orders:place": {
      "post": {
        "operationId": "ordersPlace",
        "summary": "Invoke topic orders:place",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OrdersPlaceRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "ok", "content": { "application/json": {
            "schema": { "$ref": "#/components/schemas/OrdersPlaceResponse" } } } },
          "400": { "description": "bad-request", "content": { "application/json": {
            "schema": { "$ref": "#/components/schemas/BenzeneError" } } } }
          // ... one entry per failure status, ordered by HTTP code
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BenzeneError": { "type": "object",
        "properties": { "status": { "type": "string" }, "detail": { "type": "string" } },
        "required": ["status", "detail"] },
      "OrdersPlaceRequest": { "type": "object", "properties": {
        "sku": { "type": "string" }, "quantity": { "type": "integer" } },
        "required": ["sku", "quantity"] },
      "OrdersPlaceResponse": { "type": "object", "properties": {
        "orderId": { "type": "string" } }, "required": ["orderId"] }
    }
  }
}

The payload schemas are exactly what benzene.core.json_schema emits — 2020-12 subset, wire-naming (orderId) property names, required tracking the caller's obligation — and OpenAPI 3.1 adopts that same dialect, so they drop in unchanged. The invoke base comes from benzene.http.StandardPaths; pass server_paths=StandardPaths(prefix="/api") to relocate it.

Output is deterministic: topics are sorted by (id, version), paths and component-schema keys are sorted lexicographically, and responses are ordered by HTTP code, so the same registry always yields an identical, diff-friendly document. Pure — no broker, no third-party package. Mirrors .NET's Benzene.Schema.OpenApi, and contributes the benzene.openapi subpackage to the shared benzene namespace.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

benzene_openapi-0.1.0b1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

benzene_openapi-0.1.0b1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file benzene_openapi-0.1.0b1.tar.gz.

File metadata

  • Download URL: benzene_openapi-0.1.0b1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for benzene_openapi-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 3af33226f78c6e6a5d2018cf05a6a582414a664477368c7d4911357451ec257f
MD5 71d62464e9ea5b7496eb53149ca3bfb4
BLAKE2b-256 b66047e2f62bb45a8baef3e6f570cc358b715f5f4160f032b3af1449ad8ba404

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_openapi-0.1.0b1.tar.gz:

Publisher: release.yml on daniellepelley/benzene-python

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

File details

Details for the file benzene_openapi-0.1.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for benzene_openapi-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8c1f86b0bce224131b21a7c222e18ed6fb41d80ca1475a910839e43546d815
MD5 1b274adc350bb1e0968c89fdd3fcbbe8
BLAKE2b-256 feb65a2a78f10066c5d2747d08c381318f8917b4440a147f72ee3d3092c7d7fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_openapi-0.1.0b1-py3-none-any.whl:

Publisher: release.yml on daniellepelley/benzene-python

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

Release history Release notifications | RSS feed

This release

0.1.0b1 This release

2 files

Supported by

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