diff --git a/examples/simpleweb/main.go b/examples/simpleweb/main.go index ff38d19..3914bbe 100644 --- a/examples/simpleweb/main.go +++ b/examples/simpleweb/main.go @@ -105,7 +105,12 @@ func registerEndpointRouterConfig(rb router.IRouterBuilder) { endpoints.UseLiveness(rb) endpoints.UseJwt(rb) endpoints.UseRouteInfo(rb) - endpoints.UseSwaggerDoc(rb, swagger.Info{Title: "simple web swagger", Version: "10.0.0", Description: "尝试对接swagger文档"}) + endpoints.UseSwaggerDoc(rb, + swagger.Info{ + Title: "YoyoGO 框架文档演示", + Version: "1.0.0 beta", + Description: "框架文档演示swagger文档 1.0", + }) rb.GET("/error", func(ctx *context.HttpContext) { panic("http get error") diff --git a/pkg/swagger/swagger_path.go b/pkg/swagger/swagger_path.go index 7a8d24b..fc522d1 100644 --- a/pkg/swagger/swagger_path.go +++ b/pkg/swagger/swagger_path.go @@ -5,7 +5,7 @@ type Path struct { Summary string `json:"summary"` Description string `json:"description"` OperationId string `json:"operationId"` - Parameters []Parameters `json:"parameters"` + Parameters interface{} `json:"parameters,omitempty"` RequestBody RequestBody `json:"requestBody,omitempty"` Responses map[string]ResponsesItem `json:"responses"` Security []Security `json:"security"` diff --git a/web/endpoints/swagger.go b/web/endpoints/swagger.go index 5784e43..bc12623 100644 --- a/web/endpoints/swagger.go +++ b/web/endpoints/swagger.go @@ -18,12 +18,12 @@ func UseSwaggerDoc(router router.IRouterBuilder, info swagger.Info) { xlog.GetXLogger("Endpoint").Debug("loaded swagger ui endpoint.") // swagger.json - router.GET("/swagger.json", func(ctx *context.HttpContext) { + router.GET("/resources/swagger.json", func(ctx *context.HttpContext) { var env *abstractions.HostEnvironment _ = ctx.RequiredServices.GetService(&env) openapi := &swagger.OpenApi{ - Openapi: "3.1.0", + Openapi: "3.0.0", Paths: make(map[string]map[string]swagger.Path)} openapi.Info = info GetSwaggerRouteInfomation(openapi, router, env) @@ -31,7 +31,12 @@ func UseSwaggerDoc(router router.IRouterBuilder, info swagger.Info) { }) // swagger ui - router.GET("/swagger", func(ctx *context.HttpContext) { + router.GET("/resources/swagger", func(ctx *context.HttpContext) { + var env *abstractions.HostEnvironment + _ = ctx.RequiredServices.GetService(&env) + serverPath := env.MetaData["server.path"] + // swagger json address + swaggerJsonUri := fmt.Sprintf("/%s/resources/swagger.json", serverPath) swaggerUIHTML := `
@@ -42,16 +47,16 @@ func UseSwaggerDoc(router router.IRouterBuilder, info swagger.Info) { content="SwaggerUI" />