biosustain / potion

Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
http://potion.readthedocs.io
Other
488 stars 51 forks source link

Cross resource fields.Inline does not updates the schema accordingly #140

Closed dappiu closed 6 years ago

dappiu commented 6 years ago

I have a resource with a Route that instead of returning the own schema, should return the schema of another ModelResource. I'll explain with some code that is purely a demo but should give the idea:

class UserResource(ModelResource):
    class Meta:
        model = User

class AuthResource(Resource):
    class Meta:
        name = 'auth'

    @Route.PUT
    @jwt_required
    def link_facebook_account(self, fb_user_token: fields.String()) -> fields.Inline('user'):
        user = User.query.get(get_jwt_identity())
        link_fb_account(user, fb_user_token)
        return user

Since the link_facebook_account annotates the user resource as its output value, I'm expecting that the /auth/schema endpoint should describe the targetSchema for the link-facebook-account link like this:

"targetSchema": { "$ref": "/api/v1/user/schema" }

But what I have is: "targetSchema": { "$ref": "/api/v1/auth/schema" }

So the targetSchema refers to the own schema of AuthResource and not to the UserResource schema. Anyway calling the endpoint produces the correct result returning the serialized user object.