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

Only swagger generation for end-point #83

Open
vladarefiev opened this issue Jun 8, 2020 · 10 comments
Open

Only swagger generation for end-point #83

vladarefiev opened this issue Jun 8, 2020 · 10 comments

Comments

@vladarefiev
Copy link

Hello @apryor6 .
I am happy using this library, but sometimes I want to do something before validation, for example pass context to Marshmallow Schema, but I still want to generate swagger for this API.

I'd like to contribute to the library implementing such functionality. What is the best way to do it to your opinion?

  • extend existing both accepts and responds decorators with validate: bool param.
  • create new decorator @swagger just for generation swagger spec.

What do you think?

@vladarefiev vladarefiev changed the title Only swagger generation Only swagger generation for end-point Jun 8, 2020
@apryor6
Copy link
Owner

apryor6 commented Jun 13, 2020

Hi there! A clarifying question so that I better understand the desire - are you referring to wanting to use the Marshmallow validators and have those requirements displayed within Swagger or something else?

@vladarefiev
Copy link
Author

Hey @apryor6
Sometimes I can't use @accepts , but I still want to display model generated from Marshmallow schema in Swagger. So, I supposed two options how to implement it, I suggested creating a new decorator like @swagger(api, input_schema, output_schema) which helps to display your Marshmallow schemas in Swagger. What do you think?

@vryazanov
Copy link

vryazanov commented Jun 13, 2020

@vladarefiev @apryor6 hey guys, I'm interesting in this topic as well. The main problem to me is that I cannot pass some extra params to Schema constructor directly, for one case I want to pass partial (but I know that it'is already implemented), for another case it could be a context.
That's deffinetly not a problem with partial parameter, but there are some problems with context, since in many cases the context should be generated in runtime, not import time (like if a part of context should be some data from request or request itself).
Maybe the high-level interface could look like:

def get_context():
    return {'request': flask.request}


class Resource(...):
        @responds(schema=WidgetSchema, schema_context=get_context, api=api)
        def post(self):
            pass

and somewhere under the hood:

def get_create_schema(schema_class, schema_context):
    return schema_class(...., context=schema_context())

wdyt?
let me know if I can help somehow

@vryazanov
Copy link

let's just add schema_context:Optional[dict] parameter to respond decorator at the beginning. that will make me happy 😄

@vladarefiev
Copy link
Author

I need context in @accepts as well

@vryazanov
Copy link

oops, sure, I meant accepts, there is no point to pass it to respond

@apryor6
Copy link
Owner

apryor6 commented Jun 13, 2020

Ah okay now I follow you - thanks for the example. I think your implementation about is exactly what I would suggest. If you want to contribute an implementation with supporting tests, I would be happy to review and accept a PR.

@vryazanov
Copy link

Started implementation and realized that we can pass an instance of schema to the decorator, so it's not a problem to pass context into constructor directly. as well as many parameter. according to c32b169

@apryor6
Copy link
Owner

apryor6 commented Jun 18, 2020

That’s probably the simplest approach - does it fully resolve this issue, or is there a case where you might need schema construction to happen at request time outside of what can be dynamic via the context param?

@vryazanov
Copy link

@apryor6 yes, at least it's good to automatically update the schema context with query params

class Resource(...):
        @responds(schema=WidgetSchema, api=api)
        def post(self, some_id: int):
            pass

so that some_id should go to context without any extra code.
may be before this line https://github.com/apryor6/flask_accepts/blob/master/flask_accepts/decorators/decorators.py#L119
should be something like this: schema.context.update(**kwargs)

wdyt?

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

3 participants