1

My API is returning lists with three entries like so (pseudocode only)

results=[]

for db_row in db_rows:
    result = []
    result.append (db_row[0]) # Name (string)
    result.append (db_row[1]) # Age (int)
    result.append (db_row[2]) # DOB (timestamp)

results.append (results)

I want to create a model for it to show up in swagger docs like so

_results_model = api.model (
    'results model',{
       'results': fields.List(
            fields.String(
                description = 'Name of user',
                min_length = 6,
                max_length = 64,
                pattern = '.*',
                help = "...",
                example = 'john.smith'
            ),
            fields.Integer(
                description = 'Age of user',
                minimum=0,
                help = "...",
                example = '25'
            ),
            fields.DateTime(
                description = 'Date of birth',
                help = "...",
                example = '1918-11-11'
            )
        )
    }
)

But it appears it is not possible to pass more than one parameter to fields.List

'results': fields.List
TypeError: __init__() takes 2 positional arguments but 4 were given

Question: What other option do I have for creating a model to represent a complex list?

  • Did you find a solution for this problem? I'm also searching for a solution to have a list of a complex object – Reggi Jul 07 '22 at 15:09

0 Answers0