Home Blog Documentation with Swagger UI
Back to Blog
Dev Tools

Documentation with Swagger UI

acretph_nikolai
Nikolai Angelo Ceballos
Software Developer
September 4, 2026
Blog Image

Swagger UI is a simple way to make your APIs easier to use. By keeping your spec accurate and setting up the UI correctly, you can provide a useful tool for your team and anyone else building on your platform. It takes a bit of work to get the details right, but it saves everyone a lot of time in the long run by making your API documentation clear and interactive.

Introduction

Good API documentation is more than just a list of endpoints; it’s a tool that helps developers actually get things done. When you’re trying to integrate with a new service, you don’t want to just read about a request, you want to try it out. Swagger UI takes your OpenAPI file and turns it into a web page where anyone can test live requests right from their browser. This guide covers how to set it up, how to make it useful for your team, and some of the more advanced things you can do with it.

Why API Documentation Matters

Clear docs mean people spend less time asking questions and more time building. If your API is easy to understand, external partners can get started on their own without needing a guided tour of your code. For internal teams, it helps keep everyone on the same page and ensures that the front-end and back-end actually match up.

Key benefits include:

  • It’s much faster to build apps when the API is easy to follow.
  • You’ll spend less time fixing bugs caused by simple misunderstandings.
  • Different teams can work together more smoothly.
  • It’s easier to stay organized and follow your security rules.

Overview of Swagger UI

Swagger UI is an open-source tool that reads your OpenAPI definition and builds a responsive web page. It shows every path, parameter, and response type, but the best part is the "Try it out" button. This lets you send actual HTTP requests to the server and see the response instantly. Since the UI is built directly from your spec file, the documentation updates itself whenever you change the API contract.

Core features of Swagger UI:

  • It automatically displays your paths, schemas, and security settings.
  • You get a built-in request tool for query, header, and body data.
  • It uses syntax highlighting to make JSON and YAML easy to read.
  • You can change the look, layout, and how users log in.

Setting Up Swagger UI

Prerequisites

  • A valid OpenAPI 3.0 (or 2.0) specification file in JSON or YAML format.
  • Access to the API server for testing live requests.
  • Node.js and npm installed if you plan to run Swagger UI as a standalone server, or a web server capable of serving static files.

Installation Steps

1. Pick a folder – Create a directory for the project and run `npm init -y` if you’re using npm.

2. Install Swagger UI – Use `npm install swagger-ui-dist` to get the files you need.

3. Copy the files – Take everything inside `node_modules/swagger-ui-dist` and move it to a folder named `public`.

4. Add your spec – Put your `openapi.yaml` or `openapi.json` file right in that same `public` folder.

5. Make an HTML page – Create an `index.html` file to load the UI and point it to your spec. You can use this template:

```html

<!DOCTYPE html>

<html>

<head>

<title>API Documentation</title>

<link rel="stylesheet" href="swagger-ui.css">

</head>

<body>

<div id="swagger-ui"></div>

<script src="swagger-ui-bundle.js"></script>

<script src="swagger-ui-standalone-preset.js"></script>

<script>

const ui = SwaggerUIBundle({

url: "openapi.yaml",

dom_id: "#swagger-ui",

presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],

layout: "BaseLayout"

});

</script>

</body>

</html>

```

6. Run a server – Use something like `npx http-server public` to start hosting the files locally.

7. Check the browser – Go to `http://localhost:8080` to see your API endpoints in action.

Configuration

Swagger UI offers a rich set of configuration options that can be passed to `SwaggerUIBundle`. Commonly used settings include:

  • `deepLinking: true` – Enables URL fragments for each operation, allowing direct linking.
  • `docExpansion: "none"` – Collapses all sections by default for a cleaner view.
  • `defaultModelsExpandDepth: -1` – Hides schema definitions unless explicitly requested.
  • `oauth2RedirectUrl` – Specifies the redirect URL for OAuth2 authentication flows.

You can mix and match these settings to build a page that works best for whoever is using your API.

Best Practices for Effective Documentation

  • Keep your spec files with your code – Store your OpenAPI file in Git so it’s always next to the actual implementation.
  • Give operations clear names – Using logical operation IDs makes generated code much easier for others to use.
  • Don't forget error codes – Show people what to expect when something goes wrong by documenting common error responses.
  • Reuse your definitions – If you have a schema or parameter used in multiple places, define it once and reference it everywhere.
  • Include realistic examples – Filling your spec with real-world data helps users understand what they’re supposed to send.
  • Set up security – Use the UI's built-in support for API keys or OAuth2 to make testing secure.

Common Pitfalls and How to Avoid Them

  • Specs falling behind – Avoid manual updates. Try to generate your OpenAPI file automatically from your code so they stay in sync.
  • Showing too much – Double-check your spec before you publish it to make sure internal-only endpoints aren’t visible.
  • UI lag – If your API is huge, enable the search filter or break the spec into smaller files to keep the page fast.
  • Connection issues – If "Try it out" fails, you probably need to configure your API server to allow requests from the domain where Swagger is hosted.

Advanced Features

You can do a lot more than just list endpoints. Here are some of the handier tools:

  • Plugins – You can write small scripts to add custom components or change how requests are handled.
  • Styling – Use custom CSS to change colors and logos so the page matches your brand.
  • Grouping multiple APIs – If you have different versions of an API, you can load them all onto one page using a simple dropdown.
  • Picking a server – You can let users choose whether they want to send requests to dev, staging, or production.
  • API Gateways – You can plug Swagger UI into larger portals to create a single place for developers to find everything.

Conclusion

Swagger UI is a simple way to make your APIs easier to use. By keeping your spec accurate and setting up the UI correctly, you can provide a useful tool for your team and anyone else building on your platform. It takes a bit of work to get the details right, but it saves everyone a lot of time in the long run by making your API documentation clear and interactive.

Tags:
Dev Tools
acretph_nikolai
Nikolai Angelo Ceballos
Software Developer
I’m a developer who loves learning and adapting to the fast-changing tech world. I started my journey without AI, but once I embraced it, my growth in the industry sped up in ways I didn’t expect. For me, it’s all about staying curious, picking up new tools, and building things that make a difference.

Table of Contents

AcretPhilippines Inc.
Bringing Japanese software development excellence to the Philippine market since 2019.

Acret Philippines Inc.

14th Floor Latitude Corporate Center

Cebu Business Park

Lahug, Cebu City

TEL: 032-344-3847

09:00 AM - 06:00 PM (PHT)

Head Office Acret Inc.

〒650-0011

601 Kenso Building, 2-13-3 Shimoyamate-dori

Chuo-ku Kobe-shi, Hyogo, Japan

TEL:+81 78-599-8511

10:00-17:00 JPT

© 2025 Acret Philippines Inc. All rights reserved.