pgjones / quart-schema

Quart-Schema is a Quart extension that provides schema validation and auto-generated API documentation.
MIT License
80 stars 23 forks source link

Extending schema generation (openapi.json) #1

Closed danionescu0 closed 1 year ago

danionescu0 commented 2 years ago

Hello there.

I have a question about this package. In have some specific usecase about the generation of openapi.json and i'm trying to override "_build_openapi_schema" function in extension.py I am working on an app that uses nested blueprints, i want to know for every view function :

    for rule in app.url_map.iter_rules():
        func = app.view_functions[rule.endpoint]

What is the parent blueprint to extract the url_prefix from it and add the prefix to the documentation in some way.

Now i am having some trouble getting this information, i've tried looping through the blueprints, my code looks like this:

for blueprint in app.iter_blueprints():
    if len(blueprint._blueprints) > 0:
        for bp in blueprint._blueprints:
            for def_fun in bp[0].deferred_functions:
                print(type(def_fun))
                print(dir(def_fun)

but i'm getting the "deferred_functions", now i need to match the "func" from my fist code block, with the "def_fun" and i don't know how to do that.

I would appreciate any hint you could give me, thank you!

pgjones commented 2 years ago

This might be a bug, I would have expected the paths to be correct, i.e. including the prefixes, as output in the schema. Is this not the case?

danionescu0 commented 2 years ago

The code above will print output like: <class 'function'> ['annotations', 'call', 'class', 'closure', 'code', 'defaults', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'get', 'getattribute', 'globals', 'gt', 'hash', 'init', 'init_subclass', 'kwdefaults', 'le', 'lt', 'module', 'name', 'ne', 'new', 'qualname', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook'] ... ... Which won't give me the actual route

My question is can i get for every function that i loop in this code:

        func = app.view_functions[rule.endpoint]
        # func will be smth like <function get_profile at 0x7fc8da3f1d30>

the actual route ex: "/v2/profiles" ?

The view function looks like this:

profile_bp = Blueprint('profile_bp', __name__)

@profile_bp.route('/v2/profiles', methods=['GET'])
@tag(["PROFILE"])
async def get_profiles():
    ...

for example:

func.get_actual_route() # which should be "/v2/profiles"
pgjones commented 1 year ago

I don't think I understood this. Closing due to time elapsed (probably fixed).