-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
109 lines (94 loc) · 3.22 KB
/
main.go
File metadata and controls
109 lines (94 loc) · 3.22 KB
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
package main
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"github.com/richjyoung/echopen"
v310 "github.com/richjyoung/echopen/openapi/v3.1.0"
)
func main() {
api := echopen.New(
"Responses",
"1.0.0",
echopen.WithSpecDescription("Example to show reused responses, loosely based on the Petstore examples."),
echopen.WithSpecTag(&v310.Tag{Name: "pets", Description: "Pets endpoints"}),
)
api.Spec.GetComponents().AddJSONResponse("UnexpectedErrorResponse", "unexpected error", api.ToSchemaRef(Error{}))
api.Spec.GetComponents().AddJSONResponse("NotFoundResponse", "not found", api.ToSchemaRef(Error{}))
api.Spec.GetComponents().AddJSONResponse("PetResponse", "pet response", api.ToSchemaRef(Pet{}))
api.GET(
"/pets",
findPets,
echopen.WithOperationID("findPets"),
echopen.WithDescription("Finds all pets the user has access to"),
echopen.WithTags("pets"),
echopen.WithQueryStruct(FindPetsQuery{}),
echopen.WithResponseStruct(fmt.Sprint(http.StatusOK), "pet response", []Pet{}),
echopen.WithResponseRef("default", "UnexpectedErrorResponse"),
)
api.POST(
"/pets",
addPet,
echopen.WithOperationID("addPet"),
echopen.WithDescription("Creates a new pet in the store. Duplicates are allowed"),
echopen.WithTags("pets"),
echopen.WithRequestBodyStruct(echo.MIMEApplicationJSON, "Pet to add to the store", NewPet{}),
echopen.WithResponseRef(fmt.Sprint(http.StatusOK), "PetResponse"),
echopen.WithResponseRef("default", "UnexpectedErrorResponse"),
)
api.GET(
"/pets/:id",
findPetByID,
echopen.WithOperationID("findPetByID"),
echopen.WithDescription("Returns a user based on a single ID, if the user does not have access to the pet"),
echopen.WithTags("pets"),
// echopen.WithPathParameter(&echopen.PathParameterConfig{
// Name: "id",
// Description: "ID of pet to fetch",
// Schema: &v310.Schema{
// Type: v310.IntegerSchemaType,
// Format: "int64",
// },
// }),
echopen.WithResponseRef(fmt.Sprint(http.StatusOK), "PetResponse"),
echopen.WithResponseRef(fmt.Sprint(http.StatusNotFound), "NotFoundResponse"),
echopen.WithResponseRef("default", "UnexpectedErrorResponse"),
)
api.DELETE(
"/pets/:id",
deletePet,
echopen.WithOperationID("deletePet"),
echopen.WithDescription("deletes a single pet based on the ID supplied"),
echopen.WithTags("pets"),
// echopen.WithPathParameter(&echopen.PathParameterConfig{
// Name: "id",
// Description: "ID of pet to delete",
// Schema: &v310.Schema{
// Type: v310.IntegerSchemaType,
// Format: "int64",
// },
// }),
echopen.WithResponseDescription(fmt.Sprint(http.StatusNoContent), "pet deleted"),
echopen.WithResponseRef(fmt.Sprint(http.StatusNotFound), "NotFoundResponse"),
echopen.WithResponseRef("default", "UnexpectedErrorResponse"),
)
// Serve the generated schema
api.ServeYAMLSpec("/openapi.yml")
api.ServeSwaggerUI("/", "/openapi.yml", "5.10.3")
// Write the full generated spec
api.WriteYAMLSpec("openapi_out.yml")
// Start the server
api.Start("localhost:3000")
}
func findPets(c echo.Context) error {
return nil
}
func addPet(c echo.Context) error {
return nil
}
func findPetByID(c echo.Context) error {
return nil
}
func deletePet(c echo.Context) error {
return nil
}