-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_spec_types.go
64 lines (56 loc) · 1.95 KB
/
api_spec_types.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
package allsrvc
// JSON API spec envelope types
type (
// RespBody represents a JSON-API response body.
// https://jsonapi.org/format/#document-top-level
//
// note: data can be either an array or a single resource object. This allows for both.
RespBody[Attr Attrs] struct {
Meta RespMeta `json:"meta"`
Errs []RespErr `json:"errors,omitempty"`
Data *Data[Attr] `json:"data,omitempty"`
}
// Data represents a JSON-API data response.
//
// https://jsonapi.org/format/#document-top-level
Data[Attr Attrs] struct {
Type string `json:"type"`
ID string `json:"id"`
Attrs Attr `json:"attributes"`
// omitting the relationships here for brevity not at lvl 3 RMM
}
// Attrs can be either a document or a collection of documents.
Attrs interface {
any | []Attrs
}
// RespMeta represents a JSON-API meta object. The data here is
// useful for our example service. You can add whatever non-standard
// context that is relevant to your domain here.
// https://jsonapi.org/format/#document-meta
RespMeta struct {
TookMilli int `json:"took_ms"`
TraceID string `json:"trace_id"`
}
// RespErr represents a JSON-API error object. Do note that we
// aren't implementing the entire error type. Just the most impactful
// bits for this workshop. Mainly, skipping Title & description separation.
// https://jsonapi.org/format/#error-objects
RespErr struct {
Status int `json:"status,string"`
Code int `json:"code"`
Msg string `json:"message"`
Source *RespErrSource `json:"source"`
}
// RespErrSource represents a JSON-API err source.
// https://jsonapi.org/format/#error-objects
RespErrSource struct {
Pointer string `json:"pointer"`
Parameter string `json:"parameter,omitempty"`
Header string `json:"header,omitempty"`
}
// ReqBody represents a JSON-API request body.
// https://jsonapi.org/format/#crud-creating
ReqBody[Attr Attrs] struct {
Data Data[Attr] `json:"data"`
}
)