generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema_test.go
79 lines (68 loc) · 1.8 KB
/
schema_test.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
package jsonrpc_test
import (
"context"
"testing"
"github.com/swaggest/assertjson"
"github.com/swaggest/jsonrpc"
"github.com/swaggest/usecase"
)
func TestOpenAPI_Collect(t *testing.T) {
apiSchema := jsonrpc.OpenAPI{}
apiSchema.Reflector().SpecEns().Info.Title = "JSON-RPC Example"
apiSchema.Reflector().SpecEns().Info.Version = "v1.2.3"
apiSchema.Reflector().SpecEns().Info.WithDescription("This app showcases a trivial JSON-RPC API.")
h := &jsonrpc.Handler{}
h.OpenAPI = &apiSchema
h.Validator = &jsonrpc.JSONSchemaValidator{}
h.SkipResultValidation = true
type inp struct {
Name string `json:"name"`
}
type out struct {
Len int `json:"len"`
}
u := usecase.NewIOI(new(inp), new(out), func(ctx context.Context, input, output interface{}) error {
output.(*out).Len = len(input.(*inp).Name)
return nil
})
u.SetTitle("Test")
u.SetDescription("Test Description")
u.SetName("nameLength")
h.Add(u)
assertjson.EqualMarshal(t, []byte(`{
"openapi":"3.0.3",
"info":{
"title":"JSON-RPC Example",
"description":"This app showcases a trivial JSON-RPC API.",
"version":"v1.2.3"
},
"paths":{
"nameLength":{
"post":{
"summary":"Test","description":"Test Description",
"operationId":"nameLength",
"requestBody":{
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/JsonrpcTestInp"}}
}
},
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/JsonrpcTestOut"}}
}
}
}
}
}
},
"components":{
"schemas":{
"JsonrpcTestInp":{"type":"object","properties":{"name":{"type":"string"}}},
"JsonrpcTestOut":{"type":"object","properties":{"len":{"type":"integer"}}}
}
},
"x-envelope":"jsonrpc-2.0"
}`), apiSchema.Reflector().SpecEns())
}