Coder Social home page Coder Social logo

Comments (10)

vryazanov avatar vryazanov commented on June 3, 2024 1

@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

from flask_accepts.

vryazanov avatar vryazanov commented on June 3, 2024 1

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

from flask_accepts.

apryor6 avatar apryor6 commented on June 3, 2024

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?

from flask_accepts.

vladarefiev avatar vladarefiev commented on June 3, 2024

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?

from flask_accepts.

vryazanov avatar vryazanov commented on June 3, 2024

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

from flask_accepts.

vladarefiev avatar vladarefiev commented on June 3, 2024

I need context in @accepts as well

from flask_accepts.

vryazanov avatar vryazanov commented on June 3, 2024

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

from flask_accepts.

apryor6 avatar apryor6 commented on June 3, 2024

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.

from flask_accepts.

apryor6 avatar apryor6 commented on June 3, 2024

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?

from flask_accepts.

vryazanov avatar vryazanov commented on June 3, 2024

@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?

from flask_accepts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.