Skip to main content

OpenAPI 3.1 generation for hayate: routes from app.routes, schemas from your validators

Project description

hayate-openapi

OpenAPI 3.1 generation for hayate — built from what your app already knows: routes from app.routes, request schemas from your validators, response schemas from one decorator. No magic inference, no schema-library lock-in.

Status: alpha (0.1.x). The emitted document passes the official openapi-spec-validator and feeds openapi-typescript for end-to-end TypeScript types. The internal design memo (Japanese, per project convention) lives in DESIGN.md. Version 0.1.1 also aligns package metadata and the protected release path; the OpenAPI surface is unchanged from 0.1.0.

from hayate import Hayate
from hayate_openapi import OpenApi, describe, validated
import msgspec

class BookIn(msgspec.Struct):
    title: str

app = Hayate()

@app.post("/books", validated("json", BookIn))   # validator + schema tag in one
@describe(status=201, summary="Create a book")
async def create(c):
    book = c.req.valid("json")     # BookIn instance — validation still runs
    return c.json({"title": book.title}, status=201)

OpenApi(app, title="Bookstore", version="1.0.0").register(app)
# GET /openapi.json is live; or emit statically:
#   python -m hayate_openapi main:app --title Bookstore --version 1.0.0

How it works

Source What it provides
app.routes (hayate ≥ 0.8) every method + path, converted to OpenAPI templating (:id{id})
validated(target, T) request body / query / form schemas — a tagging wrapper around the core validator, behavior-identical
@describe(...) summary, tags, response schemas, operationId — all optional, all additive

Schema conversion goes through a SchemaProvider protocol. msgspec and pydantic are auto-detected (guarded imports); a plain dict is taken as literal JSON Schema. The package itself depends only on hayate.

TypeScript types, the recommended recipe:

python -m hayate_openapi main:app --title API --version 1.0.0 -o openapi.json
npx openapi-typescript openapi.json -o src/api-types.ts

Docs UI: serve the JSON and point any renderer at it — e.g. one line of Scalar or Redoc HTML. Nothing is bundled.

What is documented (and what is not)

  • Routes with real HTTP verbs; WebSocket routes and wildcard mounts (/api/auth/*) are skipped.
  • Responses you declare. Undeclared operations get a bare 200 — the generator never invents schemas.
  • Operations with a validator automatically document the 400 application/problem+json failure the framework actually returns.

License

MIT

Project details


Download files

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

Source Distribution

hayate_openapi-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

hayate_openapi-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file hayate_openapi-0.1.1.tar.gz.

File metadata

  • Download URL: hayate_openapi-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_openapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9baf49d7089dd4ddd73d09cafa8eb79479c108438c241a93bf2eae36e06a795f
MD5 defd013cae76aaab196ba761302e7309
BLAKE2b-256 d0a613f3b0c62506469a69739fd899d21f9238eb7dc86d1435c6739734df3622

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_openapi-0.1.1.tar.gz:

Publisher: release.yml on hayatepy/hayate-openapi

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

File details

Details for the file hayate_openapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hayate_openapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_openapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2defd9d0c9088fbaaeb62f6d326589684dab084fd33e45de03340c5bea55ee0c
MD5 ee6d771b9044f4feefc091ba1594bf07
BLAKE2b-256 54a5228464f3bccfb6a79abd4fb34a730ef11217db3f65bb88a8538836755f72

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_openapi-0.1.1-py3-none-any.whl:

Publisher: release.yml on hayatepy/hayate-openapi

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