1f0638719e
This change implements a unit test for ensuring proper processing of requests and responses by generated API code. Additionally, this change requires API handlers to explicitly receive Monkit scopes rather than assuming that `mon` will always exist in the generated API code's namespace. Change-Id: Iea56f139f9dad0050b7d09ea765189280c3466f2
42 lines
767 B
Go
42 lines
767 B
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
//go:generate go run gen.go
|
|
//go:build ignore
|
|
// +build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"storj.io/common/uuid"
|
|
"storj.io/storj/private/apigen"
|
|
)
|
|
|
|
func main() {
|
|
a := &apigen.API{PackageName: "example"}
|
|
|
|
g := a.Group("TestAPI", "testapi")
|
|
|
|
g.Post("/{path}", &apigen.Endpoint{
|
|
MethodName: "GenTestAPI",
|
|
Response: struct {
|
|
ID uuid.UUID
|
|
Date time.Time
|
|
PathParam string
|
|
Body string
|
|
}{},
|
|
Request: struct{ Content string }{},
|
|
QueryParams: []apigen.Param{
|
|
apigen.NewParam("id", uuid.UUID{}),
|
|
apigen.NewParam("date", time.Time{}),
|
|
},
|
|
PathParams: []apigen.Param{
|
|
apigen.NewParam("path", ""),
|
|
},
|
|
})
|
|
|
|
a.MustWriteGo("api.gen.go")
|
|
}
|