// Code generated by ogen, DO NOT EDIT. package openapi import ( "fmt" "io" "mime" "net/http" "github.com/go-faster/errors" "github.com/go-faster/jx" "github.com/ogen-go/ogen/ogenerrors" "github.com/ogen-go/ogen/validate" ) func decodeGroupsGetResponse(resp *http.Response) (res []Group, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response []Group if err := func() error { response = make([]Group, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Group if err := elem.Decode(d); err != nil { return err } response = append(response, elem) return nil }); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if response == nil { return errors.New("nil is invalid value") } var failures []validate.FieldError for i, elem := range response { if err := func() error { if err := elem.Validate(); err != nil { return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ Name: fmt.Sprintf("[%d]", i), Error: err, }) } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeGroupsIDDeleteResponse(resp *http.Response) (res GroupsIDDeleteRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Ok if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeGroupsIDGetResponse(resp *http.Response) (res GroupsIDGetRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Group if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeGroupsIDPutResponse(resp *http.Response) (res GroupsIDPutRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Group if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeGroupsPostResponse(resp *http.Response) (res *Group, _ error) { switch resp.StatusCode { case 201: // Code 201. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Group if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeHealthzGetResponse(resp *http.Response) (res *Ok, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Ok if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersGetResponse(resp *http.Response) (res []User, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response []User if err := func() error { response = make([]User, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem User if err := elem.Decode(d); err != nil { return err } response = append(response, elem) return nil }); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if response == nil { return errors.New("nil is invalid value") } var failures []validate.FieldError for i, elem := range response { if err := func() error { if err := elem.Validate(); err != nil { return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ Name: fmt.Sprintf("[%d]", i), Error: err, }) } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersIDDeleteResponse(resp *http.Response) (res UsersIDDeleteRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Ok if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersIDGetResponse(resp *http.Response) (res UsersIDGetRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response User if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersIDGroupPutResponse(resp *http.Response) (res UsersIDGroupPutRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response User if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersIDPutResponse(resp *http.Response) (res UsersIDPutRes, _ error) { switch resp.StatusCode { case 200: // Code 200. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response User if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } case 404: // Code 404. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") } func decodeUsersPostResponse(resp *http.Response) (res *User, _ error) { switch resp.StatusCode { case 201: // Code 201. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response User if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } // Validate response. if err := func() error { if err := response.Validate(); err != nil { return err } return nil }(); err != nil { return res, errors.Wrap(err, "validate") } return &response, nil default: return res, validate.InvalidContentType(ct) } } // Convenient error response. defRes, err := func() (res *ErrorStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response Error if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &ErrorStatusCode{ StatusCode: resp.StatusCode, Response: response, }, nil default: return res, validate.InvalidContentType(ct) } }() if err != nil { return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) } return res, errors.Wrap(defRes, "error") }