generated-client.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. // Package client provides primitives to interact with the openapi HTTP API.
  2. //
  3. // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
  4. package client
  5. import (
  6. "bytes"
  7. "context"
  8. "encoding/json"
  9. "fmt"
  10. "io"
  11. "net/http"
  12. "net/url"
  13. "strings"
  14. )
  15. // SessionInfo defines model for Session.Info.
  16. type SessionInfo struct {
  17. Id string `json:"id"`
  18. ShareID *string `json:"shareID,omitempty"`
  19. Title string `json:"title"`
  20. Tokens struct {
  21. Input float32 `json:"input"`
  22. Output float32 `json:"output"`
  23. Reasoning float32 `json:"reasoning"`
  24. } `json:"tokens"`
  25. }
  26. // PostSessionChatJSONBody defines parameters for PostSessionChat.
  27. type PostSessionChatJSONBody struct {
  28. Parts *interface{} `json:"parts,omitempty"`
  29. SessionID string `json:"sessionID"`
  30. }
  31. // PostSessionMessagesJSONBody defines parameters for PostSessionMessages.
  32. type PostSessionMessagesJSONBody struct {
  33. SessionID string `json:"sessionID"`
  34. }
  35. // PostSessionShareJSONBody defines parameters for PostSessionShare.
  36. type PostSessionShareJSONBody struct {
  37. SessionID string `json:"sessionID"`
  38. }
  39. // PostSessionChatJSONRequestBody defines body for PostSessionChat for application/json ContentType.
  40. type PostSessionChatJSONRequestBody PostSessionChatJSONBody
  41. // PostSessionMessagesJSONRequestBody defines body for PostSessionMessages for application/json ContentType.
  42. type PostSessionMessagesJSONRequestBody PostSessionMessagesJSONBody
  43. // PostSessionShareJSONRequestBody defines body for PostSessionShare for application/json ContentType.
  44. type PostSessionShareJSONRequestBody PostSessionShareJSONBody
  45. // RequestEditorFn is the function signature for the RequestEditor callback function
  46. type RequestEditorFn func(ctx context.Context, req *http.Request) error
  47. // Doer performs HTTP requests.
  48. //
  49. // The standard http.Client implements this interface.
  50. type HttpRequestDoer interface {
  51. Do(req *http.Request) (*http.Response, error)
  52. }
  53. // Client which conforms to the OpenAPI3 specification for this service.
  54. type Client struct {
  55. // The endpoint of the server conforming to this interface, with scheme,
  56. // https://api.deepmap.com for example. This can contain a path relative
  57. // to the server, such as https://api.deepmap.com/dev-test, and all the
  58. // paths in the swagger spec will be appended to the server.
  59. Server string
  60. // Doer for performing requests, typically a *http.Client with any
  61. // customized settings, such as certificate chains.
  62. Client HttpRequestDoer
  63. // A list of callbacks for modifying requests which are generated before sending over
  64. // the network.
  65. RequestEditors []RequestEditorFn
  66. }
  67. // ClientOption allows setting custom parameters during construction
  68. type ClientOption func(*Client) error
  69. // Creates a new Client, with reasonable defaults
  70. func NewClient(server string, opts ...ClientOption) (*Client, error) {
  71. // create a client with sane default values
  72. client := Client{
  73. Server: server,
  74. }
  75. // mutate client and add all optional params
  76. for _, o := range opts {
  77. if err := o(&client); err != nil {
  78. return nil, err
  79. }
  80. }
  81. // ensure the server URL always has a trailing slash
  82. if !strings.HasSuffix(client.Server, "/") {
  83. client.Server += "/"
  84. }
  85. // create httpClient, if not already present
  86. if client.Client == nil {
  87. client.Client = &http.Client{}
  88. }
  89. return &client, nil
  90. }
  91. // WithHTTPClient allows overriding the default Doer, which is
  92. // automatically created using http.Client. This is useful for tests.
  93. func WithHTTPClient(doer HttpRequestDoer) ClientOption {
  94. return func(c *Client) error {
  95. c.Client = doer
  96. return nil
  97. }
  98. }
  99. // WithRequestEditorFn allows setting up a callback function, which will be
  100. // called right before sending the request. This can be used to mutate the request.
  101. func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
  102. return func(c *Client) error {
  103. c.RequestEditors = append(c.RequestEditors, fn)
  104. return nil
  105. }
  106. }
  107. // The interface specification for the client above.
  108. type ClientInterface interface {
  109. // PostSessionChatWithBody request with any body
  110. PostSessionChatWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
  111. PostSessionChat(ctx context.Context, body PostSessionChatJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
  112. // PostSessionCreate request
  113. PostSessionCreate(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
  114. // PostSessionMessagesWithBody request with any body
  115. PostSessionMessagesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
  116. PostSessionMessages(ctx context.Context, body PostSessionMessagesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
  117. // PostSessionShareWithBody request with any body
  118. PostSessionShareWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
  119. PostSessionShare(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
  120. }
  121. func (c *Client) PostSessionChatWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
  122. req, err := NewPostSessionChatRequestWithBody(c.Server, contentType, body)
  123. if err != nil {
  124. return nil, err
  125. }
  126. req = req.WithContext(ctx)
  127. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  128. return nil, err
  129. }
  130. return c.Client.Do(req)
  131. }
  132. func (c *Client) PostSessionChat(ctx context.Context, body PostSessionChatJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
  133. req, err := NewPostSessionChatRequest(c.Server, body)
  134. if err != nil {
  135. return nil, err
  136. }
  137. req = req.WithContext(ctx)
  138. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  139. return nil, err
  140. }
  141. return c.Client.Do(req)
  142. }
  143. func (c *Client) PostSessionCreate(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
  144. req, err := NewPostSessionCreateRequest(c.Server)
  145. if err != nil {
  146. return nil, err
  147. }
  148. req = req.WithContext(ctx)
  149. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  150. return nil, err
  151. }
  152. return c.Client.Do(req)
  153. }
  154. func (c *Client) PostSessionMessagesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
  155. req, err := NewPostSessionMessagesRequestWithBody(c.Server, contentType, body)
  156. if err != nil {
  157. return nil, err
  158. }
  159. req = req.WithContext(ctx)
  160. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  161. return nil, err
  162. }
  163. return c.Client.Do(req)
  164. }
  165. func (c *Client) PostSessionMessages(ctx context.Context, body PostSessionMessagesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
  166. req, err := NewPostSessionMessagesRequest(c.Server, body)
  167. if err != nil {
  168. return nil, err
  169. }
  170. req = req.WithContext(ctx)
  171. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  172. return nil, err
  173. }
  174. return c.Client.Do(req)
  175. }
  176. func (c *Client) PostSessionShareWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
  177. req, err := NewPostSessionShareRequestWithBody(c.Server, contentType, body)
  178. if err != nil {
  179. return nil, err
  180. }
  181. req = req.WithContext(ctx)
  182. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  183. return nil, err
  184. }
  185. return c.Client.Do(req)
  186. }
  187. func (c *Client) PostSessionShare(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
  188. req, err := NewPostSessionShareRequest(c.Server, body)
  189. if err != nil {
  190. return nil, err
  191. }
  192. req = req.WithContext(ctx)
  193. if err := c.applyEditors(ctx, req, reqEditors); err != nil {
  194. return nil, err
  195. }
  196. return c.Client.Do(req)
  197. }
  198. // NewPostSessionChatRequest calls the generic PostSessionChat builder with application/json body
  199. func NewPostSessionChatRequest(server string, body PostSessionChatJSONRequestBody) (*http.Request, error) {
  200. var bodyReader io.Reader
  201. buf, err := json.Marshal(body)
  202. if err != nil {
  203. return nil, err
  204. }
  205. bodyReader = bytes.NewReader(buf)
  206. return NewPostSessionChatRequestWithBody(server, "application/json", bodyReader)
  207. }
  208. // NewPostSessionChatRequestWithBody generates requests for PostSessionChat with any type of body
  209. func NewPostSessionChatRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
  210. var err error
  211. serverURL, err := url.Parse(server)
  212. if err != nil {
  213. return nil, err
  214. }
  215. operationPath := fmt.Sprintf("/session_chat")
  216. if operationPath[0] == '/' {
  217. operationPath = "." + operationPath
  218. }
  219. queryURL, err := serverURL.Parse(operationPath)
  220. if err != nil {
  221. return nil, err
  222. }
  223. req, err := http.NewRequest("POST", queryURL.String(), body)
  224. if err != nil {
  225. return nil, err
  226. }
  227. req.Header.Add("Content-Type", contentType)
  228. return req, nil
  229. }
  230. // NewPostSessionCreateRequest generates requests for PostSessionCreate
  231. func NewPostSessionCreateRequest(server string) (*http.Request, error) {
  232. var err error
  233. serverURL, err := url.Parse(server)
  234. if err != nil {
  235. return nil, err
  236. }
  237. operationPath := fmt.Sprintf("/session_create")
  238. if operationPath[0] == '/' {
  239. operationPath = "." + operationPath
  240. }
  241. queryURL, err := serverURL.Parse(operationPath)
  242. if err != nil {
  243. return nil, err
  244. }
  245. req, err := http.NewRequest("POST", queryURL.String(), nil)
  246. if err != nil {
  247. return nil, err
  248. }
  249. return req, nil
  250. }
  251. // NewPostSessionMessagesRequest calls the generic PostSessionMessages builder with application/json body
  252. func NewPostSessionMessagesRequest(server string, body PostSessionMessagesJSONRequestBody) (*http.Request, error) {
  253. var bodyReader io.Reader
  254. buf, err := json.Marshal(body)
  255. if err != nil {
  256. return nil, err
  257. }
  258. bodyReader = bytes.NewReader(buf)
  259. return NewPostSessionMessagesRequestWithBody(server, "application/json", bodyReader)
  260. }
  261. // NewPostSessionMessagesRequestWithBody generates requests for PostSessionMessages with any type of body
  262. func NewPostSessionMessagesRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
  263. var err error
  264. serverURL, err := url.Parse(server)
  265. if err != nil {
  266. return nil, err
  267. }
  268. operationPath := fmt.Sprintf("/session_messages")
  269. if operationPath[0] == '/' {
  270. operationPath = "." + operationPath
  271. }
  272. queryURL, err := serverURL.Parse(operationPath)
  273. if err != nil {
  274. return nil, err
  275. }
  276. req, err := http.NewRequest("POST", queryURL.String(), body)
  277. if err != nil {
  278. return nil, err
  279. }
  280. req.Header.Add("Content-Type", contentType)
  281. return req, nil
  282. }
  283. // NewPostSessionShareRequest calls the generic PostSessionShare builder with application/json body
  284. func NewPostSessionShareRequest(server string, body PostSessionShareJSONRequestBody) (*http.Request, error) {
  285. var bodyReader io.Reader
  286. buf, err := json.Marshal(body)
  287. if err != nil {
  288. return nil, err
  289. }
  290. bodyReader = bytes.NewReader(buf)
  291. return NewPostSessionShareRequestWithBody(server, "application/json", bodyReader)
  292. }
  293. // NewPostSessionShareRequestWithBody generates requests for PostSessionShare with any type of body
  294. func NewPostSessionShareRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
  295. var err error
  296. serverURL, err := url.Parse(server)
  297. if err != nil {
  298. return nil, err
  299. }
  300. operationPath := fmt.Sprintf("/session_share")
  301. if operationPath[0] == '/' {
  302. operationPath = "." + operationPath
  303. }
  304. queryURL, err := serverURL.Parse(operationPath)
  305. if err != nil {
  306. return nil, err
  307. }
  308. req, err := http.NewRequest("POST", queryURL.String(), body)
  309. if err != nil {
  310. return nil, err
  311. }
  312. req.Header.Add("Content-Type", contentType)
  313. return req, nil
  314. }
  315. func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
  316. for _, r := range c.RequestEditors {
  317. if err := r(ctx, req); err != nil {
  318. return err
  319. }
  320. }
  321. for _, r := range additionalEditors {
  322. if err := r(ctx, req); err != nil {
  323. return err
  324. }
  325. }
  326. return nil
  327. }
  328. // ClientWithResponses builds on ClientInterface to offer response payloads
  329. type ClientWithResponses struct {
  330. ClientInterface
  331. }
  332. // NewClientWithResponses creates a new ClientWithResponses, which wraps
  333. // Client with return type handling
  334. func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) {
  335. client, err := NewClient(server, opts...)
  336. if err != nil {
  337. return nil, err
  338. }
  339. return &ClientWithResponses{client}, nil
  340. }
  341. // WithBaseURL overrides the baseURL.
  342. func WithBaseURL(baseURL string) ClientOption {
  343. return func(c *Client) error {
  344. newBaseURL, err := url.Parse(baseURL)
  345. if err != nil {
  346. return err
  347. }
  348. c.Server = newBaseURL.String()
  349. return nil
  350. }
  351. }
  352. // ClientWithResponsesInterface is the interface specification for the client with responses above.
  353. type ClientWithResponsesInterface interface {
  354. // PostSessionChatWithBodyWithResponse request with any body
  355. PostSessionChatWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error)
  356. PostSessionChatWithResponse(ctx context.Context, body PostSessionChatJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error)
  357. // PostSessionCreateWithResponse request
  358. PostSessionCreateWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionCreateResponse, error)
  359. // PostSessionMessagesWithBodyWithResponse request with any body
  360. PostSessionMessagesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionMessagesResponse, error)
  361. PostSessionMessagesWithResponse(ctx context.Context, body PostSessionMessagesJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionMessagesResponse, error)
  362. // PostSessionShareWithBodyWithResponse request with any body
  363. PostSessionShareWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionShareResponse, error)
  364. PostSessionShareWithResponse(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionShareResponse, error)
  365. }
  366. type PostSessionChatResponse struct {
  367. Body []byte
  368. HTTPResponse *http.Response
  369. }
  370. // Status returns HTTPResponse.Status
  371. func (r PostSessionChatResponse) Status() string {
  372. if r.HTTPResponse != nil {
  373. return r.HTTPResponse.Status
  374. }
  375. return http.StatusText(0)
  376. }
  377. // StatusCode returns HTTPResponse.StatusCode
  378. func (r PostSessionChatResponse) StatusCode() int {
  379. if r.HTTPResponse != nil {
  380. return r.HTTPResponse.StatusCode
  381. }
  382. return 0
  383. }
  384. type PostSessionCreateResponse struct {
  385. Body []byte
  386. HTTPResponse *http.Response
  387. JSON200 *SessionInfo
  388. }
  389. // Status returns HTTPResponse.Status
  390. func (r PostSessionCreateResponse) Status() string {
  391. if r.HTTPResponse != nil {
  392. return r.HTTPResponse.Status
  393. }
  394. return http.StatusText(0)
  395. }
  396. // StatusCode returns HTTPResponse.StatusCode
  397. func (r PostSessionCreateResponse) StatusCode() int {
  398. if r.HTTPResponse != nil {
  399. return r.HTTPResponse.StatusCode
  400. }
  401. return 0
  402. }
  403. type PostSessionMessagesResponse struct {
  404. Body []byte
  405. HTTPResponse *http.Response
  406. JSON200 *interface{}
  407. }
  408. // Status returns HTTPResponse.Status
  409. func (r PostSessionMessagesResponse) Status() string {
  410. if r.HTTPResponse != nil {
  411. return r.HTTPResponse.Status
  412. }
  413. return http.StatusText(0)
  414. }
  415. // StatusCode returns HTTPResponse.StatusCode
  416. func (r PostSessionMessagesResponse) StatusCode() int {
  417. if r.HTTPResponse != nil {
  418. return r.HTTPResponse.StatusCode
  419. }
  420. return 0
  421. }
  422. type PostSessionShareResponse struct {
  423. Body []byte
  424. HTTPResponse *http.Response
  425. JSON200 *SessionInfo
  426. }
  427. // Status returns HTTPResponse.Status
  428. func (r PostSessionShareResponse) Status() string {
  429. if r.HTTPResponse != nil {
  430. return r.HTTPResponse.Status
  431. }
  432. return http.StatusText(0)
  433. }
  434. // StatusCode returns HTTPResponse.StatusCode
  435. func (r PostSessionShareResponse) StatusCode() int {
  436. if r.HTTPResponse != nil {
  437. return r.HTTPResponse.StatusCode
  438. }
  439. return 0
  440. }
  441. // PostSessionChatWithBodyWithResponse request with arbitrary body returning *PostSessionChatResponse
  442. func (c *ClientWithResponses) PostSessionChatWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error) {
  443. rsp, err := c.PostSessionChatWithBody(ctx, contentType, body, reqEditors...)
  444. if err != nil {
  445. return nil, err
  446. }
  447. return ParsePostSessionChatResponse(rsp)
  448. }
  449. func (c *ClientWithResponses) PostSessionChatWithResponse(ctx context.Context, body PostSessionChatJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error) {
  450. rsp, err := c.PostSessionChat(ctx, body, reqEditors...)
  451. if err != nil {
  452. return nil, err
  453. }
  454. return ParsePostSessionChatResponse(rsp)
  455. }
  456. // PostSessionCreateWithResponse request returning *PostSessionCreateResponse
  457. func (c *ClientWithResponses) PostSessionCreateWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionCreateResponse, error) {
  458. rsp, err := c.PostSessionCreate(ctx, reqEditors...)
  459. if err != nil {
  460. return nil, err
  461. }
  462. return ParsePostSessionCreateResponse(rsp)
  463. }
  464. // PostSessionMessagesWithBodyWithResponse request with arbitrary body returning *PostSessionMessagesResponse
  465. func (c *ClientWithResponses) PostSessionMessagesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionMessagesResponse, error) {
  466. rsp, err := c.PostSessionMessagesWithBody(ctx, contentType, body, reqEditors...)
  467. if err != nil {
  468. return nil, err
  469. }
  470. return ParsePostSessionMessagesResponse(rsp)
  471. }
  472. func (c *ClientWithResponses) PostSessionMessagesWithResponse(ctx context.Context, body PostSessionMessagesJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionMessagesResponse, error) {
  473. rsp, err := c.PostSessionMessages(ctx, body, reqEditors...)
  474. if err != nil {
  475. return nil, err
  476. }
  477. return ParsePostSessionMessagesResponse(rsp)
  478. }
  479. // PostSessionShareWithBodyWithResponse request with arbitrary body returning *PostSessionShareResponse
  480. func (c *ClientWithResponses) PostSessionShareWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionShareResponse, error) {
  481. rsp, err := c.PostSessionShareWithBody(ctx, contentType, body, reqEditors...)
  482. if err != nil {
  483. return nil, err
  484. }
  485. return ParsePostSessionShareResponse(rsp)
  486. }
  487. func (c *ClientWithResponses) PostSessionShareWithResponse(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionShareResponse, error) {
  488. rsp, err := c.PostSessionShare(ctx, body, reqEditors...)
  489. if err != nil {
  490. return nil, err
  491. }
  492. return ParsePostSessionShareResponse(rsp)
  493. }
  494. // ParsePostSessionChatResponse parses an HTTP response from a PostSessionChatWithResponse call
  495. func ParsePostSessionChatResponse(rsp *http.Response) (*PostSessionChatResponse, error) {
  496. bodyBytes, err := io.ReadAll(rsp.Body)
  497. defer func() { _ = rsp.Body.Close() }()
  498. if err != nil {
  499. return nil, err
  500. }
  501. response := &PostSessionChatResponse{
  502. Body: bodyBytes,
  503. HTTPResponse: rsp,
  504. }
  505. return response, nil
  506. }
  507. // ParsePostSessionCreateResponse parses an HTTP response from a PostSessionCreateWithResponse call
  508. func ParsePostSessionCreateResponse(rsp *http.Response) (*PostSessionCreateResponse, error) {
  509. bodyBytes, err := io.ReadAll(rsp.Body)
  510. defer func() { _ = rsp.Body.Close() }()
  511. if err != nil {
  512. return nil, err
  513. }
  514. response := &PostSessionCreateResponse{
  515. Body: bodyBytes,
  516. HTTPResponse: rsp,
  517. }
  518. switch {
  519. case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
  520. var dest SessionInfo
  521. if err := json.Unmarshal(bodyBytes, &dest); err != nil {
  522. return nil, err
  523. }
  524. response.JSON200 = &dest
  525. }
  526. return response, nil
  527. }
  528. // ParsePostSessionMessagesResponse parses an HTTP response from a PostSessionMessagesWithResponse call
  529. func ParsePostSessionMessagesResponse(rsp *http.Response) (*PostSessionMessagesResponse, error) {
  530. bodyBytes, err := io.ReadAll(rsp.Body)
  531. defer func() { _ = rsp.Body.Close() }()
  532. if err != nil {
  533. return nil, err
  534. }
  535. response := &PostSessionMessagesResponse{
  536. Body: bodyBytes,
  537. HTTPResponse: rsp,
  538. }
  539. switch {
  540. case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
  541. var dest interface{}
  542. if err := json.Unmarshal(bodyBytes, &dest); err != nil {
  543. return nil, err
  544. }
  545. response.JSON200 = &dest
  546. }
  547. return response, nil
  548. }
  549. // ParsePostSessionShareResponse parses an HTTP response from a PostSessionShareWithResponse call
  550. func ParsePostSessionShareResponse(rsp *http.Response) (*PostSessionShareResponse, error) {
  551. bodyBytes, err := io.ReadAll(rsp.Body)
  552. defer func() { _ = rsp.Body.Close() }()
  553. if err != nil {
  554. return nil, err
  555. }
  556. response := &PostSessionShareResponse{
  557. Body: bodyBytes,
  558. HTTPResponse: rsp,
  559. }
  560. switch {
  561. case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
  562. var dest SessionInfo
  563. if err := json.Unmarshal(bodyBytes, &dest); err != nil {
  564. return nil, err
  565. }
  566. response.JSON200 = &dest
  567. }
  568. return response, nil
  569. }