Coder Social home page Coder Social logo

Nested marshmellow schemas about flask_accepts HOT 11 CLOSED

edkb avatar edkb commented on June 11, 2024
Nested marshmellow schemas

from flask_accepts.

Comments (11)

apryor6 avatar apryor6 commented on June 11, 2024 1

from flask_accepts.

apryor6 avatar apryor6 commented on June 11, 2024 1

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.

edkb avatar edkb commented on June 11, 2024 1

Thanks AJ, it works perfectly!

from flask_accepts.

apryor6 avatar apryor6 commented on June 11, 2024

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.

edkb avatar edkb commented on June 11, 2024

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.

apryor6 avatar apryor6 commented on June 11, 2024

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.

apryor6 avatar apryor6 commented on June 11, 2024

Thanks to @j5awry for the help with that

from flask_accepts.

apryor6 avatar apryor6 commented on June 11, 2024

Thanks for bringing this up, should now be fixed. Let me know if there are still issues.

from flask_accepts.

edkb avatar edkb commented on June 11, 2024

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

Screenshot_2019-09-04 API

from flask_accepts.

apryor6 avatar apryor6 commented on June 11, 2024

Thanks for such careful testing -- this will be a simple change

from flask_accepts.

apryor6 avatar apryor6 commented on June 11, 2024

This should be fixed in 0.11.2. Give it a try.

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.