Skip to content

Commit

Permalink
wow of course the protocol has undocumented fields it returns
Browse files Browse the repository at this point in the history
  • Loading branch information
andreykaipov committed May 8, 2024
1 parent cc5e3d0 commit c2f0593
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/requests/record/xx_generated.togglerecordpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func (o *ToggleRecordPauseParams) GetRequestName() string {
// Represents the response body for the ToggleRecordPause request.
type ToggleRecordPauseResponse struct {
_response

OutputPaused bool `json:"outputPaused,omitempty"`
}

// Toggles pause on the record output.
Expand Down
23 changes: 19 additions & 4 deletions internal/generate/protocol/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ func generateRequest(request *Request) (s *Statement, err error) {
structName = name + "Response"
s.Commentf("Represents the response body for the %s request.", name).Line()

respf := &ResponseField{}
respf.ValueName = "_response"
respf.ValueType = "~requests~" // internal type
request.ResponseFields = append(request.ResponseFields, respf)
augmentStructFromProtocol(structName, request)

if err := generateStructFromParams("response", s, structName, request.ResponseFields); err != nil {
return nil, fmt.Errorf("Failed parsing 'Returns' for request %q in category %q", name, category)
Expand Down Expand Up @@ -397,6 +394,24 @@ func generateRequestStatuses(enums []*Enum, filter enumFilter) {
}
}

func augmentStructFromProtocol(name string, request *Request) {
if strings.HasSuffix(name, "Response") {
respf := &ResponseField{}
respf.ValueName = "_response"
respf.ValueType = "~requests~" // internal type
request.ResponseFields = append(request.ResponseFields, respf)
}

// the protocol sometimes omits fields that are returned by the server
switch name {
case "ToggleRecordPauseResponse":
f := &ResponseField{}
f.ValueName = "outputPaused"
f.ValueType = "Boolean"
request.ResponseFields = append(request.ResponseFields, f)
}
}

func generateStructFromParams[F Field](origin string, s *Statement, name string, fields []F) error {
keysInfo := map[string]keyInfo{}

Expand Down

0 comments on commit c2f0593

Please sign in to comment.