-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathjson_param.go
More file actions
49 lines (39 loc) · 1.28 KB
/
json_param.go
File metadata and controls
49 lines (39 loc) · 1.28 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
package main
import (
"context"
"github.com/google/uuid"
"github.com/swaggest/usecase"
)
func jsonParam() usecase.Interactor {
type JSONPayload struct {
ID int `json:"id"`
Name string `json:"name"`
}
type inputWithJSON struct {
Header string `header:"X-Header" description:"Simple scalar value in header."`
Query int `query:"in_query" description:"Simple scalar value in query."`
Path string `path:"in-path" description:"Simple scalar value in path"`
Cookie uuid.UUID `cookie:"in_cookie" description:"UUID in cookie."`
Identity JSONPayload `query:"identity" description:"JSON value in query"`
}
type outputWithJSON struct {
Header string `json:"inHeader"`
Query int `json:"inQuery"`
Path string `json:"inPath"`
JSONPayload
}
u := usecase.NewIOI(new(inputWithJSON), new(outputWithJSON), func(ctx context.Context, input, output any) (err error) {
var (
in = input.(*inputWithJSON)
out = output.(*outputWithJSON)
)
out.Query = in.Query
out.Header = in.Header
out.Path = in.Path
out.JSONPayload = in.Identity
return nil
})
u.SetTitle("Request With JSON Query Parameter")
u.SetDescription("Request with JSON body and query/header/path params, response with JSON body and data from request.")
return u
}