LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Swagger UI

In light-rest-4j, there is a specification module. It contains several handlers to render Swagger UI for light-rest-4j services including http-sidecar and light-gateway to assist users to test the API from the browser.

Handlers

SpecSwaggerUIHandler

The main handler is called SpecSwaggerUIHandler and it will return an HTML file to render the Swagger UI. The HTML refers to a url for the OpenAPI specification file on the server as “/spec.yaml”.

SpecDisplayHandler

The /spec.yaml endpoimt is served by SpecDisplayHandler and it uses the specificatiom.yml config file to locate the openapi.yaml specification file in the config folder.

Here is the default specification.yml in the module.

---
# Specification type and file name definition
# The filename with path of the specification file, and usually it is openapi.yaml
fileName: ${specification.fileName:config/openapi.yaml}
# The content type of the specification file. In most cases, we are using yaml format.
contentType: ${specification.contentType:text/yaml}

You can overwrite the file location and filename as well as the content type in values.yml file. For example, some developers use openapi.json for the specification.

The SpecDisplayHandler will ensure that a get request to /spec.yaml will return the openapi.ymal or openapi.json.

FaviconHandler

This handler return the favicon.ico from the default module resources/config folder and this file can be overwrite in the externalized config folder. Most browsers will reuqest this file when loading an HTML file. This handler will prevent 404 error on the server.

Configuration

To enable the Swagger UI renderer, we need to add the following hanlders and paths to the handler.yml

handler.handlers:
  - com.networknt.specification.SpecDisplayHandler@spec
  - com.networknt.specification.SpecSwaggerUIHandler@swaggerui
  - com.networknt.specification.FaviconHandler@favicon

paths:
  - path: '/spec.yaml'
    method: 'get'
    exec:
      - spec
  - path: '/specui.html'
    method: 'get'
    exec:
      - swaggerui
  - path: '/favicon.ico'
    method: 'get'
    exec:
      - favicon


The other config file is the specification.yml and the content is here for the light-gateway and http-sidecar.

---
# Specification type and file name definition
# The filename with path of the specification file, and usually it is openapi.yaml
fileName: ${specification.fileName:openapi.yaml}
# The content type of the specification file. In most cases, we are using yaml format.
contentType: ${specification.contentType:text/yaml}

http-sidecar

The http-sidecar is one of the examples to use the Swagger UI and here is the steps you can follow to access the Swagger-UI.

cd ~/networknt
git clone https://github.com/networknt/http-sidecar.git
cd http-sidecar
mvn clean install
java -jar -Dlight-4j-config-dir=config/local target/http-sidecar.jar

Once the server is up and running. Open a browser and enter the following URL to acces the Swagger UI.

https://localhost:9445/specui.html

light-gateway

The light-gateway is another examaples and here is the steps to follow.

cd ~/networknt
git clone https://github.com/networknt/light-gateway.git
cd light-gateway
mvn clean install
java -jar -Dlight-4j-config-dir=config/local target/light-gateway.jar

Once the server is up and running. Open a browser and enter the following URL to acces the Swagger UI.

https://localhost:9445/specui.html
  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Swagger UI” was last updated: May 12, 2022: fixes #336 add swagger ui document (01f068b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute