DEV Community

Cover image for Why use Swagger for creating and documenting APIs
Diana Maltseva
Diana Maltseva

Posted on

Why use Swagger for creating and documenting APIs

API is the best way of connecting software engineers and sharing valuable data and developments. Through API, programmers access a network of shared pieces of code and useful experiences. However, to access them they need clear documentation.

Noteworthy that earlier there was not only industry standard for developing APIs, but there was no standard for documenting them. Swagger emerged as an approach to building APIs and soon became the most popular framework for this purpose.

Two years ago Swagger specification was renamed the OpenAPI Specification and moved to the Linux Foundation.

What's important, a Swagger framework is supported by such corporations as Google, Microsoft, and Atlassian. Also, giants like Yelp and Netflix have already used it in their work.

What is Swagger

Swagger is the largest framework for designing APIs using a common language and enabling the development across the whole API lifecycle, including documentation, design, testing, and deployment.

The framework provides a set of tools that help programmers generate client or server code and install self-generated documentation for web services.

However, there are many other frameworks like RAML, APIBlueprint, Summation, etc. So, how to explain the huge popularity of Swagger? The answer is that it offers a lot of advantages and besides creating clear documentation provides other great things.

Swagger framework tools and benefits

First and foremost, as Swagger uses a common language that everyone can understand, it’s easily comprehensible for both developers and non-developers.

Thus, software developers, product and project managers, business analysts and even potential customers can access API design.

Also, as Swagger is easily adjustable, it can be successfully used for API testing and bug fixing. Another important point is that the same documentation can be used for accelerating various API-dependent processes.

Swagger provides a set of great tools for designing APIs and improving the work with web services:

  • Swagger Editor – enables to write API documentation, design and describe new APIs, and edit the existing ones. The first open-source editor visually renders OAS/Swagger definition with error handling and real-time feedback.
  • Swagger Codegen – allows developers to generate client library code for different platforms. As the tool helps facilitate the dev process by generating server stubs and client SDKs, software engineers get the ability to faster build your API and better focus on its adoption.
  • Swagger UI – allows engineers to get self-generated documentation for different platforms. Swagger UI is a fully customizable tool that can be hosted in any environment. A great plus is that it enables developers to save a lot of time for API documentation.
  • Swagger Inspector – a tool for testing and auto-generating OpenAPI documentation for any API. Swagger Inspector allows to easily validate and test APIs with no limits on what you test. Tests are automatically saved in the cloud with a simple access.
  • Also, find out how to set up Swagger and use it for designing APIs.

    Top comments (6)

    Collapse
     
    millebi profile image
    Bill Miller

    A few thoughts that may be helpful:

    I'm not sure if the newest version is the same (I assume it is), but the older version of Swagger allowed for dynamic generation of your API as well as a static (compile time) version.

    The dynamic version essentially creates an API to call your API at runtime, but it is also running code inside your server... which may/may not be a security/performance problem for your application.

    The static version generates the needed files during compile and the files are then deployed using simple HTML deployment. This makes them simpler to deploy and not have any extra security/performance risks to your application (other than serving the files of course).

    The two methods of deployment end up having implied features not explicity defined by the authors, like:

    • Dev/QA: Dynamic publishing of the API, so that it is always accurate.
    • Production: Static publishing of your API to reduce risk AND control which features you want to advertise to callers (i.e. Display a subset of what's actually available until new features are fully tested and scaled)

    Mixing the two types depending on the context can be extremely useful and have the same upfront "costs" to implement (i.e. The information entered into the code is the same for both methods).

    Collapse
     
    rafalpienkowski profile image
    Rafal Pienkowski

    Nice post.
    Nowadays I can't image the creation of an open to the Internet API which will be accessible to anyone without Swagger Docs page. For my OpenAPI Specification is a "REST equivalent" of SOAP's WSDL.

    Collapse
     
    kayis profile image
    K

    Nice!

    I saw AWS uses Swagger for API-Gateway definitions. Most of the time I got by by using CloudFormation/AWS SAM to define simple stuff, but sometimes they wrote about how you need Swagger for a feature.

    I should probably learn about it :D

    Collapse
     
    colinmtech profile image
    Colin Morgan

    Is there a convenient way to break swagger docs into multiple files? I have a really hard time reading and working in huge monolithic JSON/yaml files. I found that, even for moderate sized APIs, the swagger doc became ridiculously large and difficult to work with.

    I like the idea of swagger, I just don't use it because I become so frustrated trying to maintain it.

    Collapse
     
    dianamaltseva8 profile image
    Diana Maltseva

    You can delve into the issue by checking out this link stackoverflow.com/questions/355479.... Here you'll find how to generate documentation using swashbuckle for WebApi 2.

    Collapse
     
    suraj_rtiwari profile image
    Suraj Tiwari

    Nice, post