zmievsa / cadwyn

Production-ready community-driven modern Stripe-like API versioning in FastAPI
https://docs.cadwyn.dev/
MIT License
186 stars 24 forks source link

BUG: Cadwyn ignores `generate_unique_id_function` for OpenAPI schema #163

Closed isaacharrisholt closed 4 months ago

isaacharrisholt commented 4 months ago

Describe the bug

The generate_unique_id_function kwarg for FastAPI is used in the OpenAPI schema for routing. It doesn't seem to work with Cadwyn.

zmievsa commented 4 months ago

Heard about it before. Will likely publish the fix today.

zmievsa commented 4 months ago

Could you help me out with a reproducible example?

isaacharrisholt commented 4 months ago

Sure!

from datetime import date

from cadwyn import Cadwyn
from cadwyn.structure import VersionBundle, Version

from .data import latest

def generate_openapi_id(route: APIRoute) -> str:
    print(route)
    if not route.tags:
        return route.name
    return f'{str(route.tags[0]).lower().replace(' ', '_')}:{route.name}'

versions = VersionBundle(
    Version(date(2024, 3, 5)),
    latest_schemas_package=latest
)

app = Cadwyn(
    versions=versions,
    generate_unique_id_function=generate_openapi_id,
)

@app.get('/', tags=['misc'])
def home():
    return 'Helo, byd!'

If you run this and go to the docs URL, you'll notice that the URL for the / does not end in misc:home like it should.

zmievsa commented 4 months ago

@isaacharrisholt Fixed everything related to this in 3.12.0. Please, check :pray:

isaacharrisholt commented 3 months ago

Yep! Seems to work