dockeropenapiswagger-ui

Swagger UI Generating Malformed Request URL with Docker and Swaggo v2


I'm using Swaggo v2 to generate OpenAPI 3 documentation for my Go project. My annotations include:

// @title           project
// @version         1.0
// @host            localhost:4000
// @BasePath        /v1
// @securitydefinitions.bearerauth BearerAuth

This generates a swagger.yml with:

...
openapi: 3.1.0
servers:
 - url: localhost:4000/v1

I run Swagger UI via Docker Compose:

services:
  swagger-ui:
    image: swaggerapi/swagger-ui:v5.19.0
    ports:
      - "8080:8080"
    environment:
      - URL=http://localhost:4000/docs/swagger.json  # Accessible from host

When executing requests via Swagger UI, the URL becomes malformed (e.g., localhost://localhost:40004000/v1/healthcheck). Removing @host "works" but uses the default host/port, which isn't ideal.

How can I ensure Swagger UI constructs valid URLs (e.g., http://localhost:4000/v1/healthcheck) while keeping @host annotations?

this how the current configuration looks like enter image description here

and this is the workaround enter image description here


Solution

  • using @server.url like this // @servers.url http://localhost:4000/v1 instead of @host and @BasePath solves the issue.