History

fix working example/basic/api function (#123)

Anton Dzyk committed 6 years ago

Commit 4199ce81 parent bbeaf5b4 files · +75 −33Browse files

Showing the changes to example/basic/docs (1 of 4 files). Show all

Unified · Split

example/basic/docs/docs.go+62−31
@@ -1,18 +1,23 @@
1// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT1// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2// This file was generated by swaggo/swag at2// This file was generated by swaggo/swag
3// 2017-06-25 01:25:37.872454531 +0800 CST
4 3
5package docs4package docs
6 5
7import (6import (
7 "bytes"
8 "encoding/json"
9 "strings"
10
11 "github.com/alecthomas/template"
8 "github.com/swaggo/swag"12 "github.com/swaggo/swag"
9)13)
10 14
11var doc = `{15var doc = `{
16 "schemes": {{ marshal .Schemes }},
12 "swagger": "2.0",17 "swagger": "2.0",
13 "info": {18 "info": {
14 "description": "This is a sample server Petstore server.",19 "description": "{{.Description}}",
15 "title": "Swagger Example API",20 "title": "{{.Title}}",
16 "termsOfService": "http://swagger.io/terms/",21 "termsOfService": "http://swagger.io/terms/",
17 "contact": {22 "contact": {
18 "name": "API Support",23 "name": "API Support",
@@ -23,10 +28,10 @@ var doc = `{ · 4 unmodified lines
23 "name": "Apache 2.0",28 "name": "Apache 2.0",
24 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"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",33 "host": "{{.Host}}",
29 "basePath": "/v2",34 "basePath": "{{.BasePath}}",
30 "paths": {35 "paths": {
31 "/testapi/get-string-by-int/{some_id}": {36 "/testapi/get-string-by-int/{some_id}": {
32 "get": {37 "get": {
@@ -40,13 +45,11 @@ var doc = `{ · 7 unmodified lines
40 "summary": "Add a new pet to the store",45 "summary": "Add a new pet to the store",
41 "parameters": [46 "parameters": [
42 {47 {
48 "type": "integer",
43 "description": "Some ID",49 "description": "Some ID",
44 "name": "some_id",50 "name": "some_id",
45 "in": "path",51 "in": "path",
46 "required": true,52 "required": true
47 "schema": {
48 "type": "int"
49 }
50 }53 }
51 ],54 ],
52 "responses": {55 "responses": {
@@ -59,14 +62,12 @@ var doc = `{ · 6 unmodified lines
59 "400": {62 "400": {
60 "description": "We need ID!!",63 "description": "We need ID!!",
61 "schema": {64 "schema": {
62 "type": "object",
63 "$ref": "#/definitions/web.APIError"65 "$ref": "#/definitions/web.APIError"
64 }66 }
65 },67 },
66 "404": {68 "404": {
67 "description": "Can not find ID",69 "description": "Can not find ID",
68 "schema": {70 "schema": {
69 "type": "object",
70 "$ref": "#/definitions/web.APIError"71 "$ref": "#/definitions/web.APIError"
71 }72 }
72 }73 }
@@ -84,31 +85,25 @@ var doc = `{ · 11 unmodified lines
84 ],85 ],
85 "parameters": [86 "parameters": [
86 {87 {
88 "type": "string",
87 "description": "Some ID",89 "description": "Some ID",
88 "name": "some_id",90 "name": "some_id",
89 "in": "path",91 "in": "path",
90 "required": true,92 "required": true
91 "schema": {
92 "type": "string"
93 }
94 },93 },
95 {94 {
95 "type": "integer",
96 "description": "Offset",96 "description": "Offset",
97 "name": "offset",97 "name": "offset",
98 "in": "query",98 "in": "query",
99 "required": true,99 "required": true
100 "schema": {
101 "type": "int"
102 }
103 },100 },
104 {101 {
102 "type": "integer",
105 "description": "Offset",103 "description": "Offset",
106 "name": "limit",104 "name": "limit",
107 "in": "query",105 "in": "query",
108 "required": true,106 "required": true
109 "schema": {
110 "type": "int"
111 }
112 }107 }
113 ],108 ],
114 "responses": {109 "responses": {
@@ -121,14 +116,12 @@ var doc = `{ · 6 unmodified lines
121 "400": {116 "400": {
122 "description": "We need ID!!",117 "description": "We need ID!!",
123 "schema": {118 "schema": {
124 "type": "object",
125 "$ref": "#/definitions/web.APIError"119 "$ref": "#/definitions/web.APIError"
126 }120 }
127 },121 },
128 "404": {122 "404": {
129 "description": "Can not find ID",123 "description": "Can not find ID",
130 "schema": {124 "schema": {
131 "type": "object",
132 "$ref": "#/definitions/web.APIError"125 "$ref": "#/definitions/web.APIError"
133 }126 }
134 }127 }
@@ -140,10 +133,10 @@ var doc = `{ · 5 unmodified lines
140 "web.APIError": {133 "web.APIError": {
141 "type": "object",134 "type": "object",
142 "properties": {135 "properties": {
143 "ErrorCode": {136 "errorCode": {
144 "type": "int"137 "type": "integer"
145 },138 },
146 "ErrorMessage": {139 "errorMessage": {
147 "type": "string"140 "type": "string"
148 }141 }
149 }142 }
@@ -151,11 +144,49 @@ var doc = `{ · 1 unmodified line
151 }144 }
152}`145}`
153 146
147type 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
157var 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
154type s struct{}166type s struct{}
155 167
156func (s *s) ReadDoc() string {168func (s *s) ReadDoc() string {
157 return doc169 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
159func init() {190func init() {
160 swag.Register(swag.Name, &s{})191 swag.Register(swag.Name, &s{})
161}192}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t