Polymorphic types with python-eve

I would like to have an endpoint that validates multiple circuits. I have read the docs and some of Eve's codes, but it is not immediately clear to me that this is possible. Here's a simple example of what I would like to do:

POST http://eve-server/vehicles/
{
    type: 'Boat',
    manufacturer: 'Seadoo',
    propeller_size: 2.0
}

POST http://eve-server/vehicles/
{
    type: 'Airplane',
    manufacturer: 'Boeing',
    wing_span: 195.8
}

GET http://eve-server/vehicles/

[
    {type: 'Boat', manufacturer: 'Seadoo', propeller_size: 2.0},
    {type: 'Airplane', manufacturer: 'Boeing', wing_span: 195.8}
]

      

Does Eve / Cerberus support polymorphic types? If not, is it possible to wire in something like JSON Schema that supports this while preserving the referential integrity provided data_relation

?

+3


source to share


1 answer


Hmm, I'm not sure I understand your question. At first glance, I would say that this is how a normal API endpoint behaves. I am assuming that propeller_size

and wing_span

are optional fields. You can post one document at a time, like in your example:

POST http://eve-server/vehicles/
{
    type: 'Boat',
    manufacturer: 'Seadoo',
    propeller_size: 2.0
}

POST http://eve-server/vehicles/
{
    type: 'Airplane',
    manufacturer: 'Boeing',
    wing_span: 195.8
}

      

or you can post a list of documents:

POST http://eve-server/vehicles/    
[
    {type: 'Boat', manufacturer: 'Seadoo', propeller_size: 2.0},
    {type: 'Airplane', manufacturer: 'Boeing', wing_span: 195.8}
]

      



In both cases, when you get on the same endpoint, you will get a list of available documents:

GET http://eve-server/vehicles/    
{
    "_items": [
        {type: 'Boat', manufacturer: 'Seadoo', propeller_size: 2.0},
        {type: 'Airplane', manufacturer: 'Boeing', wing_span: 195.8}
    ]
    "_meta": {
        "total": 259,
        "page": 1,
        "size": 25
    }
}

      

Let's assume HATEOAS is disabled, otherwise you will also get a meta field _links

.

That being said, just keep in mind that you can set up multiple endpoints that target the same datasource , so you can only have a POST endpoint with its own schema and validation, and possibly a GET-only endpoint with a different schema perhaps because on that endpoint, you are returning fields that were added via mongo, or event hooks (callbacks), or via other API endpoints.

+1


source







All Articles