openapi - Swagger UI Generating Malformed Request URL with Docker and Swaggo v2 - Stack Overflow

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

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

and this is the workaround

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

and this is the workaround

Share Improve this question edited Mar 25 at 13:48 Helen 98.3k17 gold badges276 silver badges346 bronze badges asked Mar 25 at 12:25 KingindanordKingindanord 2,0884 gold badges24 silver badges59 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744196523a4562683.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信