For one put into action these improvement, the swagger.yml document from parts 1 will need to be modified

For one put into action these improvement, the swagger.yml document from parts 1 will need to be modified

Here’s exactly what the preceding rule is performing:

Traces 1 – 9 significance some Flask modules to create the others API replies, and additionally importing the db case from the config.py component. Additionally, it imports the SQLAlchemy Person and Marshmallow PersonSchema classes to get into anyone databases desk and serialize the outcome.

Line 11 initiate this is of read_all() that responds with the REST API Address endpoint attain /api/people and comes back the information inside the person database table sorted in ascending order by last identity.

Traces 19 – 22 tell SQLAlchemy to query the individual databases desk for all your files, kind them in ascending purchase (the standard sorting order), and go back a listing of people Python objects once the changeable people .

Range 24 is when the Marshmallow PersonSchema course meaning turns out to be valuable. Your create an instance on the PersonSchema , moving they the factor many=True . This informs PersonSchema to anticipate an interable to serialize, and that is just what individuals variable is.

Line 25 uses the PersonSchema case variable ( person_schema ), calling their dump() strategy making use of the everyone listing. The result is an object having a data characteristic, an object containing a people record which can be transformed into JSON. This can be came back and changed by Connexion to JSON since a reaction to the others API label.

Mention: people listing variable created on Line 24 above can’t be came back right because Connexion won’t know how to transform the timestamp industry into JSON. Returning the list of visitors without processing they with Marshmallow leads to a long mistake traceback and finally this different: