OpenAPI

Embeds the Swagger UI, using your OpenAPI specification

Technology

The openapi module provides Swagger UI integration for Project Forge applications. It embeds the complete Swagger UI interface to visualize, explore, and test OpenAPI specifications.

Overview

This module provides:

Key Features

Interactive Documentation

Seamless Integration

Security & Customization

Usage

Basic Implementation

By default, no controller exposes the Swagger UI. Create a controller following this example, then add a route with your preferred security:

1
2
3
4
5
6
7
func OpenAPI(w http.ResponseWriter, r *http.Request) {
controller.Act("openapi", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
u := "http://localhost:{{{ .Port }}}/assets/openapi.json"
ps.SetTitleAndData("OpenAPI", u)
return controller.Render(r, as, &vopenapi.OpenAPI{URL: u}, ps, "breadcrumbs")
})
}

Configuration Options

You can customize the OpenAPI specification source:

1
2
3
4
5
6
7
8
// Local specification file
u := "/assets/openapi.json"

// Remote specification
u := "https://api.example.com/openapi.json"

// Dynamic specification
u := fmt.Sprintf("http://%s/api/openapi.json", r.Host)

Configuration

This module requires:

  1. An OpenAPI 3.x specification file accessible at the configured URL
  2. A controller implementation (not provided by default)
  3. Route configuration for accessing the Swagger UI

Source Code

See Also