Comments (10)
@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.
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.
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.
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.
let's just add schema_context:Optional[dict]
parameter to respond
decorator at the beginning. that will make me happy ๐
from flask_accepts.
I need context
in @accepts
as well
from flask_accepts.
oops, sure, I meant accepts
, there is no point to pass it to respond
from flask_accepts.
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.
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.
@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)
- When using the @responds decorator, X-Fields headers are automatically applied to the swagger request HOT 2
- Swagger fails to load when a schema does not have a default set in one of the fields. HOT 4
- Marshmallow schema for form data HOT 1
- Query parameter and header schemas do not respect the data key attribute HOT 1
- Passing a schema type to the `schema` argument of @accepts ignores the type's Meta attributes
- Marshmallow 4 breaking changes
- Overriding flask_restx field
- Nested Marshmallow Schemas throwing error on Swagger HOT 5
- Partial param for Schema loading HOT 4
- [Q] Customize schema_errors? HOT 2
- What is the best practice for file uploads? HOT 2
- Working with UUIDs, Marshmallow & 'missing' fields
- Nested schemas with many=true do not generate a list of schemas in the swagger docs HOT 6
- The new partial keyword of accepts() breaks the marshmallow schema
- Using multiple different schemas in accepts decorator raises KeyError if there is a ValidationError
- Cookie header validation works on gunicorn, does not on NGINX
- Static typing on request.parsed_obj
- More forgiving loading of the JSON schema payload ignoring the mimetype
- Skip response fields where value is None
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask_accepts.