Sitemap

Swagger

--

Press enter or click to view image in full size

What is Swagger?

The OpenAPI specification was originally called SwaggerAPI. The Swagger Will be referring to a suite of tools produced to help design, build and Document APIs using the OpenAPI specification.

Swagger tools for API documentation:

  1. Swagger Editor:

The Swagger Editor is primarily a tool for developers to design and buid their RESTful APIs. It also visualizes the API, allowing the team to document the API from the beginning.

2. Swagger Codegen:

It is allows you to create code to simulate server responses to API calls and SDKs(Software Development kits) — it is a set of tools to developers to integrate your API into their system.

3. Swagger UI:

Swagger UI is a tool in which the Technical Write is most likely to get involving to create the swagger API documentation. It provides a visual representaion of the APIs and its documentation. It takes the YAML or JSON file and displays it as interactive documentation, allowing users to try out the API calls in the browser. Showing the available end-points and allowing calls to each end-point.

4. Swagger Hub:

It is the latest offering from the swagger team which provides a hosted Environment combining Swagger Editor, Swagger Codegen and Swagger UI in one interface.

What can you do With Swagger?

Those are the tools that swagger provides, it also provide the Documentation for our APIs . you can also Can Document for Existing APIs and Integrating with any development Environment.

Who can benefit from Swagger?

If speed and reliability are important to your project, creating your API in Swagger Editor means that your developers will have access and live error reports to remain compliant with the specification.

You don’t have an API or API documentation available, but your customers/partners are demanding one. You can use Swagger Editor to design an API and expose endpoints using a mock server, before implementing it in your product.

An API is only as good as its documentation, after all, we can’t use APIs if there are non-existent, incomplete, or difficult-to-use explanations of how the API works. Swagger UI allows you to easily produce documentation from the code.

How to create API documentation using Swagger

Top-down or bottom-up?

Using a top-down approach means starting with Swagger Editor and creating/editing the API documentation along with the API. Whilst this may be the preferred option for most Technical Writers, it is generally seen by development teams as a technique that slows the production of the API itself.

The top-down development approach allows new start-ups or new projects to design the API and use it to generate the OpenAPI specification.

The bottom-up approach (also known as the code-first approach) is much more common and usually involves the Technical Writer taking a completed API and using Swagger UI to create online, interactive documentation.

Editing And Reviewing Swagger Files

Using Swagger Editor allows you to either load your YAML or JSON file. In the Creating the file using the CRUD operations by using POST, PUT, GET, DELETE.

Get Cathrine Peterraj’s stories in your inbox

Join Medium for free to get updates from this writer.

When you creating a file if any error are occur you can see the updating error and also it makes the visual representation to see the Endpoints.

Creating Client Libraries in swagger:

you can create client libraries directly from your Swagger API, for most languages including, Android, C#, C++, Java, Javascript, Go, ObjC, PHP, Python, Ruby, Scala, and many more.

Filtering and Sorting:

In swagger We all know about the Basic CRUD operation. But i recently start to learn new things like Sorting and Filtering. for an Example i take one Endpoint. This is fromathe Get operation to get values using this features.

Because real applications need powerful searching, not only simple searches. Examples:

  • Amazon → price filter
  • Swiggy → rating filter
  • LinkedIn → experience range
  • Gmail → date range filter

This is professional API design.

Endpoint:

/company?filter[rating][gt]=4&filter[employees][lt]=100&sort=-rating

This means:

  • rating > 4
  • employees < 100
  • sort by rating descending

parameters:
name: filter[rating][gt]
in: query
required: false
schema:
type: integer
description: Rating greater than

name: filter[employees][lt]
in: query
required: false
schema:
type: integer
description: Employees less than

name: sort
in: query
required: false
schema:
type: string
description: Sort by field (prefix ‘-’ for descending)

Press enter or click to view image in full size
Press enter or click to view image in full size

In this after sorting by the name , company id, rating….. Now we are sorting the value by page size.

Pagination means dividing data into pages like:

  • page 1 → 10 items
  • page 2 → next 10 items
  • page 3 → next 10 items

This prevents sending 1000+ results at once.

  • name: page
    in: query
    schema:
    type: integer
  • name: size
    in: query
    schema:
    type: integer
Press enter or click to view image in full size

--

--