Comments (11)
from flask_accepts.
I should add that nested Schemas work as far as serialization goes. It’s only the documentation that is lacking, as it just defaults to empty curly braces for the nested object.
from flask_accepts.
Thanks AJ, it works perfectly!
from flask_accepts.
The default values are not currently being passed through, so that is a relatively simple change for me to make within flask_accepts
.
However, it appears that default parameters in the body are not being used in flask-RESTplus. I've got an open discussion upstream with them.
Both of these will need to be resolved, and then this should work.
from flask_accepts.
Nice, I've opened this issue here because I had problems to make this work with RESTplus too and the auto-docs is one of the main reasons to use this framework. Hope its a simple fix
from flask_accepts.
For api.model
, it turns out the proper keyword for modifying the default value is example
and NOT default
. I'll just need to create a mapping from marshmallow default
to this example
param (with a default value if one was not provided), and this should be good to go
from flask_accepts.
Thanks to @j5awry for the help with that
from flask_accepts.
Thanks for bringing this up, should now be fixed. Let me know if there are still issues.
from flask_accepts.
Thanks, it worked! But there there's still is one more small thing. It uses a default name for the nested models and the correct name just for the root, so I think it should display the correct name for the nested models too.
Example: When I use the model Cog nested in the Widget(POST), swagger shows "DefaultResponseModel_2". But when I use just the Cog not as a nested model (GET) it shows it's correct name.
class CogSchema(Schema):
cog_foo = fields.String(default="cog")
cog_baz = fields.Integer(default=999)
class WidgetSchema(Schema):
foo = fields.String(default="test string")
baz = fields.Integer(default=42)
flag = fields.Bool(default=False)
date = fields.Date(default="01-01-1900")
dec = fields.Decimal(default=42.42)
dct = fields.Dict(default={"key": "value"})
cog = fields.Nested(CogSchema)
@api.route("/restplus/make_a_widget")
class WidgetResource(Resource):
@accepts(dict(name="some_arg", type=str), schema=CogSchema, api=api)
@responds(schema=CogSchema, api=api)
def get(self):
from flask import jsonify
return request.parsed_obj
@accepts(dict(name="some_arg", type=str), schema=WidgetSchema, api=api)
@responds(schema=WidgetSchema, api=api)
def post(self):
from flask import jsonify
return request.parsed_obj
from flask_accepts.
Thanks for such careful testing -- this will be a simple change
from flask_accepts.
This should be fixed in 0.11.2
. Give it a try.
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
- Only swagger generation for end-point HOT 10
- 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.