top | item 37835424

(no title)

barefeg | 2 years ago

How do you make sure that the spec is in sync with the implementation?

discuss

order

anttiviljami|2 years ago

The spec is used in runtime for routing and validation.

https://openapistack.co/docs/examples/building-apis/

barefeg|2 years ago

Thanks. I missed this part https://openapistack.co/docs/openapi-backend/typescript/ so the types are generated for the backend to use. We’ve used API first approach before, but it was very painful to keep the types in sync. Now we’re transitioning to FastAPI which allows to more or less create the OpenAPI types in code (via pydantic which can export the python types into OpenAPI schema).

We now follow a kind of hybrid approach in which the routes and types are created in code first, without actual implementation (just return 404). This auto generates the spec.yaml as well as any vendor code we might need (via client generator). I think this is quite a productive workflow as well because the type generation in code is more convenient than typing yaml by hand and everything is always in sync