Talk

How Not to Repeat Yourself - pydantic, YAML, Connexion and all the REST of it.

Saturday, May 27

14:40 - 15:10
RoomRisotto
LanguageEnglish
Audience levelIntermediate
Elevator pitch

Let’s face it: Writing YAML sucks! Have a nice decorator generate OpenAPI YAML specs for you, and instead write type hints, docstrings and pydantic schemas like you would have anyway, so you don’t have to repeat yourself.

Abstract

The usual - in fact, recommended - way to write a REST API with Connexion is specs first, i.e. you write an OpenAPI YAML document describing endpoints (“paths”), parameters, and response schemas, and then the endpoint functions, and let Connexion do the rest, including providing a nice Swagger UI. It is how we started as well, with our Syndication Partner API for our price comparison business.

However, this approach is not without its drawbacks: code, data types and documentation are spread across multiple files, it is hard to keep them in sync, and harder still to not repeat yourself. In this talk we will explore possibilities to honor D.R.Y. and keep stuff in almost one place, with the help of pydantic’s OpenAPI schema generator, type hints, docstrings, lots of inspection, and a convenient @endpoint decorator to tie it all together.

And we get to keep our nice Swagger UI.

TagsDocumentation, REST, Best Practice
participant photo

Dr. Patrick Schemitz

Patrick is a programmer. He has been programming for a long time. He has written code on computers with 1 kB of memory. He has seen code horrors beyond your imagination, including in languages so old even the elves have long since forgotten about them. The last 20 years he mostly did Python, which is a respite. He has a background (and a Ph.D.) in particle physics and is still in love with the Scientific Method. He works at solute GmbH, a German e-commerce company.