jmcarp / flask-apispec

MIT License
655 stars 156 forks source link

Is marshall_with unnecessary boilerplate? #174

Open justinmoon opened 4 years ago

justinmoon commented 4 years ago

In principal, it seems like marshall_with is unnecessary boilerplate.

If we could attach a marshmallow.Schema to classes (e.g. database models) returned by Flask routes, flask-apispec should be able to hook into Flask's post-request machinery to infer the relevant schema and serialize them accordingly.

I'd be willing to try to implement this it's a good idea and if someone could give me some pointers on how to do it.

justinmoon commented 4 years ago

After looking at this a little more, it seems you might need a decorator to intercept route return values that Flask doesn't support. after_request can't do this ...

AbdealiLoKo commented 4 years ago

I'm not too clear on how this would look. The return value from flask would be only after a request has actually been made. So, when generating the swagger-ui or swagger.json -> there is no way for the library to know what the schema is - because it does not really call the API