Showing the changes to example/basic/docs (1 of 4 files). Show all
Unified · Split
| @@ -1,18 +1,23 @@ | ||
| 1 | 1 | // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT |
| 2 | −// This file was generated by swaggo/swag at | |
| 3 | −// 2017-06-25 01:25:37.872454531 +0800 CST | |
| 2 | +// This file was generated by swaggo/swag | |
| 4 | 3 | |
| 5 | 4 | package docs |
| 6 | 5 | |
| 7 | 6 | import ( |
| 7 | + "bytes" | |
| 8 | + "encoding/json" | |
| 9 | + "strings" | |
| 10 | + | |
| 11 | + "github.com/alecthomas/template" | |
| 8 | 12 | "github.com/swaggo/swag" |
| 9 | 13 | ) |
| 10 | 14 | |
| 11 | 15 | var doc = `{ |
| 16 | + "schemes": {{ marshal .Schemes }}, | |
| 12 | 17 | "swagger": "2.0", |
| 13 | 18 | "info": { |
| 14 | − "description": "This is a sample server Petstore server.", | |
| 15 | − "title": "Swagger Example API", | |
| 19 | + "description": "{{.Description}}", | |
| 20 | + "title": "{{.Title}}", | |
| 16 | 21 | "termsOfService": "http://swagger.io/terms/", |
| 17 | 22 | "contact": { |
| 18 | 23 | "name": "API Support", |
| @@ -23,10 +28,10 @@ var doc = `{ · 4 unmodified lines | ||
| 23 | 28 | "name": "Apache 2.0", |
| 24 | 29 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" |
| 25 | 30 | }, |
| 26 | − "version": "1.0" | |
| 31 | + "version": "{{.Version}}" | |
| 27 | 32 | }, |
| 28 | − "host": "petstore.swagger.io", | |
| 29 | − "basePath": "/v2", | |
| 33 | + "host": "{{.Host}}", | |
| 34 | + "basePath": "{{.BasePath}}", | |
| 30 | 35 | "paths": { |
| 31 | 36 | "/testapi/get-string-by-int/{some_id}": { |
| 32 | 37 | "get": { |
| @@ -40,13 +45,11 @@ var doc = `{ · 7 unmodified lines | ||
| 40 | 45 | "summary": "Add a new pet to the store", |
| 41 | 46 | "parameters": [ |
| 42 | 47 | { |
| 48 | + "type": "integer", | |
| 43 | 49 | "description": "Some ID", |
| 44 | 50 | "name": "some_id", |
| 45 | 51 | "in": "path", |
| 46 | − "required": true, | |
| 47 | − "schema": { | |
| 48 | − "type": "int" | |
| 49 | − } | |
| 52 | + "required": true | |
| 50 | 53 | } |
| 51 | 54 | ], |
| 52 | 55 | "responses": { |
| @@ -59,14 +62,12 @@ var doc = `{ · 6 unmodified lines | ||
| 59 | 62 | "400": { |
| 60 | 63 | "description": "We need ID!!", |
| 61 | 64 | "schema": { |
| 62 | − "type": "object", | |
| 63 | 65 | "$ref": "#/definitions/web.APIError" |
| 64 | 66 | } |
| 65 | 67 | }, |
| 66 | 68 | "404": { |
| 67 | 69 | "description": "Can not find ID", |
| 68 | 70 | "schema": { |
| 69 | − "type": "object", | |
| 70 | 71 | "$ref": "#/definitions/web.APIError" |
| 71 | 72 | } |
| 72 | 73 | } |
| @@ -84,31 +85,25 @@ var doc = `{ · 11 unmodified lines | ||
| 84 | 85 | ], |
| 85 | 86 | "parameters": [ |
| 86 | 87 | { |
| 88 | + "type": "string", | |
| 87 | 89 | "description": "Some ID", |
| 88 | 90 | "name": "some_id", |
| 89 | 91 | "in": "path", |
| 90 | − "required": true, | |
| 91 | − "schema": { | |
| 92 | − "type": "string" | |
| 93 | − } | |
| 92 | + "required": true | |
| 94 | 93 | }, |
| 95 | 94 | { |
| 95 | + "type": "integer", | |
| 96 | 96 | "description": "Offset", |
| 97 | 97 | "name": "offset", |
| 98 | 98 | "in": "query", |
| 99 | − "required": true, | |
| 100 | − "schema": { | |
| 101 | − "type": "int" | |
| 102 | − } | |
| 99 | + "required": true | |
| 103 | 100 | }, |
| 104 | 101 | { |
| 102 | + "type": "integer", | |
| 105 | 103 | "description": "Offset", |
| 106 | 104 | "name": "limit", |
| 107 | 105 | "in": "query", |
| 108 | − "required": true, | |
| 109 | − "schema": { | |
| 110 | − "type": "int" | |
| 111 | − } | |
| 106 | + "required": true | |
| 112 | 107 | } |
| 113 | 108 | ], |
| 114 | 109 | "responses": { |
| @@ -121,14 +116,12 @@ var doc = `{ · 6 unmodified lines | ||
| 121 | 116 | "400": { |
| 122 | 117 | "description": "We need ID!!", |
| 123 | 118 | "schema": { |
| 124 | − "type": "object", | |
| 125 | 119 | "$ref": "#/definitions/web.APIError" |
| 126 | 120 | } |
| 127 | 121 | }, |
| 128 | 122 | "404": { |
| 129 | 123 | "description": "Can not find ID", |
| 130 | 124 | "schema": { |
| 131 | − "type": "object", | |
| 132 | 125 | "$ref": "#/definitions/web.APIError" |
| 133 | 126 | } |
| 134 | 127 | } |
| @@ -140,10 +133,10 @@ var doc = `{ · 5 unmodified lines | ||
| 140 | 133 | "web.APIError": { |
| 141 | 134 | "type": "object", |
| 142 | 135 | "properties": { |
| 143 | − "ErrorCode": { | |
| 144 | − "type": "int" | |
| 136 | + "errorCode": { | |
| 137 | + "type": "integer" | |
| 145 | 138 | }, |
| 146 | − "ErrorMessage": { | |
| 139 | + "errorMessage": { | |
| 147 | 140 | "type": "string" |
| 148 | 141 | } |
| 149 | 142 | } |
| @@ -151,11 +144,49 @@ var doc = `{ · 1 unmodified line | ||
| 151 | 144 | } |
| 152 | 145 | }` |
| 153 | 146 | |
| 147 | +type swaggerInfo struct { | |
| 148 | + Version string | |
| 149 | + Host string | |
| 150 | + BasePath string | |
| 151 | + Schemes []string | |
| 152 | + Title string | |
| 153 | + Description string | |
| 154 | +} | |
| 155 | + | |
| 156 | +// SwaggerInfo holds exported Swagger Info so clients can modify it | |
| 157 | +var SwaggerInfo = swaggerInfo{ | |
| 158 | + Version: "1.0", | |
| 159 | + Host: "petstore.swagger.io:8080", | |
| 160 | + BasePath: "/v2", | |
| 161 | + Schemes: []string{}, | |
| 162 | + Title: "Swagger Example API", | |
| 163 | + Description: "This is a sample server Petstore server.", | |
| 164 | +} | |
| 165 | + | |
| 154 | 166 | type s struct{} |
| 155 | 167 | |
| 156 | 168 | func (s *s) ReadDoc() string { |
| 157 | − return doc | |
| 169 | + sInfo := SwaggerInfo | |
| 170 | + sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) | |
| 171 | + | |
| 172 | + t, err := template.New("swagger_info").Funcs(template.FuncMap{ | |
| 173 | + "marshal": func(v interface{}) string { | |
| 174 | + a, _ := json.Marshal(v) | |
| 175 | + return string(a) | |
| 176 | + }, | |
| 177 | + }).Parse(doc) | |
| 178 | + if err != nil { | |
| 179 | + return doc | |
| 180 | + } | |
| 181 | + | |
| 182 | + var tpl bytes.Buffer | |
| 183 | + if err := t.Execute(&tpl, sInfo); err != nil { | |
| 184 | + return doc | |
| 185 | + } | |
| 186 | + | |
| 187 | + return tpl.String() | |
| 158 | 188 | } |
| 189 | + | |
| 159 | 190 | func init() { |
| 160 | 191 | swag.Register(swag.Name, &s{}) |
| 161 | 192 | } |