Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make schema extensible #40

Open
soon opened this issue May 22, 2023 · 1 comment
Open

Make schema extensible #40

soon opened this issue May 22, 2023 · 1 comment

Comments

@soon
Copy link

soon commented May 22, 2023

Right now it is impossible to customise schema without subclassing QuartSchema and using it everywhere. E.g. I needed to add operationId to my schema, and the only way is to manually change generated schema in the overridden QuartSchema.openapi method.

My proposal is to provide extension points so users can change schema during generation time. This may look like the following:

def method_schema_generator():
    # some magic decorator provided by library which does the following:
    # 1. Registers user-defined extension in the method
    # 2. Wraps extension in a way to pass schema during generation time, so user can "bind" all other arguments
    # 
    # Then during schema generation step QuartSchema calls registered extension 
    # passing schema to it along with all arguments bound by user 
    ...

# user-defined extension
@method_schema_generator
def operation_id(value, schema):
    schema['operationId'] = value

# usage
@app.post("/")
@validate_request(Todo)
@validate_response(Todo, 201)
@operation_id("create_todo")
async def create_todo(data: Todo) -> tuple[Todo, int]:
    ...
@mst-ableton
Copy link
Contributor

I think a more extensible schema generation would be nice, but I wanted to mention that I've just submitted a PR to add operationID support here: #41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants