From cb60195b27406c6404269aba9af43202d32931df Mon Sep 17 00:00:00 2001 From: elvinchan Date: Sat, 11 May 2019 22:27:52 +0800 Subject: [PATCH] #19 Retrieve bathPath automatically --- README.md | 4 +- README_zh-CN.md | 2 - assets.go | 7 +++- examples/main.go | 2 +- examples/main_test.go | 2 +- internal.go | 10 ++--- security_test.go | 4 +- spec.go | 33 ++++++++++------ spec_test.go | 89 ++++++++++++++++++++++++++++++----------- utils.go | 21 +++++++++- wrapper.go | 9 ++--- wrapper_test.go | 92 ++++++++++++------------------------------- 12 files changed, 150 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index cef4749..96ea53b 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,8 @@ func createUser(c echo.Context) error { ## Usage #### Create a `ApiRoot` with `New()`, which is a wrapper of `echo.New()` ``` -r := echoswagger.New(echo.New(), "/v1", "doc/", nil) +r := echoswagger.New(echo.New(), "doc/", nil) ``` -> Note: The parameter `basePath` is generally used when the access root path is not the root directory of the website after application is deployed. For example, the URL of an API in the program running locally is: `http://localhost:1323/users`, the actual URL after deployed to server is: `https://www.xxx.com/legacy-api/users`, then, when running locally, `basePath` should be `/`, when running on server, `basePath` should be `/legacy-api`. - You can use the result `ApiRoot` instance to: - Setup Security definitions, request/response Content-Types, UI options, Scheme, etc. ``` diff --git a/README_zh-CN.md b/README_zh-CN.md index 4d49317..0726be4 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -58,8 +58,6 @@ func createUser(c echo.Context) error { ``` r := echoswagger.New(echo.New(), "/v1", "doc/", nil) ``` -> 注意:参数`basePath`一般用于程序部署后访问路径并非网站根目录时的情况,比如程序运行在本地的某个API的URL为:`http://localhost:1323/users`,部署至服务器后的实际URL为:`https://www.xxx.com/legacy-api/users`,则本地运行时,`basePath`应该传入`/`, 部署至服务器时,`basePath`应该传入`/legacy-api`。 - 你可以用这个`ApiRoot`来: - 设置Security定义, 请求/响应Content-Type,UI选项,Scheme等。 ``` diff --git a/assets.go b/assets.go index a9938dd..25d008f 100644 --- a/assets.go +++ b/assets.go @@ -47,10 +47,13 @@ const SwaggerUIContent = `{{define "swagger"}}