How to write a great OpenAPI spec
Blog post from Stainless
OpenAPI, originally known as Swagger, is a widely adopted standard for describing HTTP APIs, providing a flexible framework that allows developers to define the structure, methods, inputs, and outputs of an API. Despite being a reactive tool rather than a necessity for API development, OpenAPI supports the creation of consistent API documentation and SDKs, which can otherwise suffer from inconsistencies if done manually. The specification's community-recognized patterns, such as pagination methods and webhook support, alongside its compatibility with various API frameworks like FastAPI, contribute to its popularity. While OpenAPI specifications can be complex, especially with constructs like unions, a bias towards simplicity is advised to minimize usability challenges. OpenAPI also doubles as documentation, with its Markdown support allowing for detailed content creation. Despite potential challenges in managing distributed teams and maintaining consistency, tools like Stainless and Optic assist in refining specifications and detecting breaking changes. These tools offer features such as resource reorganization and diagnostics for resolving type ambiguities, promoting the development of robust and user-friendly APIs.