Logo

dev-resources.site

for different kinds of informations.

Introducing Swama: A CLI Tool for Swagger/OpenAPI Interactions

Published at
9/16/2024
Categories
swagger
openapi
swama
tooling
Author
idsulik
Categories
4 categories in total
swagger
open
openapi
open
swama
open
tooling
open
Author
7 person written this
idsulik
open
Introducing Swama: A CLI Tool for Swagger/OpenAPI Interactions

APIs have become a critical part of software development. However, working with Swagger or OpenAPI specifications can sometimes feel like a manual and repetitive process. Wouldn't it be great if you could easily interact with these API specifications directly from your terminal?

That's where Swama comes in. Swama is a CLI tool built for developers who work with Swagger/OpenAPI specifications. It allows you to effortlessly explore, manipulate, and convert API definitions from the command line.

In this post, I’ll walk you through Swama’s features, how to install it, and how to use it to streamline your API development process.


What is Swama?

Swama is a command-line interface (CLI) tool designed to help developers interact with Swagger/OpenAPI definitions. It provides a simple way to list API endpoints, view detailed endpoint information, convert endpoints into curl or fetch commands, and more.

If you are tired of manually browsing through large API definitions or testing endpoints via Swagger UI, Swama is the perfect solution to boost your productivity.

Why Use Swama?

  • No More Swagger UI: Browse and explore APIs directly from the command line.
  • Endpoint Conversion: Quickly convert API endpoints into curl or fetch commands for easy testing.
  • Filtering & Grouping: Filter and group endpoints by method, tags, or paths.
  • Binaries for All Platforms: Pre-built binaries are available for Linux, macOS, and Windows.

Key Features

Here’s a rundown of some of Swama’s key features:

1. List API Endpoints

Swama allows you to list all available API endpoints in a Swagger or OpenAPI file. You can filter endpoints by HTTP method, tags, or specific paths using wildcard matching.

swama endpoints list --method GET --tag user
Enter fullscreen mode Exit fullscreen mode

This command lists all GET endpoints tagged with user in the specified Swagger file.

Image description

2. View Endpoint Details

Want to know more about a specific endpoint? Swama allows you to view detailed information about any endpoint in the API specification.

swama endpoints view --endpoint /user --method GET
Enter fullscreen mode Exit fullscreen mode

The above command will show detailed information about the /user endpoint, including its summary, request body, and response details.

Image description

3. Convert Endpoints to curl or fetch

Testing an API endpoint often involves writing curl or fetch commands. Swama simplifies this process by allowing you to instantly convert an API endpoint into one of these commands.

swama endpoints convert --file swagger.yaml --endpoint /api/users --method POST --type curl
Enter fullscreen mode Exit fullscreen mode

This command converts the POST /api/users endpoint into a curl command that you can use in your terminal.

4. Explore Tags

APIs often use tags to categorize endpoints. Swama lets you list all tags in the API specification:

swama tags list --file swagger.yaml
Enter fullscreen mode Exit fullscreen mode

With this command, you can easily see how the API is structured and what each tag represents.

5. List Servers

Many APIs are deployed across multiple servers (staging, production, etc.). Swama makes it easy to view all the servers listed in your API definition:

swama servers list --file swagger.yaml
Enter fullscreen mode Exit fullscreen mode

This command gives you a quick overview of the environments your API is running in.


Installation

You can install Swama using the pre-built binaries available on the GitHub releases page. Follow these steps to get started:

  1. Download the latest release for your platform (Linux, macOS, or Windows) from GitHub Releases.

  2. Move the binary to your $PATH:

    • On Linux/macOS:
     sudo mv swama /usr/local/bin/
     sudo chmod +x /usr/local/bin/swama
    
  • On Windows: Add the binary to your system’s PATH to run it globally.

Alternatively, you can build Swama from source:

git clone https://github.com/idsulik/swama
cd swama
go build -o swama
Enter fullscreen mode Exit fullscreen mode

Once installed, run the following to verify the installation:

swama --help
Enter fullscreen mode Exit fullscreen mode

Getting Started with Swama

Let’s walk through a few example commands that will get you up and running with Swama.

1. Listing All Endpoints

Want to list all the endpoints in your API definition? Use the list command:

