turner-townsend / flask-pydantic-spec

An Flask OpenAPI library using Pydantic
Apache License 2.0
98 stars 17 forks source link

[Feature request] allow registration of Blueprints #64

Open EdDanileyko opened 9 months ago

EdDanileyko commented 9 months ago

Hello, is it possible to apply the register function to Blueprints and create apidoc on those? If this functionality is already available, then I'm not sure if I'm doing it right.

suggested solution

from flask import Blueprint, Flask

from flask_pydantic_spec import FlaskPydanticSpec

api = Blueprint("my-blueprint", __name__, url_prefix="/path")
api_spec = FlaskPydanticSpec("my api", title="api spec", app=api)

...

With this, open api docs would be registered under the path of the Blueprint.

satya-prime commented 6 months ago

Were you able to use Blueprint with this, am in need of similar thing.

EdDanileyko commented 6 months ago

No I was not. I had to pass the top-level spec object into a function that registered Blueprints and reused that spec:

def make_routes(api: Blueprint, spec: FlaskPydanticSpec):

    # set up logic

    @api.route(...)
    @spec.validate(...)
    def my_route(...):
        ...

    return api