Debian Codegraph @

internal/comments/types.go

raw
1 package main
2
3 // Took
4 // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/comments.json
5 // and put it into something like https://mholt.github.io/json-to-go/, deduping
6 // and cleaning up the structs manually.
7
8 // Param represents an individual entry in a request's Params field, or in an
9 // event or request's Returns field.
10 type Param struct {
11 Description string `json:"description"`
12 Name string `json:"name"`
13 Type string `json:"type"`
14 }
15
16 // Event represents the specification of an event. Its fields are also common
17 // for a Request, and embedded in that definition.
18 type Event struct {
19 // API can either be "events" or "requests"
20 API string `json:"api"`
21
22 // Category is the subsection of the Event or Request, e.g. "general" or
23 // "sources". We don't really need this as we already know which
24 // category an event or request belongs to since the parent key of this
25 // event or request is also the category.
26 Category string `json:"category"`
27
28 // Categories is like Category because it's only ever of length one, but
29 // I imagine it's a slice for future-proofing reasons.
30 Categories []struct {
31 Description string `json:"description"`
32 Name string `json:"name"`
33 } `json:"categories"`
34
35 // Lead is a preface for the description. If it's present, we should use
36 // it first.
37 Lead string `json:"lead"`
38
39 // Description is... the description.
40 Description string `json:"description"`
41
42 // Name is the name of the event or request.
43 Name string `json:"name"`
44
45 // Names is like Name because it's only ever of length one, but
46 // I imagine it's a slice for future-proofing reasons.
47 Names []struct {
48 Description string `json:"description"`
49 Name string `json:"name"`
50 } `json:"names"`
51
52 // Return is a neat representation of the fields in the JSON response of
53 // the event or request, I guess for documentation purposes. It could be
54 // either a `[]string` or just a `string`. For programmatic and parsing
55 // purposes, Returns is easier to use though.
56 Return interface{} `json:"return"`
57
58 // Returns is a representation of the fields in the JSON response.
59 Returns []*Param `json:"returns"`
60
61 // The following are kinda unnecessary fields, but keep them here
62 // because I already did the work
63
64 // Since is the version the event or request was introduced in.
65 Since string `json:"since"`
66
67 // Sinces is like Since because it's only ever of length one, but
68 // I imagine it's a slice for future-proofing reasons.
69 Sinces []struct {
70 Description string `json:"description"`
71 Name string `json:"name"`
72 } `json:"sinces"`
73
74 // Examples looks to be always empty, but I guess it's for examples.
75 Examples []interface{} `json:"examples"`
76
77 // Heading is just for documentation generation on Palakis' end.
78 Heading struct {
79 Level int `json:"level"`
80 Text string `json:"text"`
81 } `json:"heading"`
82
83 // Subheads looks to be always empty, but it's probably for
84 // documentation purposes again.
85 Subheads []interface{} `json:"subheads"`
86
87 // Type looks to be always "class" for events and requests.
88 Type string `json:"type"`
89 }
90
91 // Request surprisingly represents a Request.
92 type Request struct {
93 *Event
94
95 // Param is a neat representation of the fields in the JSON request,
96 // I guess for documentation purposes. It could be either a `[]string`
97 // or just a `string`. For programmatic and parsing purposes, Params is
98 // easier to use though.
99 Param interface{} `json:"param,omitempty"`
100
101 // Params is a representation of the fields in the JSON request.
102 Params []*Param `json:"params"`
103
104 // Deprecated is deprecation text for the request. If it's present, we
105 // know the request is deprecated. We'd have to parse the string to find
106 // out what exact version it was deprecated though.
107 Deprecated string `json:"deprecated,omitempty"`
108
109 // Deprecateds is like deprecated. Probably for future-proofing, but
110 // I can't imagine why since it's not like you can have two different
111 // deprecation versions. Who cares -- I don't need it.
112 Deprecateds []struct {
113 Description string `json:"description"`
114 Name string `json:"name"`
115 } `json:"deprecateds,omitempty"`
116 }
117
118 // TypeDef defines more complex types
119 type TypeDef struct {
120 Examples []interface{} `json:"examples"`
121 Heading struct {
122 Level int `json:"level"`
123 Text string `json:"text"`
124 } `json:"heading"`
125 Name string `json:"name"`
126 Properties []*Param `json:"properties"`
127 Property interface{} `json:"property"` // could be []string or just string; not so important since Properties has all the info we'd need
128 Subheads []interface{} `json:"subheads"`
129 TypeDef string `json:"typedef"`
130 TypeDefs []*Param `json:"typedefs"`
131 }
132
133 // Comments represents the generated comments.json from Palakis
134 type Comments struct {
135 Events map[string][]*Event `json:"events"`
136 Requests map[string][]*Request `json:"requests"`
137 TypeDefs []*TypeDef `json:"typedefs"`
138 }