ai4os / DEEPaaS

A REST API to serve machine learning and deep learning models
https://deepaas.readthedocs.io
Apache License 2.0
35 stars 15 forks source link

Schema validation from methods? #113

Closed BorjaEst closed 1 year ago

BorjaEst commented 1 year ago

Description

From experience, conventions intriduce problems unless forced or directed. In this particular case, I would use Schemas to ensure the API methods return valid types and fields.

For example, that the return from the function get_metadata returns a lis or, from doc mandatory are ‘description’ and ‘name’ that it returns a dict with at least the fields ‘description’ and ‘name’. Or even some schemas might not accept extra parameters.

In case method return unexpected types or dictionary fields (or missing), it should raise and exception so user is forced to modify it.

Additionally, it should be possible to bypass this in a setting or somethig (i.e. env=development) so when developing the framework it we can test the edited behavior.

In some cases I get:

def get_metadata():
    return [{"name": "rnacontactmap"}]

# API returns
500 Internal Server Error
Server got itself in trouble

Which is not very traceable. It might be easier to raise an Exception to get "Unexpected return value from get_metadata, missing x,x,x"

Versions

2.1.0