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 badges1 Answer
Reset to default 0using @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条)