swama endpoints list --file swagger.yaml
Enter fullscreen mode Exit fullscreen mode

This will output all the API endpoints defined in the swagger.yaml file.

2. Viewing Endpoint Details

To view the details of a specific API endpoint, including methods, request bodies, and responses, use the view command:

swama endpoints view --file swagger.yaml --endpoint /api/users --method GET
Enter fullscreen mode Exit fullscreen mode

3. Convert Endpoints to Testable Commands

One of Swama’s most powerful features is its ability to convert API endpoints into curl or fetch commands. For example, to convert an endpoint to a curl command:

swama endpoints convert --file swagger.yaml --endpoint /api/users --method POST --type curl
Enter fullscreen mode Exit fullscreen mode

This command converts the POST /api/users endpoint into a curl command, making it super easy to test the API from the terminal.


Autocompletion for Faster Workflows

Swama supports autocompletion for various shells like Bash and Zsh. You can enable autocompletion for faster and more efficient workflows.

To generate the autocompletion script for your shell, run:

swama completion bash > /etc/bash_completion.d/swama
Enter fullscreen mode Exit fullscreen mode

For Zsh:

swama completion zsh > ~/.zsh/completion/_swama
Enter fullscreen mode Exit fullscreen mode

This allows you to quickly navigate through Swama commands and subcommands with autocompletion.


Final Thoughts

Swama brings the convenience of working with Swagger/OpenAPI definitions directly into your terminal. Whether you're listing endpoints, converting them to curl or fetch, or exploring tags and servers, Swama makes interacting with APIs seamless.

I built Swama to solve my own frustrations with manually browsing through Swagger files and converting API endpoints for testing. I hope it makes your development experience smoother as well.

By following these steps, you can simplify your interaction with API specifications, reduce manual work, and boost your productivity.

swagger Article's
30 articles in total
Favicon
Crudify: Automate Your Mongoose CRUD Operations in NestJS
Favicon
🚀 API Maker : Release Notes for v1.9.0
Favicon
What Does Swagger x-nullable Mean?
Favicon
Two Reasons on Why We Ship LiveAPI with An ROI Calculator
Favicon
.NET 9 Revolutionizing documentation of APIs : From Swashbuckle to Scalar 🚀
Favicon
What is the Best Way to Group REST API methods in Swagger UI
Favicon
How Scale Changes Everything - The LiveAPI Perspective
Favicon
What is SwaggerHub?
Favicon
Ever wished to maintain API Docs with ease? Introducing LiveAPI: Super Convenient API Docs
Favicon
Integrate Swagger UI with Codeigniter4
Favicon
How to Use Swagger UI Locally: A Step-by-Step Guide
Favicon
Musings Over What Makes LiveAPI Different (from Swagger Et Cetera)
Favicon
Missing Required Key in Body of PUT /odata/Assets({Key}) Edit an asset on UiPath.WebApi 18.0
Favicon
An Online Free API AutoTesting Tool That Completes 160 Hours of Testing Work for 20 APIs in Just 3 Minutes
Favicon
How to Improve Development Efficiency Through Automated API Testing
Favicon
Top 8 Swagger Codegen Alternatives
Favicon
JavaFX In Action #8 with Ulas Ergin: How JavaFX helps to migrate from Swing to React UIs, all combined in one Java app
Favicon
Exploring AutoAPI: An Automation Tool to Simplify Frontend Development
Favicon
Django Rest framework with Swagger
Favicon
Seamlessly Integrate Swagger with JWT Authentication in NestJS
Favicon
New Swagger-UI embedding Cloud TypeScript Editor with RPC SDK
Favicon
Laravel API Documentation Made Easy: Step-by-Step Swagger Integration
Favicon
Introducing Swama: A CLI Tool for Swagger/OpenAPI Interactions
Favicon
StudySpy: Building the new PublicApi v2
Favicon
Swagger UI + Docker: Initial Setup
Favicon
apigen-ts – Simple TypeScript API Client Generator
Favicon
Automating Swagger Documentation with Joi in Node.js: Simplify Your API Documentation Workflow
Favicon
Merge and bundle open api yaml files for swagger
Favicon
Gerando Documentação de API Automática com Fastify, @fastify/swagger e Zod
Favicon
Hosting Swagger-UI using GitHub Pages

Featured ones: