go-clean-template
223 строки · 6.2 Кб
1// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2// This file was generated by swaggo/swag
3package docs
4
5import (
6"bytes"
7"encoding/json"
8"strings"
9"text/template"
10
11"github.com/swaggo/swag"
12)
13
14var doc = `{
15"schemes": {{ marshal .Schemes }},
16"swagger": "2.0",
17"info": {
18"description": "{{escape .Description}}",
19"title": "{{.Title}}",
20"contact": {},
21"version": "{{.Version}}"
22},
23"host": "{{.Host}}",
24"basePath": "{{.BasePath}}",
25"paths": {
26"/translation/do-translate": {
27"post": {
28"description": "Translate a text",
29"consumes": [
30"application/json"
31],
32"produces": [
33"application/json"
34],
35"tags": [
36"translation"
37],
38"summary": "Translate",
39"operationId": "do-translate",
40"parameters": [
41{
42"description": "Set up translation",
43"name": "request",
44"in": "body",
45"required": true,
46"schema": {
47"$ref": "#/definitions/v1.doTranslateRequest"
48}
49}
50],
51"responses": {
52"200": {
53"description": "OK",
54"schema": {
55"$ref": "#/definitions/entity.Translation"
56}
57},
58"400": {
59"description": "Bad Request",
60"schema": {
61"$ref": "#/definitions/v1.response"
62}
63},
64"500": {
65"description": "Internal Server Error",
66"schema": {
67"$ref": "#/definitions/v1.response"
68}
69}
70}
71}
72},
73"/translation/history": {
74"get": {
75"description": "Show all translation history",
76"consumes": [
77"application/json"
78],
79"produces": [
80"application/json"
81],
82"tags": [
83"translation"
84],
85"summary": "Show history",
86"operationId": "history",
87"responses": {
88"200": {
89"description": "OK",
90"schema": {
91"$ref": "#/definitions/v1.historyResponse"
92}
93},
94"500": {
95"description": "Internal Server Error",
96"schema": {
97"$ref": "#/definitions/v1.response"
98}
99}
100}
101}
102}
103},
104"definitions": {
105"entity.Translation": {
106"type": "object",
107"properties": {
108"destination": {
109"type": "string",
110"example": "en"
111},
112"original": {
113"type": "string",
114"example": "текст для перевода"
115},
116"source": {
117"type": "string",
118"example": "auto"
119},
120"translation": {
121"type": "string",
122"example": "text for translation"
123}
124}
125},
126"v1.doTranslateRequest": {
127"type": "object",
128"required": [
129"destination",
130"original",
131"source"
132],
133"properties": {
134"destination": {
135"type": "string",
136"example": "en"
137},
138"original": {
139"type": "string",
140"example": "текст для перевода"
141},
142"source": {
143"type": "string",
144"example": "auto"
145}
146}
147},
148"v1.historyResponse": {
149"type": "object",
150"properties": {
151"history": {
152"type": "array",
153"items": {
154"$ref": "#/definitions/entity.Translation"
155}
156}
157}
158},
159"v1.response": {
160"type": "object",
161"properties": {
162"error": {
163"type": "string",
164"example": "message"
165}
166}
167}
168}
169}`
170
171type swaggerInfo struct {
172Version string
173Host string
174BasePath string
175Schemes []string
176Title string
177Description string
178}
179
180// SwaggerInfo holds exported Swagger Info so clients can modify it
181var SwaggerInfo = swaggerInfo{
182Version: "1.0",
183Host: "localhost:8080",
184BasePath: "/v1",
185Schemes: []string{},
186Title: "Go Clean Template API",
187Description: "Using a translation service as an example",
188}
189
190type s struct{}
191
192func (s *s) ReadDoc() string {
193sInfo := SwaggerInfo
194sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
195
196t, err := template.New("swagger_info").Funcs(template.FuncMap{
197"marshal": func(v interface{}) string {
198a, _ := json.Marshal(v)
199return string(a)
200},
201"escape": func(v interface{}) string {
202// escape tabs
203str := strings.Replace(v.(string), "\t", "\\t", -1)
204// replace " with \", and if that results in \\", replace that with \\\"
205str = strings.Replace(str, "\"", "\\\"", -1)
206return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
207},
208}).Parse(doc)
209if err != nil {
210return doc
211}
212
213var tpl bytes.Buffer
214if err := t.Execute(&tpl, sInfo); err != nil {
215return doc
216}
217
218return tpl.String()
219}
220
221func init() {
222swag.Register(swag.Name, &s{})
223}
224