-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
152 lines (137 loc) · 3.66 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"embed"
"github.com/go-andiamo/chioas"
"github.com/go-chi/chi/v5"
"net/http"
)
func (a *api) SetupRoutes(r chi.Router) error {
return a.Definition.SetupRoutes(r, a)
}
//go:embed *.png
var supportFilesFS embed.FS
var apiDef = chioas.Definition{
DocOptions: chioas.DocOptions{
ServeDocs: true, // makes docs served as interactive UI on /docs/index.htm
UIStyle: chioas.Rapidoc,
SupportFiles: http.FileServer(http.FS(supportFilesFS)),
SupportFilesStripPrefix: true,
RapidocOptions: &chioas.RapidocOptions{
ShowHeader: true,
HeadingText: "Petstore",
//AllowSpecUrlLoad: true,
Theme: "dark",
ShowMethodInNavBar: "as-colored-block",
UsePathInNavBar: true,
UpdateRoute: true,
//LogoSrc: "dog.png",
InnerHtml: `<img id="logo" slot="logo" src="dog.png" width="30" height="30">
<div slot="nav-logo" style="display: flex; align-items: center; justify-content: center;">
<img src="dog.png" style="width:40px; margin-right: 20px"> <span><b>PetStore API</b></span>
</div>`,
AdditionalAttributes: map[string]string{
"nav-active-item-marker": "left-bar",
"text-color": "#133863",
"bg-color": "#ffffff",
},
},
},
Info: chioas.Info{
Title: "Swagger Petstore - OpenAPI 3.0",
Description: `This is a sample Pet Store Server based on the OpenAPI 3.0 specification.
You can find out more about Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store
repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet
Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)`,
Version: "1.0.17",
},
Tags: chioas.Tags{
{
Name: "pet",
Description: "Everything about your Pets",
ExternalDocs: &chioas.ExternalDocs{
Description: "Find out more",
Url: "http://swagger.io",
},
},
{
Name: "store",
Description: "Access to Petstore orders",
ExternalDocs: &chioas.ExternalDocs{
Description: "Find out more about our store",
Url: "http://swagger.io",
},
},
{
Name: "user",
Description: "Operations about user",
},
},
Paths: chioas.Paths{
"/pets": petsPaths,
},
Components: &components,
}
var components = chioas.Components{
Schemas: chioas.Schemas{
{
Name: "Pet",
Type: "object",
RequiredProperties: []string{"name", "photoUrls"},
Properties: []chioas.Property{
{
Name: "id",
Type: "integer",
Example: 10,
},
{
Name: "name",
Type: "string",
Example: "doggie",
},
{
Name: "category",
SchemaRef: "Category",
},
{
Name: "photoUrls",
Type: "array",
ItemType: "string",
Example: "https://example.com/dog-picture.jpg",
},
},
},
{
Name: "Category",
Type: "object",
Properties: []chioas.Property{
{
Name: "id",
Type: "integer",
Example: 1,
},
{
Name: "name",
Type: "string",
Example: "Dogs",
},
},
},
{
Name: "Status",
Type: "string",
Default: "available",
Enum: []any{"available", "pending", "sold"},
},
},
}
type api struct {
chioas.Definition
}
var petStoreApi = &api{
Definition: apiDef,
}