diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..968412e --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +generate: + go generate ./... \ No newline at end of file diff --git a/api/swagger.yaml b/api/swagger.yaml index 7824acc..cf0624c 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5,10 +5,11 @@ info: description: For generate API REST clients for Feelter UGC contact: email: garin1221@yandex.ru - version: 1.0.0 + version: 0.0.2 servers: - url: https://www.youtubekids.com/youtubei/v1 + description: Original YoutubeKids API Server V1 tags: - name: browse @@ -37,8 +38,8 @@ paths: 'application/json': "schema": $ref: '#/components/schemas/BrowseResponsePayload' - '400': - description: Bad Request + default: + description: Unexpected error content: 'application/json': "schema": @@ -52,6 +53,8 @@ components: # Ошибка Error: type: object + required: + - message properties: message: type: string @@ -104,6 +107,8 @@ components: # Текст -> Runs TextRun: type: object + required: + - text properties: text: type: string @@ -113,6 +118,8 @@ components: # Текст Text: type: object + required: + - runs properties: runs: type: array @@ -124,6 +131,9 @@ components: # Строковый параметр ключ-зачение KeyStringValue: type: object + required: + - key + - value properties: key: type: string @@ -133,6 +143,8 @@ components: # Ассеты категории CategoryAssets: type: object + required: + - assetKey properties: assetKey: type: string @@ -142,6 +154,8 @@ components: # Расширение для владельцев детских видео KidsVideoOwnerExtension: type: object + required: + - externalChannelId properties: externalChannelId: type: string @@ -149,17 +163,27 @@ components: # Thumbnail Thumbnail: type: object + required: + - url + - width + - height properties: url: type: string width: - type: number + type: integer height: - type: number + type: integer - # Компактный видеорендерер + # Рендер карточки с видео CompactVideoRenderer: type: object + required: + - videoId + - title + - viewCountText + - trackingParams + - kidsVideoOwnerExtension properties: videoId: type: string @@ -200,15 +224,107 @@ components: kidsVideoOwnerExtension: $ref: '#/components/schemas/KidsVideoOwnerExtension' + # Рендер карточки с плейлистом + CompactPlaylistRenderer: + type: object + required: + - playlistId + - title + - viewCountText + - trackingParams + properties: + playlistId: + type: string + thumbnail: + type: object + properties: + thumbnails: + type: array + items: + $ref: '#/components/schemas/Thumbnail' + title: + $ref: '#/components/schemas/Text' + shortBylineText: + $ref: '#/components/schemas/Text' + videoCountText: + $ref: '#/components/schemas/Text' + navigationEndpoint: + $ref: '#/components/schemas/NavigationEndpoint' + videoCountShortText: + $ref: '#/components/schemas/Text' + trackingParams: + type: string + sidebarThumbnails: + type: array + items: + type: object + properties: + thumbnails: + type: array + items: + $ref: '#/components/schemas/Thumbnail' + thumbnailText: + $ref: '#/components/schemas/Text' + shareUrl: + type: string + longBylineText: + $ref: '#/components/schemas/Text' + tvBanner: + type: object + properties: + thumbnails: + type: array + items: + $ref: '#/components/schemas/Thumbnail' + + # Рендер карточки с каналом + CompactChannelRenderer: + type: object + required: + - channelId + - displayName + - videoCountText + - title + - trackingParams + properties: + channelId: + type: string + thumbnail: + type: object + properties: + thumbnails: + type: array + items: + $ref: '#/components/schemas/Thumbnail' + displayName: + $ref: '#/components/schemas/Text' + videoCountText: + $ref: '#/components/schemas/Text' + subscriberCountText: + $ref: '#/components/schemas/Text' + navigationEndpoint: + $ref: '#/components/schemas/NavigationEndpoint' + title: + $ref: '#/components/schemas/Text' + trackingParams: + type: string + # Средство визуализации раздела элемента ItemSectionRenderer: type: object + required: + - contents + - trackingParams properties: contents: type: array items: type: object properties: + compactPlaylistRenderer: + $ref: '#/components/schemas/CompactPlaylistRenderer' + compactChannelRenderer: + $ref: '#/components/schemas/CompactChannelRenderer' compactVideoRenderer: $ref: '#/components/schemas/CompactVideoRenderer' trackingParams: @@ -275,13 +391,29 @@ components: # Параметры контента KidsAppContentSettings: type: object + required: + - corpusPreference + - kidsNoSearchMode properties: corpusPreference: type: string + enum: + - KIDS_CORPUS_PREFERENCE_UNKNOWN # unknown + - KIDS_CORPUS_PREFERENCE_YOUNGER # (0-4 years) + - KIDS_CORPUS_PREFERENCE_TWEEN # (5-7) + - KIDS_CORPUS_PREFERENCE_PAM_YOUNGER + - KIDS_CORPUS_PREFERENCE_PAM_TWEEN + - KIDS_CORPUS_PREFERENCE_PRESCHOOL # (8-12) example: KIDS_CORPUS_PREFERENCE_TWEEN + default: KIDS_CORPUS_PREFERENCE_TWEEN kidsNoSearchMode: type: string + enum: + - YT_KIDS_NO_SEARCH_MODE_UNKNOWN # unknown + - YT_KIDS_NO_SEARCH_MODE_ON + - YT_KIDS_NO_SEARCH_MODE_OFF example: YT_KIDS_NO_SEARCH_MODE_OFF + default: YT_KIDS_NO_SEARCH_MODE_OFF # Конфигурация категорий KidsAppCategorySettings: @@ -307,39 +439,51 @@ components: RequestClient: type: object description: Client information + required: + - kidsAppInfo properties: clientName: type: string example: WEB_KIDS + default: WEB_KIDS clientVersion: type: string - example: 2.20230202.00.00 + example: 2.20230817.00.00 + default: 2.20230817.00.00 hl: type: string example: ru + default: ru gl: type: string example: RU + default: RU experimentsToken: type: string browserName: type: string example: Safari + default: Safari deviceMake: type: string example: apple + default: apple browserVersion: type: string example: '16.2' + default: '16.2' osName: type: string example: Macintosh + default: Macintosh osVersion: type: string - example: 10_15_7 + example: '10_15_7' + default: '10_15_7' platform: type: string example: DESKTOP + default: DESKTOP kidsAppInfo: $ref: '#/components/schemas/KidsAppInfo' @@ -347,6 +491,8 @@ components: RequestContext: type: object description: Request context + required: + - client properties: client: $ref: '#/components/schemas/RequestClient' @@ -359,7 +505,7 @@ components: visitorData: type: string maxAgeSeconds: - type: number + type: integer serviceTrackingParams: type: array items: @@ -375,9 +521,14 @@ components: # Данные для запроса на получение контента определенного ресурса BrowseRequestPayload: type: object + required: + - context + - browseId properties: context: $ref: '#/components/schemas/RequestContext' + params: + type: string browseId: type: string example: FEkids_home @@ -385,6 +536,10 @@ components: # Ответ на запрос получения контента определенного ресурса BrowseResponsePayload: type: object + required: + - header + - contents + - responseContext properties: responseContext: $ref: '#/components/schemas/ResponseContext' @@ -404,12 +559,18 @@ components: # Ответ с ошибкой ErrorResponsePayload: type: object + required: + - error properties: error: type: object + required: + - code + - status + - message properties: code: - type: number + type: integer example: 400 message: type: string diff --git a/browser_request_payload_defaults.go b/browser_request_payload_defaults.go new file mode 100644 index 0000000..8853682 --- /dev/null +++ b/browser_request_payload_defaults.go @@ -0,0 +1,9 @@ +package go_youtubekids_client + +func (p *BrowseRequestPayload) SetDefaults() *BrowseRequestPayload { + p.Context.Client.setDefaults() + if p.Context.Client.KidsAppInfo.ContentSettings.Set { + p.Context.Client.KidsAppInfo.ContentSettings.Value.setDefaults() + } + return p +} diff --git a/constants.go b/constants.go new file mode 100644 index 0000000..3fbcb8c --- /dev/null +++ b/constants.go @@ -0,0 +1,5 @@ +package go_youtubekids_client + +const DefaultServerURL = "https://www.youtubekids.com/youtubei/v1" + +const BrowseIdForKidsHome = "FEkids_home" diff --git a/examples/browse/main.go b/examples/browse/main.go new file mode 100644 index 0000000..52dff07 --- /dev/null +++ b/examples/browse/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "context" + "encoding/json" + youtubekids "githouse.ru/feelter-ugc/go-youtubekids-client" + "log" +) + +func main() { + client, err := youtubekids.NewClient(youtubekids.DefaultServerURL) + if err != nil { + panic(err) + } + response, err := client.Browse(context.TODO(), (&youtubekids.BrowseRequestPayload{ + BrowseId: youtubekids.BrowseIdForKidsHome, + Context: youtubekids.RequestContext{ + Client: youtubekids.RequestClient{}, + }, + }).SetDefaults()) + if err != nil { + panic(err) + } + data, err := json.MarshalIndent(response, "", " ") + if err != nil { + panic(err) + } + log.Println(string(data)) +} diff --git a/generate.go b/generate.go index 1f4222e..da1d625 100644 --- a/generate.go +++ b/generate.go @@ -1,3 +1,7 @@ package go_youtubekids_client +import ( + _ "github.com/ogen-go/ogen/gen" +) + //go:generate go run github.com/ogen-go/ogen/cmd/ogen -target . -clean -generate-tests -no-server -no-webhook-server -no-webhook-client -package go_youtubekids_client ./api/swagger.yaml diff --git a/go.mod b/go.mod index fa656e7..b5898e4 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,14 @@ require ( github.com/go-faster/errors v0.6.1 github.com/go-faster/jx v1.0.0 github.com/ogen-go/ogen v0.61.0 + github.com/stretchr/testify v1.8.2 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/metric v0.37.0 go.opentelemetry.io/otel/trace v1.14.0 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.8.1 // indirect github.com/fatih/color v1.15.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect @@ -21,6 +23,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.18 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/segmentio/asm v1.2.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -33,4 +36,5 @@ require ( golang.org/x/text v0.8.0 // indirect golang.org/x/tools v0.7.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 98b387d..3c2d202 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2 v1.8.1 h1:6Lcdwya6GjPUNsBct8Lg/yRPwMhABj269AAzdGSiR+0= github.com/dlclark/regexp2 v1.8.1/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= @@ -31,9 +33,16 @@ github.com/ogen-go/ogen v0.61.0 h1:U3hkx9ydCL2tb0055ut0o8hWaEOWCs2+rG2rpwCMGPM= github.com/ogen-go/ogen v0.61.0/go.mod h1:Rn43MIqVcT8utwLi45lv7e/a4kPRk+klLsWsgB1z9GQ= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs= @@ -66,4 +75,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/oas_client_gen.go b/oas_client_gen.go index a2c7e1a..1590efd 100644 --- a/oas_client_gen.go +++ b/oas_client_gen.go @@ -67,16 +67,25 @@ func (c *Client) requestURL(ctx context.Context) *url.URL { // Get content for resource. // // POST /browse -func (c *Client) Browse(ctx context.Context, request *BrowseRequestPayload) (BrowseRes, error) { +func (c *Client) Browse(ctx context.Context, request *BrowseRequestPayload) (*BrowseResponsePayload, error) { res, err := c.sendBrowse(ctx, request) _ = res return res, err } -func (c *Client) sendBrowse(ctx context.Context, request *BrowseRequestPayload) (res BrowseRes, err error) { +func (c *Client) sendBrowse(ctx context.Context, request *BrowseRequestPayload) (res *BrowseResponsePayload, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("browse"), } + // Validate request before sending. + if err := func() error { + if err := request.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return res, errors.Wrap(err, "validate") + } // Run stopwatch. startTime := time.Now() diff --git a/oas_defaults_gen.go b/oas_defaults_gen.go new file mode 100644 index 0000000..10fa673 --- /dev/null +++ b/oas_defaults_gen.go @@ -0,0 +1,59 @@ +// Code generated by ogen, DO NOT EDIT. + +package go_youtubekids_client + +// setDefaults set default value of fields. +func (s *KidsAppContentSettings) setDefaults() { + { + val := KidsAppContentSettingsCorpusPreference("KIDS_CORPUS_PREFERENCE_TWEEN") + s.CorpusPreference = val + } + { + val := KidsAppContentSettingsKidsNoSearchMode("YT_KIDS_NO_SEARCH_MODE_OFF") + s.KidsNoSearchMode = val + } +} + +// setDefaults set default value of fields. +func (s *RequestClient) setDefaults() { + { + val := string("WEB_KIDS") + s.ClientName.SetTo(val) + } + { + val := string("2.20230817.00.00") + s.ClientVersion.SetTo(val) + } + { + val := string("ru") + s.Hl.SetTo(val) + } + { + val := string("RU") + s.Gl.SetTo(val) + } + { + val := string("Safari") + s.BrowserName.SetTo(val) + } + { + val := string("apple") + s.DeviceMake.SetTo(val) + } + { + val := string("16.2") + s.BrowserVersion.SetTo(val) + } + { + val := string("Macintosh") + s.OsName.SetTo(val) + } + { + val := string("10_15_7") + s.OsVersion.SetTo(val) + } + { + val := string("DESKTOP") + s.Platform.SetTo(val) + } +} diff --git a/oas_faker_gen.go b/oas_faker_gen.go index 5495db9..518ae18 100644 --- a/oas_faker_gen.go +++ b/oas_faker_gen.go @@ -86,7 +86,12 @@ func (s *BrowseRequestPayload) SetFake() { } { { - s.BrowseId.SetFake() + s.Params.SetFake() + } + } + { + { + s.BrowseId = "string" } } } @@ -146,7 +151,7 @@ func (s *CategoriesHeaderRenderer) SetFake() { func (s *CategoryAssets) SetFake() { { { - s.AssetKey.SetFake() + s.AssetKey = "string" } } { @@ -156,11 +161,195 @@ func (s *CategoryAssets) SetFake() { } } +// SetFake set fake values. +func (s *CompactChannelRenderer) SetFake() { + { + { + s.ChannelId = "string" + } + } + { + { + s.Thumbnail.SetFake() + } + } + { + { + s.DisplayName.SetFake() + } + } + { + { + s.VideoCountText.SetFake() + } + } + { + { + s.SubscriberCountText.SetFake() + } + } + { + { + s.NavigationEndpoint.SetFake() + } + } + { + { + s.Title.SetFake() + } + } + { + { + s.TrackingParams = "string" + } + } +} + +// SetFake set fake values. +func (s *CompactChannelRendererThumbnail) SetFake() { + { + { + s.Thumbnails = nil + for i := 0; i < 0; i++ { + var elem Thumbnail + { + elem.SetFake() + } + s.Thumbnails = append(s.Thumbnails, elem) + } + } + } +} + +// SetFake set fake values. +func (s *CompactPlaylistRenderer) SetFake() { + { + { + s.PlaylistId = "string" + } + } + { + { + s.Thumbnail.SetFake() + } + } + { + { + s.Title.SetFake() + } + } + { + { + s.ShortBylineText.SetFake() + } + } + { + { + s.VideoCountText.SetFake() + } + } + { + { + s.NavigationEndpoint.SetFake() + } + } + { + { + s.VideoCountShortText.SetFake() + } + } + { + { + s.TrackingParams = "string" + } + } + { + { + s.SidebarThumbnails = nil + for i := 0; i < 0; i++ { + var elem CompactPlaylistRendererSidebarThumbnailsItem + { + elem.SetFake() + } + s.SidebarThumbnails = append(s.SidebarThumbnails, elem) + } + } + } + { + { + s.ThumbnailText.SetFake() + } + } + { + { + s.ShareUrl.SetFake() + } + } + { + { + s.LongBylineText.SetFake() + } + } + { + { + s.TvBanner.SetFake() + } + } +} + +// SetFake set fake values. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) SetFake() { + { + { + s.Thumbnails = nil + for i := 0; i < 0; i++ { + var elem Thumbnail + { + elem.SetFake() + } + s.Thumbnails = append(s.Thumbnails, elem) + } + } + } +} + +// SetFake set fake values. +func (s *CompactPlaylistRendererThumbnail) SetFake() { + { + { + s.Thumbnails = nil + for i := 0; i < 0; i++ { + var elem Thumbnail + { + elem.SetFake() + } + s.Thumbnails = append(s.Thumbnails, elem) + } + } + } +} + +// SetFake set fake values. +func (s *CompactPlaylistRendererTvBanner) SetFake() { + { + { + s.Thumbnails = nil + for i := 0; i < 0; i++ { + var elem Thumbnail + { + elem.SetFake() + } + s.Thumbnails = append(s.Thumbnails, elem) + } + } + } +} + // SetFake set fake values. func (s *CompactVideoRenderer) SetFake() { { { - s.VideoId.SetFake() + s.VideoId = "string" } } { @@ -210,7 +399,7 @@ func (s *CompactVideoRenderer) SetFake() { } { { - s.TrackingParams.SetFake() + s.TrackingParams = "string" } } { @@ -266,7 +455,7 @@ func (s *CompactVideoRendererThumbnail) SetFake() { func (s *Error) SetFake() { { { - s.Message.SetFake() + s.Message = "string" } } { @@ -294,12 +483,12 @@ func (s *ErrorResponsePayload) SetFake() { func (s *ErrorResponsePayloadError) SetFake() { { { - s.Code.SetFake() + s.Code = int(0) } } { { - s.Message.SetFake() + s.Message = "string" } } { @@ -316,7 +505,7 @@ func (s *ErrorResponsePayloadError) SetFake() { } { { - s.Status.SetFake() + s.Status = "string" } } } @@ -337,13 +526,23 @@ func (s *ItemSectionRenderer) SetFake() { } { { - s.TrackingParams.SetFake() + s.TrackingParams = "string" } } } // SetFake set fake values. func (s *ItemSectionRendererContentsItem) SetFake() { + { + { + s.CompactPlaylistRenderer.SetFake() + } + } + { + { + s.CompactChannelRenderer.SetFake() + } + } { { s.CompactVideoRenderer.SetFake() @@ -355,12 +554,12 @@ func (s *ItemSectionRendererContentsItem) SetFake() { func (s *KeyStringValue) SetFake() { { { - s.Key.SetFake() + s.Key = "string" } } { { - s.Value.SetFake() + s.Value = "string" } } } @@ -395,6 +594,16 @@ func (s *KidsAppContentSettings) SetFake() { } } +// SetFake set fake values. +func (s *KidsAppContentSettingsCorpusPreference) SetFake() { + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN +} + +// SetFake set fake values. +func (s *KidsAppContentSettingsKidsNoSearchMode) SetFake() { + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN +} + // SetFake set fake values. func (s *KidsAppInfo) SetFake() { { @@ -413,7 +622,7 @@ func (s *KidsAppInfo) SetFake() { func (s *KidsVideoOwnerExtension) SetFake() { { { - s.ExternalChannelId.SetFake() + s.ExternalChannelId = "string" } } } @@ -482,24 +691,6 @@ func (s *OptBrowseEndpoint) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptBrowseResponsePayloadContents) SetFake() { - var elem BrowseResponsePayloadContents - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptBrowseResponsePayloadHeader) SetFake() { - var elem BrowseResponsePayloadHeader - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptCategoriesHeaderRenderer) SetFake() { var elem CategoriesHeaderRenderer @@ -518,6 +709,51 @@ func (s *OptCategoryAssets) SetFake() { s.SetTo(elem) } +// SetFake set fake values. +func (s *OptCompactChannelRenderer) SetFake() { + var elem CompactChannelRenderer + { + elem.SetFake() + } + s.SetTo(elem) +} + +// SetFake set fake values. +func (s *OptCompactChannelRendererThumbnail) SetFake() { + var elem CompactChannelRendererThumbnail + { + elem.SetFake() + } + s.SetTo(elem) +} + +// SetFake set fake values. +func (s *OptCompactPlaylistRenderer) SetFake() { + var elem CompactPlaylistRenderer + { + elem.SetFake() + } + s.SetTo(elem) +} + +// SetFake set fake values. +func (s *OptCompactPlaylistRendererThumbnail) SetFake() { + var elem CompactPlaylistRendererThumbnail + { + elem.SetFake() + } + s.SetTo(elem) +} + +// SetFake set fake values. +func (s *OptCompactPlaylistRendererTvBanner) SetFake() { + var elem CompactPlaylistRendererTvBanner + { + elem.SetFake() + } + s.SetTo(elem) +} + // SetFake set fake values. func (s *OptCompactVideoRenderer) SetFake() { var elem CompactVideoRenderer @@ -546,19 +782,10 @@ func (s *OptCompactVideoRendererThumbnail) SetFake() { } // SetFake set fake values. -func (s *OptErrorResponsePayloadError) SetFake() { - var elem ErrorResponsePayloadError +func (s *OptInt) SetFake() { + var elem int { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptFloat64) SetFake() { - var elem float64 - { - elem = float64(0) + elem = int(0) } s.SetTo(elem) } @@ -590,24 +817,6 @@ func (s *OptKidsAppContentSettings) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptKidsAppInfo) SetFake() { - var elem KidsAppInfo - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptKidsVideoOwnerExtension) SetFake() { - var elem KidsVideoOwnerExtension - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptNavigationEndpoint) SetFake() { var elem NavigationEndpoint @@ -617,33 +826,6 @@ func (s *OptNavigationEndpoint) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptRequestClient) SetFake() { - var elem RequestClient - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptRequestContext) SetFake() { - var elem RequestContext - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptResponseContext) SetFake() { - var elem ResponseContext - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptScreenRenderer) SetFake() { var elem ScreenRenderer @@ -889,7 +1071,7 @@ func (s *Text) SetFake() { func (s *TextRun) SetFake() { { { - s.Text.SetFake() + s.Text = "string" } } { @@ -903,17 +1085,17 @@ func (s *TextRun) SetFake() { func (s *Thumbnail) SetFake() { { { - s.URL.SetFake() + s.URL = "string" } } { { - s.Width.SetFake() + s.Width = int(0) } } { { - s.Height.SetFake() + s.Height = int(0) } } } diff --git a/oas_interfaces_gen.go b/oas_interfaces_gen.go deleted file mode 100644 index 99199df..0000000 --- a/oas_interfaces_gen.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. -package go_youtubekids_client - -type BrowseRes interface { - browseRes() -} diff --git a/oas_json_gen.go b/oas_json_gen.go index 06a5ea1..503978e 100644 --- a/oas_json_gen.go +++ b/oas_json_gen.go @@ -3,8 +3,13 @@ package go_youtubekids_client import ( + "math/bits" + "strconv" + "github.com/go-faster/errors" "github.com/go-faster/jx" + + "github.com/ogen-go/ogen/validate" ) // Encode implements json.Marshaler. @@ -434,22 +439,27 @@ func (s *BrowseRequestPayload) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *BrowseRequestPayload) encodeFields(e *jx.Encoder) { { - if s.Context.Set { - e.FieldStart("context") - s.Context.Encode(e) + + e.FieldStart("context") + s.Context.Encode(e) + } + { + if s.Params.Set { + e.FieldStart("params") + s.Params.Encode(e) } } { - if s.BrowseId.Set { - e.FieldStart("browseId") - s.BrowseId.Encode(e) - } + + e.FieldStart("browseId") + e.Str(s.BrowseId) } } -var jsonFieldsNameOfBrowseRequestPayload = [2]string{ +var jsonFieldsNameOfBrowseRequestPayload = [3]string{ 0: "context", - 1: "browseId", + 1: "params", + 2: "browseId", } // Decode decodes BrowseRequestPayload from json. @@ -457,12 +467,13 @@ func (s *BrowseRequestPayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseRequestPayload to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "context": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Context.Reset() if err := s.Context.Decode(d); err != nil { return err } @@ -470,10 +481,22 @@ func (s *BrowseRequestPayload) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"context\"") } - case "browseId": + case "params": if err := func() error { - s.BrowseId.Reset() - if err := s.BrowseId.Decode(d); err != nil { + s.Params.Reset() + if err := s.Params.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"params\"") + } + case "browseId": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := d.Str() + s.BrowseId = string(v) + if err != nil { return err } return nil @@ -487,6 +510,38 @@ func (s *BrowseRequestPayload) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode BrowseRequestPayload") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000101, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfBrowseRequestPayload) { + name = jsonFieldsNameOfBrowseRequestPayload[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -514,22 +569,19 @@ func (s *BrowseResponsePayload) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *BrowseResponsePayload) encodeFields(e *jx.Encoder) { { - if s.ResponseContext.Set { - e.FieldStart("responseContext") - s.ResponseContext.Encode(e) - } + + e.FieldStart("responseContext") + s.ResponseContext.Encode(e) } { - if s.Header.Set { - e.FieldStart("header") - s.Header.Encode(e) - } + + e.FieldStart("header") + s.Header.Encode(e) } { - if s.Contents.Set { - e.FieldStart("contents") - s.Contents.Encode(e) - } + + e.FieldStart("contents") + s.Contents.Encode(e) } { if s.TrackingParams.Set { @@ -551,12 +603,13 @@ func (s *BrowseResponsePayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseResponsePayload to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "responseContext": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.ResponseContext.Reset() if err := s.ResponseContext.Decode(d); err != nil { return err } @@ -565,8 +618,8 @@ func (s *BrowseResponsePayload) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"responseContext\"") } case "header": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.Header.Reset() if err := s.Header.Decode(d); err != nil { return err } @@ -575,8 +628,8 @@ func (s *BrowseResponsePayload) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"header\"") } case "contents": + requiredBitSet[0] |= 1 << 2 if err := func() error { - s.Contents.Reset() if err := s.Contents.Decode(d); err != nil { return err } @@ -601,6 +654,38 @@ func (s *BrowseResponsePayload) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode BrowseResponsePayload") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfBrowseResponsePayload) { + name = jsonFieldsNameOfBrowseResponsePayload[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -817,10 +902,9 @@ func (s *CategoryAssets) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *CategoryAssets) encodeFields(e *jx.Encoder) { { - if s.AssetKey.Set { - e.FieldStart("assetKey") - s.AssetKey.Encode(e) - } + + e.FieldStart("assetKey") + e.Str(s.AssetKey) } { if s.BackgroundColor.Set { @@ -840,13 +924,16 @@ func (s *CategoryAssets) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CategoryAssets to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "assetKey": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.AssetKey.Reset() - if err := s.AssetKey.Decode(d); err != nil { + v, err := d.Str() + s.AssetKey = string(v) + if err != nil { return err } return nil @@ -870,6 +957,38 @@ func (s *CategoryAssets) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode CategoryAssets") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCategoryAssets) { + name = jsonFieldsNameOfCategoryAssets[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -887,6 +1006,829 @@ func (s *CategoryAssets) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *CompactChannelRenderer) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactChannelRenderer) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("channelId") + e.Str(s.ChannelId) + } + { + if s.Thumbnail.Set { + e.FieldStart("thumbnail") + s.Thumbnail.Encode(e) + } + } + { + + e.FieldStart("displayName") + s.DisplayName.Encode(e) + } + { + + e.FieldStart("videoCountText") + s.VideoCountText.Encode(e) + } + { + if s.SubscriberCountText.Set { + e.FieldStart("subscriberCountText") + s.SubscriberCountText.Encode(e) + } + } + { + if s.NavigationEndpoint.Set { + e.FieldStart("navigationEndpoint") + s.NavigationEndpoint.Encode(e) + } + } + { + + e.FieldStart("title") + s.Title.Encode(e) + } + { + + e.FieldStart("trackingParams") + e.Str(s.TrackingParams) + } +} + +var jsonFieldsNameOfCompactChannelRenderer = [8]string{ + 0: "channelId", + 1: "thumbnail", + 2: "displayName", + 3: "videoCountText", + 4: "subscriberCountText", + 5: "navigationEndpoint", + 6: "title", + 7: "trackingParams", +} + +// Decode decodes CompactChannelRenderer from json. +func (s *CompactChannelRenderer) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactChannelRenderer to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "channelId": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Str() + s.ChannelId = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"channelId\"") + } + case "thumbnail": + if err := func() error { + s.Thumbnail.Reset() + if err := s.Thumbnail.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnail\"") + } + case "displayName": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.DisplayName.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"displayName\"") + } + case "videoCountText": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.VideoCountText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"videoCountText\"") + } + case "subscriberCountText": + if err := func() error { + s.SubscriberCountText.Reset() + if err := s.SubscriberCountText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"subscriberCountText\"") + } + case "navigationEndpoint": + if err := func() error { + s.NavigationEndpoint.Reset() + if err := s.NavigationEndpoint.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"navigationEndpoint\"") + } + case "title": + requiredBitSet[0] |= 1 << 6 + if err := func() error { + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "trackingParams": + requiredBitSet[0] |= 1 << 7 + if err := func() error { + v, err := d.Str() + s.TrackingParams = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"trackingParams\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactChannelRenderer") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b11001101, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCompactChannelRenderer) { + name = jsonFieldsNameOfCompactChannelRenderer[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactChannelRenderer) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactChannelRenderer) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CompactChannelRendererThumbnail) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactChannelRendererThumbnail) encodeFields(e *jx.Encoder) { + { + if s.Thumbnails != nil { + e.FieldStart("thumbnails") + e.ArrStart() + for _, elem := range s.Thumbnails { + elem.Encode(e) + } + e.ArrEnd() + } + } +} + +var jsonFieldsNameOfCompactChannelRendererThumbnail = [1]string{ + 0: "thumbnails", +} + +// Decode decodes CompactChannelRendererThumbnail from json. +func (s *CompactChannelRendererThumbnail) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactChannelRendererThumbnail to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "thumbnails": + if err := func() error { + s.Thumbnails = make([]Thumbnail, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Thumbnail + if err := elem.Decode(d); err != nil { + return err + } + s.Thumbnails = append(s.Thumbnails, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnails\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactChannelRendererThumbnail") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactChannelRendererThumbnail) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactChannelRendererThumbnail) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CompactPlaylistRenderer) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactPlaylistRenderer) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("playlistId") + e.Str(s.PlaylistId) + } + { + if s.Thumbnail.Set { + e.FieldStart("thumbnail") + s.Thumbnail.Encode(e) + } + } + { + + e.FieldStart("title") + s.Title.Encode(e) + } + { + if s.ShortBylineText.Set { + e.FieldStart("shortBylineText") + s.ShortBylineText.Encode(e) + } + } + { + if s.VideoCountText.Set { + e.FieldStart("videoCountText") + s.VideoCountText.Encode(e) + } + } + { + if s.NavigationEndpoint.Set { + e.FieldStart("navigationEndpoint") + s.NavigationEndpoint.Encode(e) + } + } + { + if s.VideoCountShortText.Set { + e.FieldStart("videoCountShortText") + s.VideoCountShortText.Encode(e) + } + } + { + + e.FieldStart("trackingParams") + e.Str(s.TrackingParams) + } + { + if s.SidebarThumbnails != nil { + e.FieldStart("sidebarThumbnails") + e.ArrStart() + for _, elem := range s.SidebarThumbnails { + elem.Encode(e) + } + e.ArrEnd() + } + } + { + if s.ThumbnailText.Set { + e.FieldStart("thumbnailText") + s.ThumbnailText.Encode(e) + } + } + { + if s.ShareUrl.Set { + e.FieldStart("shareUrl") + s.ShareUrl.Encode(e) + } + } + { + if s.LongBylineText.Set { + e.FieldStart("longBylineText") + s.LongBylineText.Encode(e) + } + } + { + if s.TvBanner.Set { + e.FieldStart("tvBanner") + s.TvBanner.Encode(e) + } + } +} + +var jsonFieldsNameOfCompactPlaylistRenderer = [13]string{ + 0: "playlistId", + 1: "thumbnail", + 2: "title", + 3: "shortBylineText", + 4: "videoCountText", + 5: "navigationEndpoint", + 6: "videoCountShortText", + 7: "trackingParams", + 8: "sidebarThumbnails", + 9: "thumbnailText", + 10: "shareUrl", + 11: "longBylineText", + 12: "tvBanner", +} + +// Decode decodes CompactPlaylistRenderer from json. +func (s *CompactPlaylistRenderer) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactPlaylistRenderer to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "playlistId": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Str() + s.PlaylistId = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"playlistId\"") + } + case "thumbnail": + if err := func() error { + s.Thumbnail.Reset() + if err := s.Thumbnail.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnail\"") + } + case "title": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "shortBylineText": + if err := func() error { + s.ShortBylineText.Reset() + if err := s.ShortBylineText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"shortBylineText\"") + } + case "videoCountText": + if err := func() error { + s.VideoCountText.Reset() + if err := s.VideoCountText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"videoCountText\"") + } + case "navigationEndpoint": + if err := func() error { + s.NavigationEndpoint.Reset() + if err := s.NavigationEndpoint.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"navigationEndpoint\"") + } + case "videoCountShortText": + if err := func() error { + s.VideoCountShortText.Reset() + if err := s.VideoCountShortText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"videoCountShortText\"") + } + case "trackingParams": + requiredBitSet[0] |= 1 << 7 + if err := func() error { + v, err := d.Str() + s.TrackingParams = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"trackingParams\"") + } + case "sidebarThumbnails": + if err := func() error { + s.SidebarThumbnails = make([]CompactPlaylistRendererSidebarThumbnailsItem, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem CompactPlaylistRendererSidebarThumbnailsItem + if err := elem.Decode(d); err != nil { + return err + } + s.SidebarThumbnails = append(s.SidebarThumbnails, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"sidebarThumbnails\"") + } + case "thumbnailText": + if err := func() error { + s.ThumbnailText.Reset() + if err := s.ThumbnailText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnailText\"") + } + case "shareUrl": + if err := func() error { + s.ShareUrl.Reset() + if err := s.ShareUrl.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"shareUrl\"") + } + case "longBylineText": + if err := func() error { + s.LongBylineText.Reset() + if err := s.LongBylineText.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"longBylineText\"") + } + case "tvBanner": + if err := func() error { + s.TvBanner.Reset() + if err := s.TvBanner.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"tvBanner\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactPlaylistRenderer") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b10000101, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCompactPlaylistRenderer) { + name = jsonFieldsNameOfCompactPlaylistRenderer[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactPlaylistRenderer) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactPlaylistRenderer) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) encodeFields(e *jx.Encoder) { + { + if s.Thumbnails != nil { + e.FieldStart("thumbnails") + e.ArrStart() + for _, elem := range s.Thumbnails { + elem.Encode(e) + } + e.ArrEnd() + } + } +} + +var jsonFieldsNameOfCompactPlaylistRendererSidebarThumbnailsItem = [1]string{ + 0: "thumbnails", +} + +// Decode decodes CompactPlaylistRendererSidebarThumbnailsItem from json. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactPlaylistRendererSidebarThumbnailsItem to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "thumbnails": + if err := func() error { + s.Thumbnails = make([]Thumbnail, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Thumbnail + if err := elem.Decode(d); err != nil { + return err + } + s.Thumbnails = append(s.Thumbnails, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnails\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactPlaylistRendererSidebarThumbnailsItem") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CompactPlaylistRendererThumbnail) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactPlaylistRendererThumbnail) encodeFields(e *jx.Encoder) { + { + if s.Thumbnails != nil { + e.FieldStart("thumbnails") + e.ArrStart() + for _, elem := range s.Thumbnails { + elem.Encode(e) + } + e.ArrEnd() + } + } +} + +var jsonFieldsNameOfCompactPlaylistRendererThumbnail = [1]string{ + 0: "thumbnails", +} + +// Decode decodes CompactPlaylistRendererThumbnail from json. +func (s *CompactPlaylistRendererThumbnail) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactPlaylistRendererThumbnail to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "thumbnails": + if err := func() error { + s.Thumbnails = make([]Thumbnail, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Thumbnail + if err := elem.Decode(d); err != nil { + return err + } + s.Thumbnails = append(s.Thumbnails, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnails\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactPlaylistRendererThumbnail") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactPlaylistRendererThumbnail) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactPlaylistRendererThumbnail) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CompactPlaylistRendererTvBanner) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CompactPlaylistRendererTvBanner) encodeFields(e *jx.Encoder) { + { + if s.Thumbnails != nil { + e.FieldStart("thumbnails") + e.ArrStart() + for _, elem := range s.Thumbnails { + elem.Encode(e) + } + e.ArrEnd() + } + } +} + +var jsonFieldsNameOfCompactPlaylistRendererTvBanner = [1]string{ + 0: "thumbnails", +} + +// Decode decodes CompactPlaylistRendererTvBanner from json. +func (s *CompactPlaylistRendererTvBanner) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactPlaylistRendererTvBanner to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "thumbnails": + if err := func() error { + s.Thumbnails = make([]Thumbnail, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Thumbnail + if err := elem.Decode(d); err != nil { + return err + } + s.Thumbnails = append(s.Thumbnails, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"thumbnails\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CompactPlaylistRendererTvBanner") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CompactPlaylistRendererTvBanner) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactPlaylistRendererTvBanner) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *CompactVideoRenderer) Encode(e *jx.Encoder) { e.ObjStart() @@ -897,10 +1839,9 @@ func (s *CompactVideoRenderer) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { { - if s.VideoId.Set { - e.FieldStart("videoId") - s.VideoId.Encode(e) - } + + e.FieldStart("videoId") + e.Str(s.VideoId) } { if s.Thumbnail.Set { @@ -909,10 +1850,9 @@ func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { } } { - if s.Title.Set { - e.FieldStart("title") - s.Title.Encode(e) - } + + e.FieldStart("title") + s.Title.Encode(e) } { if s.LongBylineText.Set { @@ -927,10 +1867,9 @@ func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { } } { - if s.ViewCountText.Set { - e.FieldStart("viewCountText") - s.ViewCountText.Encode(e) - } + + e.FieldStart("viewCountText") + s.ViewCountText.Encode(e) } { if s.LengthText.Set { @@ -957,10 +1896,9 @@ func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { } } { - if s.TrackingParams.Set { - e.FieldStart("trackingParams") - s.TrackingParams.Encode(e) - } + + e.FieldStart("trackingParams") + e.Str(s.TrackingParams) } { if s.ShortViewCountText.Set { @@ -975,10 +1913,9 @@ func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { } } { - if s.KidsVideoOwnerExtension.Set { - e.FieldStart("kidsVideoOwnerExtension") - s.KidsVideoOwnerExtension.Encode(e) - } + + e.FieldStart("kidsVideoOwnerExtension") + s.KidsVideoOwnerExtension.Encode(e) } } @@ -1004,13 +1941,16 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactVideoRenderer to nil") } + var requiredBitSet [2]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "videoId": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.VideoId.Reset() - if err := s.VideoId.Decode(d); err != nil { + v, err := d.Str() + s.VideoId = string(v) + if err != nil { return err } return nil @@ -1028,8 +1968,8 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"thumbnail\"") } case "title": + requiredBitSet[0] |= 1 << 2 if err := func() error { - s.Title.Reset() if err := s.Title.Decode(d); err != nil { return err } @@ -1058,8 +1998,8 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"publishedTimeText\"") } case "viewCountText": + requiredBitSet[0] |= 1 << 5 if err := func() error { - s.ViewCountText.Reset() if err := s.ViewCountText.Decode(d); err != nil { return err } @@ -1108,9 +2048,11 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"channelThumbnail\"") } case "trackingParams": + requiredBitSet[1] |= 1 << 2 if err := func() error { - s.TrackingParams.Reset() - if err := s.TrackingParams.Decode(d); err != nil { + v, err := d.Str() + s.TrackingParams = string(v) + if err != nil { return err } return nil @@ -1138,8 +2080,8 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"accessibility\"") } case "kidsVideoOwnerExtension": + requiredBitSet[1] |= 1 << 5 if err := func() error { - s.KidsVideoOwnerExtension.Reset() if err := s.KidsVideoOwnerExtension.Decode(d); err != nil { return err } @@ -1154,6 +2096,39 @@ func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode CompactVideoRenderer") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00100101, + 0b00100100, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCompactVideoRenderer) { + name = jsonFieldsNameOfCompactVideoRenderer[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1329,10 +2304,9 @@ func (s *Error) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *Error) encodeFields(e *jx.Encoder) { { - if s.Message.Set { - e.FieldStart("message") - s.Message.Encode(e) - } + + e.FieldStart("message") + e.Str(s.Message) } { if s.Domain.Set { @@ -1359,13 +2333,16 @@ func (s *Error) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Error to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "message": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Message.Reset() - if err := s.Message.Decode(d); err != nil { + v, err := d.Str() + s.Message = string(v) + if err != nil { return err } return nil @@ -1399,6 +2376,38 @@ func (s *Error) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode Error") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfError) { + name = jsonFieldsNameOfError[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1426,10 +2435,9 @@ func (s *ErrorResponsePayload) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *ErrorResponsePayload) encodeFields(e *jx.Encoder) { { - if s.Error.Set { - e.FieldStart("error") - s.Error.Encode(e) - } + + e.FieldStart("error") + s.Error.Encode(e) } } @@ -1442,12 +2450,13 @@ func (s *ErrorResponsePayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ErrorResponsePayload to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "error": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Error.Reset() if err := s.Error.Decode(d); err != nil { return err } @@ -1462,6 +2471,38 @@ func (s *ErrorResponsePayload) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode ErrorResponsePayload") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfErrorResponsePayload) { + name = jsonFieldsNameOfErrorResponsePayload[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1489,16 +2530,14 @@ func (s *ErrorResponsePayloadError) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *ErrorResponsePayloadError) encodeFields(e *jx.Encoder) { { - if s.Code.Set { - e.FieldStart("code") - s.Code.Encode(e) - } + + e.FieldStart("code") + e.Int(s.Code) } { - if s.Message.Set { - e.FieldStart("message") - s.Message.Encode(e) - } + + e.FieldStart("message") + e.Str(s.Message) } { if s.Errors != nil { @@ -1511,10 +2550,9 @@ func (s *ErrorResponsePayloadError) encodeFields(e *jx.Encoder) { } } { - if s.Status.Set { - e.FieldStart("status") - s.Status.Encode(e) - } + + e.FieldStart("status") + e.Str(s.Status) } } @@ -1530,13 +2568,16 @@ func (s *ErrorResponsePayloadError) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ErrorResponsePayloadError to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "code": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Code.Reset() - if err := s.Code.Decode(d); err != nil { + v, err := d.Int() + s.Code = int(v) + if err != nil { return err } return nil @@ -1544,9 +2585,11 @@ func (s *ErrorResponsePayloadError) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"code\"") } case "message": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.Message.Reset() - if err := s.Message.Decode(d); err != nil { + v, err := d.Str() + s.Message = string(v) + if err != nil { return err } return nil @@ -1571,9 +2614,11 @@ func (s *ErrorResponsePayloadError) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"errors\"") } case "status": + requiredBitSet[0] |= 1 << 3 if err := func() error { - s.Status.Reset() - if err := s.Status.Decode(d); err != nil { + v, err := d.Str() + s.Status = string(v) + if err != nil { return err } return nil @@ -1587,6 +2632,38 @@ func (s *ErrorResponsePayloadError) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode ErrorResponsePayloadError") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00001011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfErrorResponsePayloadError) { + name = jsonFieldsNameOfErrorResponsePayloadError[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1614,20 +2691,18 @@ func (s *ItemSectionRenderer) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *ItemSectionRenderer) encodeFields(e *jx.Encoder) { { - if s.Contents != nil { - e.FieldStart("contents") - e.ArrStart() - for _, elem := range s.Contents { - elem.Encode(e) - } - e.ArrEnd() + + e.FieldStart("contents") + e.ArrStart() + for _, elem := range s.Contents { + elem.Encode(e) } + e.ArrEnd() } { - if s.TrackingParams.Set { - e.FieldStart("trackingParams") - s.TrackingParams.Encode(e) - } + + e.FieldStart("trackingParams") + e.Str(s.TrackingParams) } } @@ -1641,10 +2716,12 @@ func (s *ItemSectionRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ItemSectionRenderer to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "contents": + requiredBitSet[0] |= 1 << 0 if err := func() error { s.Contents = make([]ItemSectionRendererContentsItem, 0) if err := d.Arr(func(d *jx.Decoder) error { @@ -1662,9 +2739,11 @@ func (s *ItemSectionRenderer) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"contents\"") } case "trackingParams": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.TrackingParams.Reset() - if err := s.TrackingParams.Decode(d); err != nil { + v, err := d.Str() + s.TrackingParams = string(v) + if err != nil { return err } return nil @@ -1678,6 +2757,38 @@ func (s *ItemSectionRenderer) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode ItemSectionRenderer") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfItemSectionRenderer) { + name = jsonFieldsNameOfItemSectionRenderer[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1704,6 +2815,18 @@ func (s *ItemSectionRendererContentsItem) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *ItemSectionRendererContentsItem) encodeFields(e *jx.Encoder) { + { + if s.CompactPlaylistRenderer.Set { + e.FieldStart("compactPlaylistRenderer") + s.CompactPlaylistRenderer.Encode(e) + } + } + { + if s.CompactChannelRenderer.Set { + e.FieldStart("compactChannelRenderer") + s.CompactChannelRenderer.Encode(e) + } + } { if s.CompactVideoRenderer.Set { e.FieldStart("compactVideoRenderer") @@ -1712,8 +2835,10 @@ func (s *ItemSectionRendererContentsItem) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfItemSectionRendererContentsItem = [1]string{ - 0: "compactVideoRenderer", +var jsonFieldsNameOfItemSectionRendererContentsItem = [3]string{ + 0: "compactPlaylistRenderer", + 1: "compactChannelRenderer", + 2: "compactVideoRenderer", } // Decode decodes ItemSectionRendererContentsItem from json. @@ -1724,6 +2849,26 @@ func (s *ItemSectionRendererContentsItem) Decode(d *jx.Decoder) error { if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { + case "compactPlaylistRenderer": + if err := func() error { + s.CompactPlaylistRenderer.Reset() + if err := s.CompactPlaylistRenderer.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"compactPlaylistRenderer\"") + } + case "compactChannelRenderer": + if err := func() error { + s.CompactChannelRenderer.Reset() + if err := s.CompactChannelRenderer.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"compactChannelRenderer\"") + } case "compactVideoRenderer": if err := func() error { s.CompactVideoRenderer.Reset() @@ -1768,16 +2913,14 @@ func (s *KeyStringValue) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *KeyStringValue) encodeFields(e *jx.Encoder) { { - if s.Key.Set { - e.FieldStart("key") - s.Key.Encode(e) - } + + e.FieldStart("key") + e.Str(s.Key) } { - if s.Value.Set { - e.FieldStart("value") - s.Value.Encode(e) - } + + e.FieldStart("value") + e.Str(s.Value) } } @@ -1791,13 +2934,16 @@ func (s *KeyStringValue) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KeyStringValue to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "key": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Key.Reset() - if err := s.Key.Decode(d); err != nil { + v, err := d.Str() + s.Key = string(v) + if err != nil { return err } return nil @@ -1805,9 +2951,11 @@ func (s *KeyStringValue) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"key\"") } case "value": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.Value.Reset() - if err := s.Value.Decode(d); err != nil { + v, err := d.Str() + s.Value = string(v) + if err != nil { return err } return nil @@ -1821,6 +2969,38 @@ func (s *KeyStringValue) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode KeyStringValue") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfKeyStringValue) { + name = jsonFieldsNameOfKeyStringValue[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1924,16 +3104,14 @@ func (s *KidsAppContentSettings) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *KidsAppContentSettings) encodeFields(e *jx.Encoder) { { - if s.CorpusPreference.Set { - e.FieldStart("corpusPreference") - s.CorpusPreference.Encode(e) - } + + e.FieldStart("corpusPreference") + s.CorpusPreference.Encode(e) } { - if s.KidsNoSearchMode.Set { - e.FieldStart("kidsNoSearchMode") - s.KidsNoSearchMode.Encode(e) - } + + e.FieldStart("kidsNoSearchMode") + s.KidsNoSearchMode.Encode(e) } } @@ -1947,12 +3125,14 @@ func (s *KidsAppContentSettings) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppContentSettings to nil") } + var requiredBitSet [1]uint8 + s.setDefaults() if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "corpusPreference": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.CorpusPreference.Reset() if err := s.CorpusPreference.Decode(d); err != nil { return err } @@ -1961,8 +3141,8 @@ func (s *KidsAppContentSettings) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"corpusPreference\"") } case "kidsNoSearchMode": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.KidsNoSearchMode.Reset() if err := s.KidsNoSearchMode.Decode(d); err != nil { return err } @@ -1977,6 +3157,38 @@ func (s *KidsAppContentSettings) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode KidsAppContentSettings") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfKidsAppContentSettings) { + name = jsonFieldsNameOfKidsAppContentSettings[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -1994,6 +3206,96 @@ func (s *KidsAppContentSettings) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes KidsAppContentSettingsCorpusPreference as json. +func (s KidsAppContentSettingsCorpusPreference) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes KidsAppContentSettingsCorpusPreference from json. +func (s *KidsAppContentSettingsCorpusPreference) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode KidsAppContentSettingsCorpusPreference to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch KidsAppContentSettingsCorpusPreference(v) { + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL + default: + *s = KidsAppContentSettingsCorpusPreference(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s KidsAppContentSettingsCorpusPreference) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *KidsAppContentSettingsCorpusPreference) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes KidsAppContentSettingsKidsNoSearchMode as json. +func (s KidsAppContentSettingsKidsNoSearchMode) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes KidsAppContentSettingsKidsNoSearchMode from json. +func (s *KidsAppContentSettingsKidsNoSearchMode) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode KidsAppContentSettingsKidsNoSearchMode to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch KidsAppContentSettingsKidsNoSearchMode(v) { + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF + default: + *s = KidsAppContentSettingsKidsNoSearchMode(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s KidsAppContentSettingsKidsNoSearchMode) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *KidsAppContentSettingsKidsNoSearchMode) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *KidsAppInfo) Encode(e *jx.Encoder) { e.ObjStart() @@ -2084,10 +3386,9 @@ func (s *KidsVideoOwnerExtension) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *KidsVideoOwnerExtension) encodeFields(e *jx.Encoder) { { - if s.ExternalChannelId.Set { - e.FieldStart("externalChannelId") - s.ExternalChannelId.Encode(e) - } + + e.FieldStart("externalChannelId") + e.Str(s.ExternalChannelId) } } @@ -2100,13 +3401,16 @@ func (s *KidsVideoOwnerExtension) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsVideoOwnerExtension to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "externalChannelId": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.ExternalChannelId.Reset() - if err := s.ExternalChannelId.Decode(d); err != nil { + v, err := d.Str() + s.ExternalChannelId = string(v) + if err != nil { return err } return nil @@ -2120,6 +3424,38 @@ func (s *KidsVideoOwnerExtension) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode KidsVideoOwnerExtension") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfKidsVideoOwnerExtension) { + name = jsonFieldsNameOfKidsVideoOwnerExtension[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -2399,72 +3735,6 @@ func (s *OptBrowseEndpoint) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes BrowseResponsePayloadContents as json. -func (o OptBrowseResponsePayloadContents) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes BrowseResponsePayloadContents from json. -func (o *OptBrowseResponsePayloadContents) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptBrowseResponsePayloadContents to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptBrowseResponsePayloadContents) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptBrowseResponsePayloadContents) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes BrowseResponsePayloadHeader as json. -func (o OptBrowseResponsePayloadHeader) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes BrowseResponsePayloadHeader from json. -func (o *OptBrowseResponsePayloadHeader) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptBrowseResponsePayloadHeader to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptBrowseResponsePayloadHeader) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptBrowseResponsePayloadHeader) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes CategoriesHeaderRenderer as json. func (o OptCategoriesHeaderRenderer) Encode(e *jx.Encoder) { if !o.Set { @@ -2531,6 +3801,171 @@ func (s *OptCategoryAssets) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes CompactChannelRenderer as json. +func (o OptCompactChannelRenderer) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes CompactChannelRenderer from json. +func (o *OptCompactChannelRenderer) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCompactChannelRenderer to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCompactChannelRenderer) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCompactChannelRenderer) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes CompactChannelRendererThumbnail as json. +func (o OptCompactChannelRendererThumbnail) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes CompactChannelRendererThumbnail from json. +func (o *OptCompactChannelRendererThumbnail) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCompactChannelRendererThumbnail to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCompactChannelRendererThumbnail) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCompactChannelRendererThumbnail) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes CompactPlaylistRenderer as json. +func (o OptCompactPlaylistRenderer) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes CompactPlaylistRenderer from json. +func (o *OptCompactPlaylistRenderer) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCompactPlaylistRenderer to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCompactPlaylistRenderer) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCompactPlaylistRenderer) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes CompactPlaylistRendererThumbnail as json. +func (o OptCompactPlaylistRendererThumbnail) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes CompactPlaylistRendererThumbnail from json. +func (o *OptCompactPlaylistRendererThumbnail) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCompactPlaylistRendererThumbnail to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCompactPlaylistRendererThumbnail) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCompactPlaylistRendererThumbnail) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes CompactPlaylistRendererTvBanner as json. +func (o OptCompactPlaylistRendererTvBanner) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes CompactPlaylistRendererTvBanner from json. +func (o *OptCompactPlaylistRendererTvBanner) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptCompactPlaylistRendererTvBanner to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptCompactPlaylistRendererTvBanner) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptCompactPlaylistRendererTvBanner) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes CompactVideoRenderer as json. func (o OptCompactVideoRenderer) Encode(e *jx.Encoder) { if !o.Set { @@ -2630,70 +4065,37 @@ func (s *OptCompactVideoRendererThumbnail) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes ErrorResponsePayloadError as json. -func (o OptErrorResponsePayloadError) Encode(e *jx.Encoder) { +// Encode encodes int as json. +func (o OptInt) Encode(e *jx.Encoder) { if !o.Set { return } - o.Value.Encode(e) + e.Int(int(o.Value)) } -// Decode decodes ErrorResponsePayloadError from json. -func (o *OptErrorResponsePayloadError) Decode(d *jx.Decoder) error { +// Decode decodes int from json. +func (o *OptInt) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptErrorResponsePayloadError to nil") + return errors.New("invalid: unable to decode OptInt to nil") } o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptErrorResponsePayloadError) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptErrorResponsePayloadError) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes float64 as json. -func (o OptFloat64) Encode(e *jx.Encoder) { - if !o.Set { - return - } - e.Float64(float64(o.Value)) -} - -// Decode decodes float64 from json. -func (o *OptFloat64) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptFloat64 to nil") - } - o.Set = true - v, err := d.Float64() + v, err := d.Int() if err != nil { return err } - o.Value = float64(v) + o.Value = int(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptFloat64) MarshalJSON() ([]byte, error) { +func (s OptInt) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptFloat64) UnmarshalJSON(data []byte) error { +func (s *OptInt) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -2797,72 +4199,6 @@ func (s *OptKidsAppContentSettings) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes KidsAppInfo as json. -func (o OptKidsAppInfo) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes KidsAppInfo from json. -func (o *OptKidsAppInfo) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptKidsAppInfo to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptKidsAppInfo) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptKidsAppInfo) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes KidsVideoOwnerExtension as json. -func (o OptKidsVideoOwnerExtension) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes KidsVideoOwnerExtension from json. -func (o *OptKidsVideoOwnerExtension) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptKidsVideoOwnerExtension to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptKidsVideoOwnerExtension) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptKidsVideoOwnerExtension) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes NavigationEndpoint as json. func (o OptNavigationEndpoint) Encode(e *jx.Encoder) { if !o.Set { @@ -2896,105 +4232,6 @@ func (s *OptNavigationEndpoint) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes RequestClient as json. -func (o OptRequestClient) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes RequestClient from json. -func (o *OptRequestClient) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptRequestClient to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptRequestClient) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptRequestClient) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes RequestContext as json. -func (o OptRequestContext) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes RequestContext from json. -func (o *OptRequestContext) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptRequestContext to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptRequestContext) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptRequestContext) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ResponseContext as json. -func (o OptResponseContext) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes ResponseContext from json. -func (o *OptResponseContext) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptResponseContext to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptResponseContext) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptResponseContext) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes ScreenRenderer as json. func (o OptScreenRenderer) Encode(e *jx.Encoder) { if !o.Set { @@ -3238,10 +4475,9 @@ func (s *RequestClient) encodeFields(e *jx.Encoder) { } } { - if s.KidsAppInfo.Set { - e.FieldStart("kidsAppInfo") - s.KidsAppInfo.Encode(e) - } + + e.FieldStart("kidsAppInfo") + s.KidsAppInfo.Encode(e) } } @@ -3265,6 +4501,8 @@ func (s *RequestClient) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode RequestClient to nil") } + var requiredBitSet [2]uint8 + s.setDefaults() if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { @@ -3379,8 +4617,8 @@ func (s *RequestClient) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"platform\"") } case "kidsAppInfo": + requiredBitSet[1] |= 1 << 3 if err := func() error { - s.KidsAppInfo.Reset() if err := s.KidsAppInfo.Decode(d); err != nil { return err } @@ -3395,6 +4633,39 @@ func (s *RequestClient) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode RequestClient") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000000, + 0b00001000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfRequestClient) { + name = jsonFieldsNameOfRequestClient[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -3422,10 +4693,9 @@ func (s *RequestContext) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *RequestContext) encodeFields(e *jx.Encoder) { { - if s.Client.Set { - e.FieldStart("client") - s.Client.Encode(e) - } + + e.FieldStart("client") + s.Client.Encode(e) } } @@ -3438,12 +4708,13 @@ func (s *RequestContext) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode RequestContext to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "client": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Client.Reset() if err := s.Client.Decode(d); err != nil { return err } @@ -3458,6 +4729,38 @@ func (s *RequestContext) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode RequestContext") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfRequestContext) { + name = jsonFieldsNameOfRequestContext[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -3975,14 +5278,13 @@ func (s *Text) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *Text) encodeFields(e *jx.Encoder) { { - if s.Runs != nil { - e.FieldStart("runs") - e.ArrStart() - for _, elem := range s.Runs { - elem.Encode(e) - } - e.ArrEnd() + + e.FieldStart("runs") + e.ArrStart() + for _, elem := range s.Runs { + elem.Encode(e) } + e.ArrEnd() } { if s.Accessibility.Set { @@ -4002,10 +5304,12 @@ func (s *Text) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Text to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "runs": + requiredBitSet[0] |= 1 << 0 if err := func() error { s.Runs = make([]TextRun, 0) if err := d.Arr(func(d *jx.Decoder) error { @@ -4039,6 +5343,38 @@ func (s *Text) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode Text") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfText) { + name = jsonFieldsNameOfText[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -4066,10 +5402,9 @@ func (s *TextRun) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *TextRun) encodeFields(e *jx.Encoder) { { - if s.Text.Set { - e.FieldStart("text") - s.Text.Encode(e) - } + + e.FieldStart("text") + e.Str(s.Text) } { if s.NavigationEndpoint.Set { @@ -4089,13 +5424,16 @@ func (s *TextRun) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode TextRun to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "text": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.Text.Reset() - if err := s.Text.Decode(d); err != nil { + v, err := d.Str() + s.Text = string(v) + if err != nil { return err } return nil @@ -4119,6 +5457,38 @@ func (s *TextRun) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode TextRun") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfTextRun) { + name = jsonFieldsNameOfTextRun[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } @@ -4146,22 +5516,19 @@ func (s *Thumbnail) Encode(e *jx.Encoder) { // encodeFields encodes fields. func (s *Thumbnail) encodeFields(e *jx.Encoder) { { - if s.URL.Set { - e.FieldStart("url") - s.URL.Encode(e) - } + + e.FieldStart("url") + e.Str(s.URL) } { - if s.Width.Set { - e.FieldStart("width") - s.Width.Encode(e) - } + + e.FieldStart("width") + e.Int(s.Width) } { - if s.Height.Set { - e.FieldStart("height") - s.Height.Encode(e) - } + + e.FieldStart("height") + e.Int(s.Height) } } @@ -4176,13 +5543,16 @@ func (s *Thumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Thumbnail to nil") } + var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "url": + requiredBitSet[0] |= 1 << 0 if err := func() error { - s.URL.Reset() - if err := s.URL.Decode(d); err != nil { + v, err := d.Str() + s.URL = string(v) + if err != nil { return err } return nil @@ -4190,9 +5560,11 @@ func (s *Thumbnail) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"url\"") } case "width": + requiredBitSet[0] |= 1 << 1 if err := func() error { - s.Width.Reset() - if err := s.Width.Decode(d); err != nil { + v, err := d.Int() + s.Width = int(v) + if err != nil { return err } return nil @@ -4200,9 +5572,11 @@ func (s *Thumbnail) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"width\"") } case "height": + requiredBitSet[0] |= 1 << 2 if err := func() error { - s.Height.Reset() - if err := s.Height.Decode(d); err != nil { + v, err := d.Int() + s.Height = int(v) + if err != nil { return err } return nil @@ -4216,6 +5590,38 @@ func (s *Thumbnail) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode Thumbnail") } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfThumbnail) { + name = jsonFieldsNameOfThumbnail[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil } diff --git a/oas_response_decoders_gen.go b/oas_response_decoders_gen.go index 4cf58d3..4f0f391 100644 --- a/oas_response_decoders_gen.go +++ b/oas_response_decoders_gen.go @@ -14,7 +14,7 @@ import ( "github.com/ogen-go/ogen/validate" ) -func decodeBrowseResponse(resp *http.Response) (res BrowseRes, err error) { +func decodeBrowseResponse(resp *http.Response) (res *BrowseResponsePayload, err error) { switch resp.StatusCode { case 200: // Code 200. @@ -51,8 +51,9 @@ func decodeBrowseResponse(resp *http.Response) (res BrowseRes, err error) { default: return res, validate.InvalidContentType(ct) } - case 400: - // Code 400. + } + // Convenient error response. + defRes, err := func() (res *ErrorResponsePayloadStatusCode, err error) { ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") @@ -82,10 +83,16 @@ func decodeBrowseResponse(resp *http.Response) (res BrowseRes, err error) { } return res, err } - return &response, nil + return &ErrorResponsePayloadStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil default: return res, validate.InvalidContentType(ct) } + }() + if err != nil { + return res, errors.Wrap(err, "default") } - return res, validate.UnexpectedStatusCode(resp.StatusCode) + return res, errors.Wrap(defRes, "error") } diff --git a/oas_schemas_gen.go b/oas_schemas_gen.go index 186c3d6..0551a28 100644 --- a/oas_schemas_gen.go +++ b/oas_schemas_gen.go @@ -2,6 +2,16 @@ package go_youtubekids_client +import ( + "fmt" + + "github.com/go-faster/errors" +) + +func (s *ErrorResponsePayloadStatusCode) Error() string { + return fmt.Sprintf("code %d: %+v", s.StatusCode, s.Response) +} + // Ref: #/components/schemas/Accessibility type Accessibility struct { AccessibilityData OptAccessibilityData `json:"accessibilityData"` @@ -144,50 +154,61 @@ func (s *BrowseEndpoint) SetCanonicalBaseUrl(val OptString) { // Ref: #/components/schemas/BrowseRequestPayload type BrowseRequestPayload struct { - Context OptRequestContext `json:"context"` - BrowseId OptString `json:"browseId"` + Context RequestContext `json:"context"` + Params OptString `json:"params"` + BrowseId string `json:"browseId"` } // GetContext returns the value of Context. -func (s *BrowseRequestPayload) GetContext() OptRequestContext { +func (s *BrowseRequestPayload) GetContext() RequestContext { return s.Context } +// GetParams returns the value of Params. +func (s *BrowseRequestPayload) GetParams() OptString { + return s.Params +} + // GetBrowseId returns the value of BrowseId. -func (s *BrowseRequestPayload) GetBrowseId() OptString { +func (s *BrowseRequestPayload) GetBrowseId() string { return s.BrowseId } // SetContext sets the value of Context. -func (s *BrowseRequestPayload) SetContext(val OptRequestContext) { +func (s *BrowseRequestPayload) SetContext(val RequestContext) { s.Context = val } +// SetParams sets the value of Params. +func (s *BrowseRequestPayload) SetParams(val OptString) { + s.Params = val +} + // SetBrowseId sets the value of BrowseId. -func (s *BrowseRequestPayload) SetBrowseId(val OptString) { +func (s *BrowseRequestPayload) SetBrowseId(val string) { s.BrowseId = val } // Ref: #/components/schemas/BrowseResponsePayload type BrowseResponsePayload struct { - ResponseContext OptResponseContext `json:"responseContext"` - Header OptBrowseResponsePayloadHeader `json:"header"` - Contents OptBrowseResponsePayloadContents `json:"contents"` - TrackingParams OptString `json:"trackingParams"` + ResponseContext ResponseContext `json:"responseContext"` + Header BrowseResponsePayloadHeader `json:"header"` + Contents BrowseResponsePayloadContents `json:"contents"` + TrackingParams OptString `json:"trackingParams"` } // GetResponseContext returns the value of ResponseContext. -func (s *BrowseResponsePayload) GetResponseContext() OptResponseContext { +func (s *BrowseResponsePayload) GetResponseContext() ResponseContext { return s.ResponseContext } // GetHeader returns the value of Header. -func (s *BrowseResponsePayload) GetHeader() OptBrowseResponsePayloadHeader { +func (s *BrowseResponsePayload) GetHeader() BrowseResponsePayloadHeader { return s.Header } // GetContents returns the value of Contents. -func (s *BrowseResponsePayload) GetContents() OptBrowseResponsePayloadContents { +func (s *BrowseResponsePayload) GetContents() BrowseResponsePayloadContents { return s.Contents } @@ -197,17 +218,17 @@ func (s *BrowseResponsePayload) GetTrackingParams() OptString { } // SetResponseContext sets the value of ResponseContext. -func (s *BrowseResponsePayload) SetResponseContext(val OptResponseContext) { +func (s *BrowseResponsePayload) SetResponseContext(val ResponseContext) { s.ResponseContext = val } // SetHeader sets the value of Header. -func (s *BrowseResponsePayload) SetHeader(val OptBrowseResponsePayloadHeader) { +func (s *BrowseResponsePayload) SetHeader(val BrowseResponsePayloadHeader) { s.Header = val } // SetContents sets the value of Contents. -func (s *BrowseResponsePayload) SetContents(val OptBrowseResponsePayloadContents) { +func (s *BrowseResponsePayload) SetContents(val BrowseResponsePayloadContents) { s.Contents = val } @@ -216,8 +237,6 @@ func (s *BrowseResponsePayload) SetTrackingParams(val OptString) { s.TrackingParams = val } -func (*BrowseResponsePayload) browseRes() {} - type BrowseResponsePayloadContents struct { KidsHomeScreenRenderer OptScreenRenderer `json:"kidsHomeScreenRenderer"` } @@ -263,12 +282,12 @@ func (s *CategoriesHeaderRenderer) SetTrackingParams(val OptString) { // Ref: #/components/schemas/CategoryAssets type CategoryAssets struct { - AssetKey OptString `json:"assetKey"` + AssetKey string `json:"assetKey"` BackgroundColor OptString `json:"backgroundColor"` } // GetAssetKey returns the value of AssetKey. -func (s *CategoryAssets) GetAssetKey() OptString { +func (s *CategoryAssets) GetAssetKey() string { return s.AssetKey } @@ -278,7 +297,7 @@ func (s *CategoryAssets) GetBackgroundColor() OptString { } // SetAssetKey sets the value of AssetKey. -func (s *CategoryAssets) SetAssetKey(val OptString) { +func (s *CategoryAssets) SetAssetKey(val string) { s.AssetKey = val } @@ -287,26 +306,321 @@ func (s *CategoryAssets) SetBackgroundColor(val OptString) { s.BackgroundColor = val } +// Ref: #/components/schemas/CompactChannelRenderer +type CompactChannelRenderer struct { + ChannelId string `json:"channelId"` + Thumbnail OptCompactChannelRendererThumbnail `json:"thumbnail"` + DisplayName Text `json:"displayName"` + VideoCountText Text `json:"videoCountText"` + SubscriberCountText OptText `json:"subscriberCountText"` + NavigationEndpoint OptNavigationEndpoint `json:"navigationEndpoint"` + Title Text `json:"title"` + TrackingParams string `json:"trackingParams"` +} + +// GetChannelId returns the value of ChannelId. +func (s *CompactChannelRenderer) GetChannelId() string { + return s.ChannelId +} + +// GetThumbnail returns the value of Thumbnail. +func (s *CompactChannelRenderer) GetThumbnail() OptCompactChannelRendererThumbnail { + return s.Thumbnail +} + +// GetDisplayName returns the value of DisplayName. +func (s *CompactChannelRenderer) GetDisplayName() Text { + return s.DisplayName +} + +// GetVideoCountText returns the value of VideoCountText. +func (s *CompactChannelRenderer) GetVideoCountText() Text { + return s.VideoCountText +} + +// GetSubscriberCountText returns the value of SubscriberCountText. +func (s *CompactChannelRenderer) GetSubscriberCountText() OptText { + return s.SubscriberCountText +} + +// GetNavigationEndpoint returns the value of NavigationEndpoint. +func (s *CompactChannelRenderer) GetNavigationEndpoint() OptNavigationEndpoint { + return s.NavigationEndpoint +} + +// GetTitle returns the value of Title. +func (s *CompactChannelRenderer) GetTitle() Text { + return s.Title +} + +// GetTrackingParams returns the value of TrackingParams. +func (s *CompactChannelRenderer) GetTrackingParams() string { + return s.TrackingParams +} + +// SetChannelId sets the value of ChannelId. +func (s *CompactChannelRenderer) SetChannelId(val string) { + s.ChannelId = val +} + +// SetThumbnail sets the value of Thumbnail. +func (s *CompactChannelRenderer) SetThumbnail(val OptCompactChannelRendererThumbnail) { + s.Thumbnail = val +} + +// SetDisplayName sets the value of DisplayName. +func (s *CompactChannelRenderer) SetDisplayName(val Text) { + s.DisplayName = val +} + +// SetVideoCountText sets the value of VideoCountText. +func (s *CompactChannelRenderer) SetVideoCountText(val Text) { + s.VideoCountText = val +} + +// SetSubscriberCountText sets the value of SubscriberCountText. +func (s *CompactChannelRenderer) SetSubscriberCountText(val OptText) { + s.SubscriberCountText = val +} + +// SetNavigationEndpoint sets the value of NavigationEndpoint. +func (s *CompactChannelRenderer) SetNavigationEndpoint(val OptNavigationEndpoint) { + s.NavigationEndpoint = val +} + +// SetTitle sets the value of Title. +func (s *CompactChannelRenderer) SetTitle(val Text) { + s.Title = val +} + +// SetTrackingParams sets the value of TrackingParams. +func (s *CompactChannelRenderer) SetTrackingParams(val string) { + s.TrackingParams = val +} + +type CompactChannelRendererThumbnail struct { + Thumbnails []Thumbnail `json:"thumbnails"` +} + +// GetThumbnails returns the value of Thumbnails. +func (s *CompactChannelRendererThumbnail) GetThumbnails() []Thumbnail { + return s.Thumbnails +} + +// SetThumbnails sets the value of Thumbnails. +func (s *CompactChannelRendererThumbnail) SetThumbnails(val []Thumbnail) { + s.Thumbnails = val +} + +// Ref: #/components/schemas/CompactPlaylistRenderer +type CompactPlaylistRenderer struct { + PlaylistId string `json:"playlistId"` + Thumbnail OptCompactPlaylistRendererThumbnail `json:"thumbnail"` + Title Text `json:"title"` + ShortBylineText OptText `json:"shortBylineText"` + VideoCountText OptText `json:"videoCountText"` + NavigationEndpoint OptNavigationEndpoint `json:"navigationEndpoint"` + VideoCountShortText OptText `json:"videoCountShortText"` + TrackingParams string `json:"trackingParams"` + SidebarThumbnails []CompactPlaylistRendererSidebarThumbnailsItem `json:"sidebarThumbnails"` + ThumbnailText OptText `json:"thumbnailText"` + ShareUrl OptString `json:"shareUrl"` + LongBylineText OptText `json:"longBylineText"` + TvBanner OptCompactPlaylistRendererTvBanner `json:"tvBanner"` +} + +// GetPlaylistId returns the value of PlaylistId. +func (s *CompactPlaylistRenderer) GetPlaylistId() string { + return s.PlaylistId +} + +// GetThumbnail returns the value of Thumbnail. +func (s *CompactPlaylistRenderer) GetThumbnail() OptCompactPlaylistRendererThumbnail { + return s.Thumbnail +} + +// GetTitle returns the value of Title. +func (s *CompactPlaylistRenderer) GetTitle() Text { + return s.Title +} + +// GetShortBylineText returns the value of ShortBylineText. +func (s *CompactPlaylistRenderer) GetShortBylineText() OptText { + return s.ShortBylineText +} + +// GetVideoCountText returns the value of VideoCountText. +func (s *CompactPlaylistRenderer) GetVideoCountText() OptText { + return s.VideoCountText +} + +// GetNavigationEndpoint returns the value of NavigationEndpoint. +func (s *CompactPlaylistRenderer) GetNavigationEndpoint() OptNavigationEndpoint { + return s.NavigationEndpoint +} + +// GetVideoCountShortText returns the value of VideoCountShortText. +func (s *CompactPlaylistRenderer) GetVideoCountShortText() OptText { + return s.VideoCountShortText +} + +// GetTrackingParams returns the value of TrackingParams. +func (s *CompactPlaylistRenderer) GetTrackingParams() string { + return s.TrackingParams +} + +// GetSidebarThumbnails returns the value of SidebarThumbnails. +func (s *CompactPlaylistRenderer) GetSidebarThumbnails() []CompactPlaylistRendererSidebarThumbnailsItem { + return s.SidebarThumbnails +} + +// GetThumbnailText returns the value of ThumbnailText. +func (s *CompactPlaylistRenderer) GetThumbnailText() OptText { + return s.ThumbnailText +} + +// GetShareUrl returns the value of ShareUrl. +func (s *CompactPlaylistRenderer) GetShareUrl() OptString { + return s.ShareUrl +} + +// GetLongBylineText returns the value of LongBylineText. +func (s *CompactPlaylistRenderer) GetLongBylineText() OptText { + return s.LongBylineText +} + +// GetTvBanner returns the value of TvBanner. +func (s *CompactPlaylistRenderer) GetTvBanner() OptCompactPlaylistRendererTvBanner { + return s.TvBanner +} + +// SetPlaylistId sets the value of PlaylistId. +func (s *CompactPlaylistRenderer) SetPlaylistId(val string) { + s.PlaylistId = val +} + +// SetThumbnail sets the value of Thumbnail. +func (s *CompactPlaylistRenderer) SetThumbnail(val OptCompactPlaylistRendererThumbnail) { + s.Thumbnail = val +} + +// SetTitle sets the value of Title. +func (s *CompactPlaylistRenderer) SetTitle(val Text) { + s.Title = val +} + +// SetShortBylineText sets the value of ShortBylineText. +func (s *CompactPlaylistRenderer) SetShortBylineText(val OptText) { + s.ShortBylineText = val +} + +// SetVideoCountText sets the value of VideoCountText. +func (s *CompactPlaylistRenderer) SetVideoCountText(val OptText) { + s.VideoCountText = val +} + +// SetNavigationEndpoint sets the value of NavigationEndpoint. +func (s *CompactPlaylistRenderer) SetNavigationEndpoint(val OptNavigationEndpoint) { + s.NavigationEndpoint = val +} + +// SetVideoCountShortText sets the value of VideoCountShortText. +func (s *CompactPlaylistRenderer) SetVideoCountShortText(val OptText) { + s.VideoCountShortText = val +} + +// SetTrackingParams sets the value of TrackingParams. +func (s *CompactPlaylistRenderer) SetTrackingParams(val string) { + s.TrackingParams = val +} + +// SetSidebarThumbnails sets the value of SidebarThumbnails. +func (s *CompactPlaylistRenderer) SetSidebarThumbnails(val []CompactPlaylistRendererSidebarThumbnailsItem) { + s.SidebarThumbnails = val +} + +// SetThumbnailText sets the value of ThumbnailText. +func (s *CompactPlaylistRenderer) SetThumbnailText(val OptText) { + s.ThumbnailText = val +} + +// SetShareUrl sets the value of ShareUrl. +func (s *CompactPlaylistRenderer) SetShareUrl(val OptString) { + s.ShareUrl = val +} + +// SetLongBylineText sets the value of LongBylineText. +func (s *CompactPlaylistRenderer) SetLongBylineText(val OptText) { + s.LongBylineText = val +} + +// SetTvBanner sets the value of TvBanner. +func (s *CompactPlaylistRenderer) SetTvBanner(val OptCompactPlaylistRendererTvBanner) { + s.TvBanner = val +} + +type CompactPlaylistRendererSidebarThumbnailsItem struct { + Thumbnails []Thumbnail `json:"thumbnails"` +} + +// GetThumbnails returns the value of Thumbnails. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) GetThumbnails() []Thumbnail { + return s.Thumbnails +} + +// SetThumbnails sets the value of Thumbnails. +func (s *CompactPlaylistRendererSidebarThumbnailsItem) SetThumbnails(val []Thumbnail) { + s.Thumbnails = val +} + +type CompactPlaylistRendererThumbnail struct { + Thumbnails []Thumbnail `json:"thumbnails"` +} + +// GetThumbnails returns the value of Thumbnails. +func (s *CompactPlaylistRendererThumbnail) GetThumbnails() []Thumbnail { + return s.Thumbnails +} + +// SetThumbnails sets the value of Thumbnails. +func (s *CompactPlaylistRendererThumbnail) SetThumbnails(val []Thumbnail) { + s.Thumbnails = val +} + +type CompactPlaylistRendererTvBanner struct { + Thumbnails []Thumbnail `json:"thumbnails"` +} + +// GetThumbnails returns the value of Thumbnails. +func (s *CompactPlaylistRendererTvBanner) GetThumbnails() []Thumbnail { + return s.Thumbnails +} + +// SetThumbnails sets the value of Thumbnails. +func (s *CompactPlaylistRendererTvBanner) SetThumbnails(val []Thumbnail) { + s.Thumbnails = val +} + // Ref: #/components/schemas/CompactVideoRenderer type CompactVideoRenderer struct { - VideoId OptString `json:"videoId"` + VideoId string `json:"videoId"` Thumbnail OptCompactVideoRendererThumbnail `json:"thumbnail"` - Title OptText `json:"title"` + Title Text `json:"title"` LongBylineText OptText `json:"longBylineText"` PublishedTimeText OptText `json:"publishedTimeText"` - ViewCountText OptText `json:"viewCountText"` + ViewCountText Text `json:"viewCountText"` LengthText OptText `json:"lengthText"` NavigationEndpoint OptNavigationEndpoint `json:"navigationEndpoint"` ShortBylineText OptText `json:"shortBylineText"` ChannelThumbnail OptCompactVideoRendererChannelThumbnail `json:"channelThumbnail"` - TrackingParams OptString `json:"trackingParams"` + TrackingParams string `json:"trackingParams"` ShortViewCountText OptText `json:"shortViewCountText"` Accessibility OptAccessibility `json:"accessibility"` - KidsVideoOwnerExtension OptKidsVideoOwnerExtension `json:"kidsVideoOwnerExtension"` + KidsVideoOwnerExtension KidsVideoOwnerExtension `json:"kidsVideoOwnerExtension"` } // GetVideoId returns the value of VideoId. -func (s *CompactVideoRenderer) GetVideoId() OptString { +func (s *CompactVideoRenderer) GetVideoId() string { return s.VideoId } @@ -316,7 +630,7 @@ func (s *CompactVideoRenderer) GetThumbnail() OptCompactVideoRendererThumbnail { } // GetTitle returns the value of Title. -func (s *CompactVideoRenderer) GetTitle() OptText { +func (s *CompactVideoRenderer) GetTitle() Text { return s.Title } @@ -331,7 +645,7 @@ func (s *CompactVideoRenderer) GetPublishedTimeText() OptText { } // GetViewCountText returns the value of ViewCountText. -func (s *CompactVideoRenderer) GetViewCountText() OptText { +func (s *CompactVideoRenderer) GetViewCountText() Text { return s.ViewCountText } @@ -356,7 +670,7 @@ func (s *CompactVideoRenderer) GetChannelThumbnail() OptCompactVideoRendererChan } // GetTrackingParams returns the value of TrackingParams. -func (s *CompactVideoRenderer) GetTrackingParams() OptString { +func (s *CompactVideoRenderer) GetTrackingParams() string { return s.TrackingParams } @@ -371,12 +685,12 @@ func (s *CompactVideoRenderer) GetAccessibility() OptAccessibility { } // GetKidsVideoOwnerExtension returns the value of KidsVideoOwnerExtension. -func (s *CompactVideoRenderer) GetKidsVideoOwnerExtension() OptKidsVideoOwnerExtension { +func (s *CompactVideoRenderer) GetKidsVideoOwnerExtension() KidsVideoOwnerExtension { return s.KidsVideoOwnerExtension } // SetVideoId sets the value of VideoId. -func (s *CompactVideoRenderer) SetVideoId(val OptString) { +func (s *CompactVideoRenderer) SetVideoId(val string) { s.VideoId = val } @@ -386,7 +700,7 @@ func (s *CompactVideoRenderer) SetThumbnail(val OptCompactVideoRendererThumbnail } // SetTitle sets the value of Title. -func (s *CompactVideoRenderer) SetTitle(val OptText) { +func (s *CompactVideoRenderer) SetTitle(val Text) { s.Title = val } @@ -401,7 +715,7 @@ func (s *CompactVideoRenderer) SetPublishedTimeText(val OptText) { } // SetViewCountText sets the value of ViewCountText. -func (s *CompactVideoRenderer) SetViewCountText(val OptText) { +func (s *CompactVideoRenderer) SetViewCountText(val Text) { s.ViewCountText = val } @@ -426,7 +740,7 @@ func (s *CompactVideoRenderer) SetChannelThumbnail(val OptCompactVideoRendererCh } // SetTrackingParams sets the value of TrackingParams. -func (s *CompactVideoRenderer) SetTrackingParams(val OptString) { +func (s *CompactVideoRenderer) SetTrackingParams(val string) { s.TrackingParams = val } @@ -441,7 +755,7 @@ func (s *CompactVideoRenderer) SetAccessibility(val OptAccessibility) { } // SetKidsVideoOwnerExtension sets the value of KidsVideoOwnerExtension. -func (s *CompactVideoRenderer) SetKidsVideoOwnerExtension(val OptKidsVideoOwnerExtension) { +func (s *CompactVideoRenderer) SetKidsVideoOwnerExtension(val KidsVideoOwnerExtension) { s.KidsVideoOwnerExtension = val } @@ -475,13 +789,13 @@ func (s *CompactVideoRendererThumbnail) SetThumbnails(val []Thumbnail) { // Ref: #/components/schemas/Error type Error struct { - Message OptString `json:"message"` + Message string `json:"message"` Domain OptString `json:"domain"` Reason OptString `json:"reason"` } // GetMessage returns the value of Message. -func (s *Error) GetMessage() OptString { +func (s *Error) GetMessage() string { return s.Message } @@ -496,7 +810,7 @@ func (s *Error) GetReason() OptString { } // SetMessage sets the value of Message. -func (s *Error) SetMessage(val OptString) { +func (s *Error) SetMessage(val string) { s.Message = val } @@ -512,35 +826,33 @@ func (s *Error) SetReason(val OptString) { // Ref: #/components/schemas/ErrorResponsePayload type ErrorResponsePayload struct { - Error OptErrorResponsePayloadError `json:"error"` + Error ErrorResponsePayloadError `json:"error"` } // GetError returns the value of Error. -func (s *ErrorResponsePayload) GetError() OptErrorResponsePayloadError { +func (s *ErrorResponsePayload) GetError() ErrorResponsePayloadError { return s.Error } // SetError sets the value of Error. -func (s *ErrorResponsePayload) SetError(val OptErrorResponsePayloadError) { +func (s *ErrorResponsePayload) SetError(val ErrorResponsePayloadError) { s.Error = val } -func (*ErrorResponsePayload) browseRes() {} - type ErrorResponsePayloadError struct { - Code OptFloat64 `json:"code"` - Message OptString `json:"message"` - Errors []Error `json:"errors"` - Status OptString `json:"status"` + Code int `json:"code"` + Message string `json:"message"` + Errors []Error `json:"errors"` + Status string `json:"status"` } // GetCode returns the value of Code. -func (s *ErrorResponsePayloadError) GetCode() OptFloat64 { +func (s *ErrorResponsePayloadError) GetCode() int { return s.Code } // GetMessage returns the value of Message. -func (s *ErrorResponsePayloadError) GetMessage() OptString { +func (s *ErrorResponsePayloadError) GetMessage() string { return s.Message } @@ -550,17 +862,17 @@ func (s *ErrorResponsePayloadError) GetErrors() []Error { } // GetStatus returns the value of Status. -func (s *ErrorResponsePayloadError) GetStatus() OptString { +func (s *ErrorResponsePayloadError) GetStatus() string { return s.Status } // SetCode sets the value of Code. -func (s *ErrorResponsePayloadError) SetCode(val OptFloat64) { +func (s *ErrorResponsePayloadError) SetCode(val int) { s.Code = val } // SetMessage sets the value of Message. -func (s *ErrorResponsePayloadError) SetMessage(val OptString) { +func (s *ErrorResponsePayloadError) SetMessage(val string) { s.Message = val } @@ -570,14 +882,40 @@ func (s *ErrorResponsePayloadError) SetErrors(val []Error) { } // SetStatus sets the value of Status. -func (s *ErrorResponsePayloadError) SetStatus(val OptString) { +func (s *ErrorResponsePayloadError) SetStatus(val string) { s.Status = val } +// ErrorResponsePayloadStatusCode wraps ErrorResponsePayload with StatusCode. +type ErrorResponsePayloadStatusCode struct { + StatusCode int + Response ErrorResponsePayload +} + +// GetStatusCode returns the value of StatusCode. +func (s *ErrorResponsePayloadStatusCode) GetStatusCode() int { + return s.StatusCode +} + +// GetResponse returns the value of Response. +func (s *ErrorResponsePayloadStatusCode) GetResponse() ErrorResponsePayload { + return s.Response +} + +// SetStatusCode sets the value of StatusCode. +func (s *ErrorResponsePayloadStatusCode) SetStatusCode(val int) { + s.StatusCode = val +} + +// SetResponse sets the value of Response. +func (s *ErrorResponsePayloadStatusCode) SetResponse(val ErrorResponsePayload) { + s.Response = val +} + // Ref: #/components/schemas/ItemSectionRenderer type ItemSectionRenderer struct { Contents []ItemSectionRendererContentsItem `json:"contents"` - TrackingParams OptString `json:"trackingParams"` + TrackingParams string `json:"trackingParams"` } // GetContents returns the value of Contents. @@ -586,7 +924,7 @@ func (s *ItemSectionRenderer) GetContents() []ItemSectionRendererContentsItem { } // GetTrackingParams returns the value of TrackingParams. -func (s *ItemSectionRenderer) GetTrackingParams() OptString { +func (s *ItemSectionRenderer) GetTrackingParams() string { return s.TrackingParams } @@ -596,12 +934,24 @@ func (s *ItemSectionRenderer) SetContents(val []ItemSectionRendererContentsItem) } // SetTrackingParams sets the value of TrackingParams. -func (s *ItemSectionRenderer) SetTrackingParams(val OptString) { +func (s *ItemSectionRenderer) SetTrackingParams(val string) { s.TrackingParams = val } type ItemSectionRendererContentsItem struct { - CompactVideoRenderer OptCompactVideoRenderer `json:"compactVideoRenderer"` + CompactPlaylistRenderer OptCompactPlaylistRenderer `json:"compactPlaylistRenderer"` + CompactChannelRenderer OptCompactChannelRenderer `json:"compactChannelRenderer"` + CompactVideoRenderer OptCompactVideoRenderer `json:"compactVideoRenderer"` +} + +// GetCompactPlaylistRenderer returns the value of CompactPlaylistRenderer. +func (s *ItemSectionRendererContentsItem) GetCompactPlaylistRenderer() OptCompactPlaylistRenderer { + return s.CompactPlaylistRenderer +} + +// GetCompactChannelRenderer returns the value of CompactChannelRenderer. +func (s *ItemSectionRendererContentsItem) GetCompactChannelRenderer() OptCompactChannelRenderer { + return s.CompactChannelRenderer } // GetCompactVideoRenderer returns the value of CompactVideoRenderer. @@ -609,6 +959,16 @@ func (s *ItemSectionRendererContentsItem) GetCompactVideoRenderer() OptCompactVi return s.CompactVideoRenderer } +// SetCompactPlaylistRenderer sets the value of CompactPlaylistRenderer. +func (s *ItemSectionRendererContentsItem) SetCompactPlaylistRenderer(val OptCompactPlaylistRenderer) { + s.CompactPlaylistRenderer = val +} + +// SetCompactChannelRenderer sets the value of CompactChannelRenderer. +func (s *ItemSectionRendererContentsItem) SetCompactChannelRenderer(val OptCompactChannelRenderer) { + s.CompactChannelRenderer = val +} + // SetCompactVideoRenderer sets the value of CompactVideoRenderer. func (s *ItemSectionRendererContentsItem) SetCompactVideoRenderer(val OptCompactVideoRenderer) { s.CompactVideoRenderer = val @@ -616,27 +976,27 @@ func (s *ItemSectionRendererContentsItem) SetCompactVideoRenderer(val OptCompact // Ref: #/components/schemas/KeyStringValue type KeyStringValue struct { - Key OptString `json:"key"` - Value OptString `json:"value"` + Key string `json:"key"` + Value string `json:"value"` } // GetKey returns the value of Key. -func (s *KeyStringValue) GetKey() OptString { +func (s *KeyStringValue) GetKey() string { return s.Key } // GetValue returns the value of Value. -func (s *KeyStringValue) GetValue() OptString { +func (s *KeyStringValue) GetValue() string { return s.Value } // SetKey sets the value of Key. -func (s *KeyStringValue) SetKey(val OptString) { +func (s *KeyStringValue) SetKey(val string) { s.Key = val } // SetValue sets the value of Value. -func (s *KeyStringValue) SetValue(val OptString) { +func (s *KeyStringValue) SetValue(val string) { s.Value = val } @@ -657,30 +1017,126 @@ func (s *KidsAppCategorySettings) SetEnabledCategories(val []string) { // Ref: #/components/schemas/KidsAppContentSettings type KidsAppContentSettings struct { - CorpusPreference OptString `json:"corpusPreference"` - KidsNoSearchMode OptString `json:"kidsNoSearchMode"` + CorpusPreference KidsAppContentSettingsCorpusPreference `json:"corpusPreference"` + KidsNoSearchMode KidsAppContentSettingsKidsNoSearchMode `json:"kidsNoSearchMode"` } // GetCorpusPreference returns the value of CorpusPreference. -func (s *KidsAppContentSettings) GetCorpusPreference() OptString { +func (s *KidsAppContentSettings) GetCorpusPreference() KidsAppContentSettingsCorpusPreference { return s.CorpusPreference } // GetKidsNoSearchMode returns the value of KidsNoSearchMode. -func (s *KidsAppContentSettings) GetKidsNoSearchMode() OptString { +func (s *KidsAppContentSettings) GetKidsNoSearchMode() KidsAppContentSettingsKidsNoSearchMode { return s.KidsNoSearchMode } // SetCorpusPreference sets the value of CorpusPreference. -func (s *KidsAppContentSettings) SetCorpusPreference(val OptString) { +func (s *KidsAppContentSettings) SetCorpusPreference(val KidsAppContentSettingsCorpusPreference) { s.CorpusPreference = val } // SetKidsNoSearchMode sets the value of KidsNoSearchMode. -func (s *KidsAppContentSettings) SetKidsNoSearchMode(val OptString) { +func (s *KidsAppContentSettings) SetKidsNoSearchMode(val KidsAppContentSettingsKidsNoSearchMode) { s.KidsNoSearchMode = val } +type KidsAppContentSettingsCorpusPreference string + +const ( + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_UNKNOWN" + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_YOUNGER" + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_TWEEN" + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_PAM_YOUNGER" + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_PAM_TWEEN" + KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL KidsAppContentSettingsCorpusPreference = "KIDS_CORPUS_PREFERENCE_PRESCHOOL" +) + +// MarshalText implements encoding.TextMarshaler. +func (s KidsAppContentSettingsCorpusPreference) MarshalText() ([]byte, error) { + switch s { + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN: + return []byte(s), nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER: + return []byte(s), nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN: + return []byte(s), nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER: + return []byte(s), nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN: + return []byte(s), nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *KidsAppContentSettingsCorpusPreference) UnmarshalText(data []byte) error { + switch KidsAppContentSettingsCorpusPreference(data) { + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN + return nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER + return nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN + return nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER + return nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN + return nil + case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL: + *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +type KidsAppContentSettingsKidsNoSearchMode string + +const ( + KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN KidsAppContentSettingsKidsNoSearchMode = "YT_KIDS_NO_SEARCH_MODE_UNKNOWN" + KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON KidsAppContentSettingsKidsNoSearchMode = "YT_KIDS_NO_SEARCH_MODE_ON" + KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF KidsAppContentSettingsKidsNoSearchMode = "YT_KIDS_NO_SEARCH_MODE_OFF" +) + +// MarshalText implements encoding.TextMarshaler. +func (s KidsAppContentSettingsKidsNoSearchMode) MarshalText() ([]byte, error) { + switch s { + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN: + return []byte(s), nil + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON: + return []byte(s), nil + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *KidsAppContentSettingsKidsNoSearchMode) UnmarshalText(data []byte) error { + switch KidsAppContentSettingsKidsNoSearchMode(data) { + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN + return nil + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON + return nil + case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF: + *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Kids application configuration. // Ref: #/components/schemas/KidsAppInfo type KidsAppInfo struct { @@ -710,16 +1166,16 @@ func (s *KidsAppInfo) SetCategorySettings(val OptKidsAppCategorySettings) { // Ref: #/components/schemas/KidsVideoOwnerExtension type KidsVideoOwnerExtension struct { - ExternalChannelId OptString `json:"externalChannelId"` + ExternalChannelId string `json:"externalChannelId"` } // GetExternalChannelId returns the value of ExternalChannelId. -func (s *KidsVideoOwnerExtension) GetExternalChannelId() OptString { +func (s *KidsVideoOwnerExtension) GetExternalChannelId() string { return s.ExternalChannelId } // SetExternalChannelId sets the value of ExternalChannelId. -func (s *KidsVideoOwnerExtension) SetExternalChannelId(val OptString) { +func (s *KidsVideoOwnerExtension) SetExternalChannelId(val string) { s.ExternalChannelId = val } @@ -990,98 +1446,6 @@ func (o OptBrowseEndpoint) Or(d BrowseEndpoint) BrowseEndpoint { return d } -// NewOptBrowseResponsePayloadContents returns new OptBrowseResponsePayloadContents with value set to v. -func NewOptBrowseResponsePayloadContents(v BrowseResponsePayloadContents) OptBrowseResponsePayloadContents { - return OptBrowseResponsePayloadContents{ - Value: v, - Set: true, - } -} - -// OptBrowseResponsePayloadContents is optional BrowseResponsePayloadContents. -type OptBrowseResponsePayloadContents struct { - Value BrowseResponsePayloadContents - Set bool -} - -// IsSet returns true if OptBrowseResponsePayloadContents was set. -func (o OptBrowseResponsePayloadContents) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptBrowseResponsePayloadContents) Reset() { - var v BrowseResponsePayloadContents - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptBrowseResponsePayloadContents) SetTo(v BrowseResponsePayloadContents) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptBrowseResponsePayloadContents) Get() (v BrowseResponsePayloadContents, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptBrowseResponsePayloadContents) Or(d BrowseResponsePayloadContents) BrowseResponsePayloadContents { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptBrowseResponsePayloadHeader returns new OptBrowseResponsePayloadHeader with value set to v. -func NewOptBrowseResponsePayloadHeader(v BrowseResponsePayloadHeader) OptBrowseResponsePayloadHeader { - return OptBrowseResponsePayloadHeader{ - Value: v, - Set: true, - } -} - -// OptBrowseResponsePayloadHeader is optional BrowseResponsePayloadHeader. -type OptBrowseResponsePayloadHeader struct { - Value BrowseResponsePayloadHeader - Set bool -} - -// IsSet returns true if OptBrowseResponsePayloadHeader was set. -func (o OptBrowseResponsePayloadHeader) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptBrowseResponsePayloadHeader) Reset() { - var v BrowseResponsePayloadHeader - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptBrowseResponsePayloadHeader) SetTo(v BrowseResponsePayloadHeader) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptBrowseResponsePayloadHeader) Get() (v BrowseResponsePayloadHeader, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptBrowseResponsePayloadHeader) Or(d BrowseResponsePayloadHeader) BrowseResponsePayloadHeader { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptCategoriesHeaderRenderer returns new OptCategoriesHeaderRenderer with value set to v. func NewOptCategoriesHeaderRenderer(v CategoriesHeaderRenderer) OptCategoriesHeaderRenderer { return OptCategoriesHeaderRenderer{ @@ -1174,6 +1538,236 @@ func (o OptCategoryAssets) Or(d CategoryAssets) CategoryAssets { return d } +// NewOptCompactChannelRenderer returns new OptCompactChannelRenderer with value set to v. +func NewOptCompactChannelRenderer(v CompactChannelRenderer) OptCompactChannelRenderer { + return OptCompactChannelRenderer{ + Value: v, + Set: true, + } +} + +// OptCompactChannelRenderer is optional CompactChannelRenderer. +type OptCompactChannelRenderer struct { + Value CompactChannelRenderer + Set bool +} + +// IsSet returns true if OptCompactChannelRenderer was set. +func (o OptCompactChannelRenderer) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptCompactChannelRenderer) Reset() { + var v CompactChannelRenderer + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptCompactChannelRenderer) SetTo(v CompactChannelRenderer) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptCompactChannelRenderer) Get() (v CompactChannelRenderer, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptCompactChannelRenderer) Or(d CompactChannelRenderer) CompactChannelRenderer { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptCompactChannelRendererThumbnail returns new OptCompactChannelRendererThumbnail with value set to v. +func NewOptCompactChannelRendererThumbnail(v CompactChannelRendererThumbnail) OptCompactChannelRendererThumbnail { + return OptCompactChannelRendererThumbnail{ + Value: v, + Set: true, + } +} + +// OptCompactChannelRendererThumbnail is optional CompactChannelRendererThumbnail. +type OptCompactChannelRendererThumbnail struct { + Value CompactChannelRendererThumbnail + Set bool +} + +// IsSet returns true if OptCompactChannelRendererThumbnail was set. +func (o OptCompactChannelRendererThumbnail) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptCompactChannelRendererThumbnail) Reset() { + var v CompactChannelRendererThumbnail + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptCompactChannelRendererThumbnail) SetTo(v CompactChannelRendererThumbnail) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptCompactChannelRendererThumbnail) Get() (v CompactChannelRendererThumbnail, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptCompactChannelRendererThumbnail) Or(d CompactChannelRendererThumbnail) CompactChannelRendererThumbnail { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptCompactPlaylistRenderer returns new OptCompactPlaylistRenderer with value set to v. +func NewOptCompactPlaylistRenderer(v CompactPlaylistRenderer) OptCompactPlaylistRenderer { + return OptCompactPlaylistRenderer{ + Value: v, + Set: true, + } +} + +// OptCompactPlaylistRenderer is optional CompactPlaylistRenderer. +type OptCompactPlaylistRenderer struct { + Value CompactPlaylistRenderer + Set bool +} + +// IsSet returns true if OptCompactPlaylistRenderer was set. +func (o OptCompactPlaylistRenderer) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptCompactPlaylistRenderer) Reset() { + var v CompactPlaylistRenderer + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptCompactPlaylistRenderer) SetTo(v CompactPlaylistRenderer) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptCompactPlaylistRenderer) Get() (v CompactPlaylistRenderer, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptCompactPlaylistRenderer) Or(d CompactPlaylistRenderer) CompactPlaylistRenderer { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptCompactPlaylistRendererThumbnail returns new OptCompactPlaylistRendererThumbnail with value set to v. +func NewOptCompactPlaylistRendererThumbnail(v CompactPlaylistRendererThumbnail) OptCompactPlaylistRendererThumbnail { + return OptCompactPlaylistRendererThumbnail{ + Value: v, + Set: true, + } +} + +// OptCompactPlaylistRendererThumbnail is optional CompactPlaylistRendererThumbnail. +type OptCompactPlaylistRendererThumbnail struct { + Value CompactPlaylistRendererThumbnail + Set bool +} + +// IsSet returns true if OptCompactPlaylistRendererThumbnail was set. +func (o OptCompactPlaylistRendererThumbnail) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptCompactPlaylistRendererThumbnail) Reset() { + var v CompactPlaylistRendererThumbnail + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptCompactPlaylistRendererThumbnail) SetTo(v CompactPlaylistRendererThumbnail) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptCompactPlaylistRendererThumbnail) Get() (v CompactPlaylistRendererThumbnail, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptCompactPlaylistRendererThumbnail) Or(d CompactPlaylistRendererThumbnail) CompactPlaylistRendererThumbnail { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptCompactPlaylistRendererTvBanner returns new OptCompactPlaylistRendererTvBanner with value set to v. +func NewOptCompactPlaylistRendererTvBanner(v CompactPlaylistRendererTvBanner) OptCompactPlaylistRendererTvBanner { + return OptCompactPlaylistRendererTvBanner{ + Value: v, + Set: true, + } +} + +// OptCompactPlaylistRendererTvBanner is optional CompactPlaylistRendererTvBanner. +type OptCompactPlaylistRendererTvBanner struct { + Value CompactPlaylistRendererTvBanner + Set bool +} + +// IsSet returns true if OptCompactPlaylistRendererTvBanner was set. +func (o OptCompactPlaylistRendererTvBanner) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptCompactPlaylistRendererTvBanner) Reset() { + var v CompactPlaylistRendererTvBanner + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptCompactPlaylistRendererTvBanner) SetTo(v CompactPlaylistRendererTvBanner) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptCompactPlaylistRendererTvBanner) Get() (v CompactPlaylistRendererTvBanner, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptCompactPlaylistRendererTvBanner) Or(d CompactPlaylistRendererTvBanner) CompactPlaylistRendererTvBanner { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptCompactVideoRenderer returns new OptCompactVideoRenderer with value set to v. func NewOptCompactVideoRenderer(v CompactVideoRenderer) OptCompactVideoRenderer { return OptCompactVideoRenderer{ @@ -1312,38 +1906,38 @@ func (o OptCompactVideoRendererThumbnail) Or(d CompactVideoRendererThumbnail) Co return d } -// NewOptErrorResponsePayloadError returns new OptErrorResponsePayloadError with value set to v. -func NewOptErrorResponsePayloadError(v ErrorResponsePayloadError) OptErrorResponsePayloadError { - return OptErrorResponsePayloadError{ +// NewOptInt returns new OptInt with value set to v. +func NewOptInt(v int) OptInt { + return OptInt{ Value: v, Set: true, } } -// OptErrorResponsePayloadError is optional ErrorResponsePayloadError. -type OptErrorResponsePayloadError struct { - Value ErrorResponsePayloadError +// OptInt is optional int. +type OptInt struct { + Value int Set bool } -// IsSet returns true if OptErrorResponsePayloadError was set. -func (o OptErrorResponsePayloadError) IsSet() bool { return o.Set } +// IsSet returns true if OptInt was set. +func (o OptInt) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptErrorResponsePayloadError) Reset() { - var v ErrorResponsePayloadError +func (o *OptInt) Reset() { + var v int o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptErrorResponsePayloadError) SetTo(v ErrorResponsePayloadError) { +func (o *OptInt) SetTo(v int) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptErrorResponsePayloadError) Get() (v ErrorResponsePayloadError, ok bool) { +func (o OptInt) Get() (v int, ok bool) { if !o.Set { return v, false } @@ -1351,53 +1945,7 @@ func (o OptErrorResponsePayloadError) Get() (v ErrorResponsePayloadError, ok boo } // Or returns value if set, or given parameter if does not. -func (o OptErrorResponsePayloadError) Or(d ErrorResponsePayloadError) ErrorResponsePayloadError { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptFloat64 returns new OptFloat64 with value set to v. -func NewOptFloat64(v float64) OptFloat64 { - return OptFloat64{ - Value: v, - Set: true, - } -} - -// OptFloat64 is optional float64. -type OptFloat64 struct { - Value float64 - Set bool -} - -// IsSet returns true if OptFloat64 was set. -func (o OptFloat64) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptFloat64) Reset() { - var v float64 - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptFloat64) SetTo(v float64) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptFloat64) Get() (v float64, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptFloat64) Or(d float64) float64 { +func (o OptInt) Or(d int) int { if v, ok := o.Get(); ok { return v } @@ -1542,98 +2090,6 @@ func (o OptKidsAppContentSettings) Or(d KidsAppContentSettings) KidsAppContentSe return d } -// NewOptKidsAppInfo returns new OptKidsAppInfo with value set to v. -func NewOptKidsAppInfo(v KidsAppInfo) OptKidsAppInfo { - return OptKidsAppInfo{ - Value: v, - Set: true, - } -} - -// OptKidsAppInfo is optional KidsAppInfo. -type OptKidsAppInfo struct { - Value KidsAppInfo - Set bool -} - -// IsSet returns true if OptKidsAppInfo was set. -func (o OptKidsAppInfo) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptKidsAppInfo) Reset() { - var v KidsAppInfo - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptKidsAppInfo) SetTo(v KidsAppInfo) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptKidsAppInfo) Get() (v KidsAppInfo, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptKidsAppInfo) Or(d KidsAppInfo) KidsAppInfo { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptKidsVideoOwnerExtension returns new OptKidsVideoOwnerExtension with value set to v. -func NewOptKidsVideoOwnerExtension(v KidsVideoOwnerExtension) OptKidsVideoOwnerExtension { - return OptKidsVideoOwnerExtension{ - Value: v, - Set: true, - } -} - -// OptKidsVideoOwnerExtension is optional KidsVideoOwnerExtension. -type OptKidsVideoOwnerExtension struct { - Value KidsVideoOwnerExtension - Set bool -} - -// IsSet returns true if OptKidsVideoOwnerExtension was set. -func (o OptKidsVideoOwnerExtension) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptKidsVideoOwnerExtension) Reset() { - var v KidsVideoOwnerExtension - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptKidsVideoOwnerExtension) SetTo(v KidsVideoOwnerExtension) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptKidsVideoOwnerExtension) Get() (v KidsVideoOwnerExtension, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptKidsVideoOwnerExtension) Or(d KidsVideoOwnerExtension) KidsVideoOwnerExtension { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptNavigationEndpoint returns new OptNavigationEndpoint with value set to v. func NewOptNavigationEndpoint(v NavigationEndpoint) OptNavigationEndpoint { return OptNavigationEndpoint{ @@ -1680,144 +2136,6 @@ func (o OptNavigationEndpoint) Or(d NavigationEndpoint) NavigationEndpoint { return d } -// NewOptRequestClient returns new OptRequestClient with value set to v. -func NewOptRequestClient(v RequestClient) OptRequestClient { - return OptRequestClient{ - Value: v, - Set: true, - } -} - -// OptRequestClient is optional RequestClient. -type OptRequestClient struct { - Value RequestClient - Set bool -} - -// IsSet returns true if OptRequestClient was set. -func (o OptRequestClient) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptRequestClient) Reset() { - var v RequestClient - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptRequestClient) SetTo(v RequestClient) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptRequestClient) Get() (v RequestClient, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptRequestClient) Or(d RequestClient) RequestClient { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptRequestContext returns new OptRequestContext with value set to v. -func NewOptRequestContext(v RequestContext) OptRequestContext { - return OptRequestContext{ - Value: v, - Set: true, - } -} - -// OptRequestContext is optional RequestContext. -type OptRequestContext struct { - Value RequestContext - Set bool -} - -// IsSet returns true if OptRequestContext was set. -func (o OptRequestContext) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptRequestContext) Reset() { - var v RequestContext - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptRequestContext) SetTo(v RequestContext) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptRequestContext) Get() (v RequestContext, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptRequestContext) Or(d RequestContext) RequestContext { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptResponseContext returns new OptResponseContext with value set to v. -func NewOptResponseContext(v ResponseContext) OptResponseContext { - return OptResponseContext{ - Value: v, - Set: true, - } -} - -// OptResponseContext is optional ResponseContext. -type OptResponseContext struct { - Value ResponseContext - Set bool -} - -// IsSet returns true if OptResponseContext was set. -func (o OptResponseContext) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptResponseContext) Reset() { - var v ResponseContext - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptResponseContext) SetTo(v ResponseContext) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptResponseContext) Get() (v ResponseContext, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptResponseContext) Or(d ResponseContext) ResponseContext { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptScreenRenderer returns new OptScreenRenderer with value set to v. func NewOptScreenRenderer(v ScreenRenderer) OptScreenRenderer { return OptScreenRenderer{ @@ -2051,18 +2369,18 @@ func (o OptWatchEndpoint) Or(d WatchEndpoint) WatchEndpoint { // Client information. // Ref: #/components/schemas/RequestClient type RequestClient struct { - ClientName OptString `json:"clientName"` - ClientVersion OptString `json:"clientVersion"` - Hl OptString `json:"hl"` - Gl OptString `json:"gl"` - ExperimentsToken OptString `json:"experimentsToken"` - BrowserName OptString `json:"browserName"` - DeviceMake OptString `json:"deviceMake"` - BrowserVersion OptString `json:"browserVersion"` - OsName OptString `json:"osName"` - OsVersion OptString `json:"osVersion"` - Platform OptString `json:"platform"` - KidsAppInfo OptKidsAppInfo `json:"kidsAppInfo"` + ClientName OptString `json:"clientName"` + ClientVersion OptString `json:"clientVersion"` + Hl OptString `json:"hl"` + Gl OptString `json:"gl"` + ExperimentsToken OptString `json:"experimentsToken"` + BrowserName OptString `json:"browserName"` + DeviceMake OptString `json:"deviceMake"` + BrowserVersion OptString `json:"browserVersion"` + OsName OptString `json:"osName"` + OsVersion OptString `json:"osVersion"` + Platform OptString `json:"platform"` + KidsAppInfo KidsAppInfo `json:"kidsAppInfo"` } // GetClientName returns the value of ClientName. @@ -2121,7 +2439,7 @@ func (s *RequestClient) GetPlatform() OptString { } // GetKidsAppInfo returns the value of KidsAppInfo. -func (s *RequestClient) GetKidsAppInfo() OptKidsAppInfo { +func (s *RequestClient) GetKidsAppInfo() KidsAppInfo { return s.KidsAppInfo } @@ -2181,23 +2499,23 @@ func (s *RequestClient) SetPlatform(val OptString) { } // SetKidsAppInfo sets the value of KidsAppInfo. -func (s *RequestClient) SetKidsAppInfo(val OptKidsAppInfo) { +func (s *RequestClient) SetKidsAppInfo(val KidsAppInfo) { s.KidsAppInfo = val } // Request context. // Ref: #/components/schemas/RequestContext type RequestContext struct { - Client OptRequestClient `json:"client"` + Client RequestClient `json:"client"` } // GetClient returns the value of Client. -func (s *RequestContext) GetClient() OptRequestClient { +func (s *RequestContext) GetClient() RequestClient { return s.Client } // SetClient sets the value of Client. -func (s *RequestContext) SetClient(val OptRequestClient) { +func (s *RequestContext) SetClient(val RequestClient) { s.Client = val } @@ -2205,7 +2523,7 @@ func (s *RequestContext) SetClient(val OptRequestClient) { // Ref: #/components/schemas/ResponseContext type ResponseContext struct { VisitorData OptString `json:"visitorData"` - MaxAgeSeconds OptFloat64 `json:"maxAgeSeconds"` + MaxAgeSeconds OptInt `json:"maxAgeSeconds"` ServiceTrackingParams []ResponseContextServiceTrackingParamsItem `json:"serviceTrackingParams"` } @@ -2215,7 +2533,7 @@ func (s *ResponseContext) GetVisitorData() OptString { } // GetMaxAgeSeconds returns the value of MaxAgeSeconds. -func (s *ResponseContext) GetMaxAgeSeconds() OptFloat64 { +func (s *ResponseContext) GetMaxAgeSeconds() OptInt { return s.MaxAgeSeconds } @@ -2230,7 +2548,7 @@ func (s *ResponseContext) SetVisitorData(val OptString) { } // SetMaxAgeSeconds sets the value of MaxAgeSeconds. -func (s *ResponseContext) SetMaxAgeSeconds(val OptFloat64) { +func (s *ResponseContext) SetMaxAgeSeconds(val OptInt) { s.MaxAgeSeconds = val } @@ -2362,12 +2680,12 @@ func (s *Text) SetAccessibility(val OptAccessibility) { // Ref: #/components/schemas/TextRun type TextRun struct { - Text OptString `json:"text"` + Text string `json:"text"` NavigationEndpoint OptNavigationEndpoint `json:"navigationEndpoint"` } // GetText returns the value of Text. -func (s *TextRun) GetText() OptString { +func (s *TextRun) GetText() string { return s.Text } @@ -2377,7 +2695,7 @@ func (s *TextRun) GetNavigationEndpoint() OptNavigationEndpoint { } // SetText sets the value of Text. -func (s *TextRun) SetText(val OptString) { +func (s *TextRun) SetText(val string) { s.Text = val } @@ -2388,38 +2706,38 @@ func (s *TextRun) SetNavigationEndpoint(val OptNavigationEndpoint) { // Ref: #/components/schemas/Thumbnail type Thumbnail struct { - URL OptString `json:"url"` - Width OptFloat64 `json:"width"` - Height OptFloat64 `json:"height"` + URL string `json:"url"` + Width int `json:"width"` + Height int `json:"height"` } // GetURL returns the value of URL. -func (s *Thumbnail) GetURL() OptString { +func (s *Thumbnail) GetURL() string { return s.URL } // GetWidth returns the value of Width. -func (s *Thumbnail) GetWidth() OptFloat64 { +func (s *Thumbnail) GetWidth() int { return s.Width } // GetHeight returns the value of Height. -func (s *Thumbnail) GetHeight() OptFloat64 { +func (s *Thumbnail) GetHeight() int { return s.Height } // SetURL sets the value of URL. -func (s *Thumbnail) SetURL(val OptString) { +func (s *Thumbnail) SetURL(val string) { s.URL = val } // SetWidth sets the value of Width. -func (s *Thumbnail) SetWidth(val OptFloat64) { +func (s *Thumbnail) SetWidth(val int) { s.Width = val } // SetHeight sets the value of Height. -func (s *Thumbnail) SetHeight(val OptFloat64) { +func (s *Thumbnail) SetHeight(val int) { s.Height = val } diff --git a/oas_test_examples_gen_test.go b/oas_test_examples_gen_test.go index 6a5dd43..b5ea344 100644 --- a/oas_test_examples_gen_test.go +++ b/oas_test_examples_gen_test.go @@ -3,8 +3,13 @@ package go_youtubekids_client import ( + "fmt" + + "github.com/go-faster/errors" "github.com/go-faster/jx" + "github.com/ogen-go/ogen/validate" + std "encoding/json" "testing" @@ -143,6 +148,78 @@ func TestCategoryAssets_EncodeDecode(t *testing.T) { var typ2 CategoryAssets require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } +func TestCompactChannelRenderer_EncodeDecode(t *testing.T) { + var typ CompactChannelRenderer + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactChannelRenderer + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestCompactChannelRendererThumbnail_EncodeDecode(t *testing.T) { + var typ CompactChannelRendererThumbnail + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactChannelRendererThumbnail + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestCompactPlaylistRenderer_EncodeDecode(t *testing.T) { + var typ CompactPlaylistRenderer + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactPlaylistRenderer + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestCompactPlaylistRendererSidebarThumbnailsItem_EncodeDecode(t *testing.T) { + var typ CompactPlaylistRendererSidebarThumbnailsItem + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactPlaylistRendererSidebarThumbnailsItem + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestCompactPlaylistRendererThumbnail_EncodeDecode(t *testing.T) { + var typ CompactPlaylistRendererThumbnail + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactPlaylistRendererThumbnail + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestCompactPlaylistRendererTvBanner_EncodeDecode(t *testing.T) { + var typ CompactPlaylistRendererTvBanner + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 CompactPlaylistRendererTvBanner + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} func TestCompactVideoRenderer_EncodeDecode(t *testing.T) { var typ CompactVideoRenderer typ.SetFake() @@ -275,6 +352,88 @@ func TestKidsAppContentSettings_EncodeDecode(t *testing.T) { var typ2 KidsAppContentSettings require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } +func TestKidsAppContentSettingsCorpusPreference_EncodeDecode(t *testing.T) { + var typ KidsAppContentSettingsCorpusPreference + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 KidsAppContentSettingsCorpusPreference + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} + +func TestKidsAppContentSettingsCorpusPreference_Examples(t *testing.T) { + + for i, tc := range []struct { + Input string + }{ + {Input: "\"KIDS_CORPUS_PREFERENCE_TWEEN\""}, + } { + tc := tc + t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) { + var typ KidsAppContentSettingsCorpusPreference + + if err := typ.Decode(jx.DecodeStr(tc.Input)); err != nil { + if validateErr, ok := errors.Into[*validate.Error](err); ok { + t.Skipf("Validation error: %v", validateErr) + return + } + require.NoErrorf(t, err, "Input: %s", tc.Input) + } + + e := jx.Encoder{} + typ.Encode(&e) + require.True(t, std.Valid(e.Bytes()), "Encoded: %s", e.Bytes()) + + var typ2 KidsAppContentSettingsCorpusPreference + require.NoError(t, typ2.Decode(jx.DecodeBytes(e.Bytes()))) + }) + } +} +func TestKidsAppContentSettingsKidsNoSearchMode_EncodeDecode(t *testing.T) { + var typ KidsAppContentSettingsKidsNoSearchMode + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 KidsAppContentSettingsKidsNoSearchMode + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} + +func TestKidsAppContentSettingsKidsNoSearchMode_Examples(t *testing.T) { + + for i, tc := range []struct { + Input string + }{ + {Input: "\"YT_KIDS_NO_SEARCH_MODE_OFF\""}, + } { + tc := tc + t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) { + var typ KidsAppContentSettingsKidsNoSearchMode + + if err := typ.Decode(jx.DecodeStr(tc.Input)); err != nil { + if validateErr, ok := errors.Into[*validate.Error](err); ok { + t.Skipf("Validation error: %v", validateErr) + return + } + require.NoErrorf(t, err, "Input: %s", tc.Input) + } + + e := jx.Encoder{} + typ.Encode(&e) + require.True(t, std.Valid(e.Bytes()), "Encoded: %s", e.Bytes()) + + var typ2 KidsAppContentSettingsKidsNoSearchMode + require.NoError(t, typ2.Decode(jx.DecodeBytes(e.Bytes()))) + }) + } +} func TestKidsAppInfo_EncodeDecode(t *testing.T) { var typ KidsAppInfo typ.SetFake() diff --git a/oas_validators_gen.go b/oas_validators_gen.go index 62f9d64..1d78f88 100644 --- a/oas_validators_gen.go +++ b/oas_validators_gen.go @@ -60,36 +60,29 @@ func (s *AnchoredSectionRendererContent) Validate() error { } return nil } -func (s *BrowseResponsePayload) Validate() error { +func (s *BrowseRequestPayload) Validate() error { var failures []validate.FieldError if err := func() error { - if s.ResponseContext.Set { - if err := func() error { - if err := s.ResponseContext.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } + if err := s.Context.Validate(); err != nil { + return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "responseContext", + Name: "context", Error: err, }) } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} +func (s *BrowseResponsePayload) Validate() error { + var failures []validate.FieldError if err := func() error { - if s.Contents.Set { - if err := func() error { - if err := s.Contents.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } + if err := s.Contents.Validate(); err != nil { + return err } return nil }(); err != nil { @@ -128,12 +121,189 @@ func (s *BrowseResponsePayloadContents) Validate() error { } return nil } +func (s *CompactChannelRenderer) Validate() error { + var failures []validate.FieldError + if err := func() error { + if err := s.DisplayName.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "displayName", + Error: err, + }) + } + if err := func() error { + if err := s.VideoCountText.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "videoCountText", + Error: err, + }) + } + if err := func() error { + if s.SubscriberCountText.Set { + if err := func() error { + if err := s.SubscriberCountText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "subscriberCountText", + Error: err, + }) + } + if err := func() error { + if err := s.Title.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "title", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} +func (s *CompactPlaylistRenderer) Validate() error { + var failures []validate.FieldError + if err := func() error { + if err := s.Title.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "title", + Error: err, + }) + } + if err := func() error { + if s.ShortBylineText.Set { + if err := func() error { + if err := s.ShortBylineText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "shortBylineText", + Error: err, + }) + } + if err := func() error { + if s.VideoCountText.Set { + if err := func() error { + if err := s.VideoCountText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "videoCountText", + Error: err, + }) + } + if err := func() error { + if s.VideoCountShortText.Set { + if err := func() error { + if err := s.VideoCountShortText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "videoCountShortText", + Error: err, + }) + } + if err := func() error { + if s.ThumbnailText.Set { + if err := func() error { + if err := s.ThumbnailText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "thumbnailText", + Error: err, + }) + } + if err := func() error { + if s.LongBylineText.Set { + if err := func() error { + if err := s.LongBylineText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "longBylineText", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} func (s *CompactVideoRenderer) Validate() error { var failures []validate.FieldError if err := func() error { - if s.Thumbnail.Set { + if err := s.Title.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "title", + Error: err, + }) + } + if err := func() error { + if s.LongBylineText.Set { if err := func() error { - if err := s.Thumbnail.Value.Validate(); err != nil { + if err := s.LongBylineText.Value.Validate(); err != nil { return err } return nil @@ -144,14 +314,14 @@ func (s *CompactVideoRenderer) Validate() error { return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "thumbnail", + Name: "longBylineText", Error: err, }) } if err := func() error { - if s.ChannelThumbnail.Set { + if s.PublishedTimeText.Set { if err := func() error { - if err := s.ChannelThumbnail.Value.Validate(); err != nil { + if err := s.PublishedTimeText.Value.Validate(); err != nil { return err } return nil @@ -162,85 +332,25 @@ func (s *CompactVideoRenderer) Validate() error { return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "channelThumbnail", + Name: "publishedTimeText", Error: err, }) } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *CompactVideoRendererChannelThumbnail) Validate() error { - var failures []validate.FieldError if err := func() error { - var failures []validate.FieldError - for i, elem := range s.Thumbnails { - 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} + if err := s.ViewCountText.Validate(); err != nil { + return err } return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "thumbnails", + Name: "viewCountText", Error: err, }) } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *CompactVideoRendererThumbnail) Validate() error { - var failures []validate.FieldError if err := func() error { - var failures []validate.FieldError - for i, elem := range s.Thumbnails { + if s.LengthText.Set { 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 { - failures = append(failures, validate.FieldError{ - Name: "thumbnails", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *ErrorResponsePayload) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.Error.Set { - if err := func() error { - if err := s.Error.Value.Validate(); err != nil { + if err := s.LengthText.Value.Validate(); err != nil { return err } return nil @@ -251,22 +361,15 @@ func (s *ErrorResponsePayload) Validate() error { return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "error", + Name: "lengthText", Error: err, }) } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *ErrorResponsePayloadError) Validate() error { - var failures []validate.FieldError if err := func() error { - if s.Code.Set { + if s.ShortBylineText.Set { if err := func() error { - if err := (validate.Float{}).Validate(float64(s.Code.Value)); err != nil { - return errors.Wrap(err, "float") + if err := s.ShortBylineText.Value.Validate(); err != nil { + return err } return nil }(); err != nil { @@ -276,7 +379,25 @@ func (s *ErrorResponsePayloadError) Validate() error { return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "code", + Name: "shortBylineText", + Error: err, + }) + } + if err := func() error { + if s.ShortViewCountText.Set { + if err := func() error { + if err := s.ShortViewCountText.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "shortViewCountText", Error: err, }) } @@ -288,6 +409,9 @@ func (s *ErrorResponsePayloadError) Validate() error { func (s *ItemSectionRenderer) Validate() error { var failures []validate.FieldError if err := func() error { + if s.Contents == nil { + return errors.New("nil is invalid value") + } var failures []validate.FieldError for i, elem := range s.Contents { if err := func() error { @@ -319,6 +443,42 @@ func (s *ItemSectionRenderer) Validate() error { } func (s *ItemSectionRendererContentsItem) Validate() error { var failures []validate.FieldError + if err := func() error { + if s.CompactPlaylistRenderer.Set { + if err := func() error { + if err := s.CompactPlaylistRenderer.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "compactPlaylistRenderer", + Error: err, + }) + } + if err := func() error { + if s.CompactChannelRenderer.Set { + if err := func() error { + if err := s.CompactChannelRenderer.Value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "compactChannelRenderer", + Error: err, + }) + } if err := func() error { if s.CompactVideoRenderer.Set { if err := func() error { @@ -342,14 +502,72 @@ func (s *ItemSectionRendererContentsItem) Validate() error { } return nil } - -func (s *ResponseContext) Validate() error { +func (s *KidsAppContentSettings) Validate() error { var failures []validate.FieldError if err := func() error { - if s.MaxAgeSeconds.Set { + if err := s.CorpusPreference.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "corpusPreference", + Error: err, + }) + } + if err := func() error { + if err := s.KidsNoSearchMode.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "kidsNoSearchMode", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} +func (s KidsAppContentSettingsCorpusPreference) Validate() error { + switch s { + case "KIDS_CORPUS_PREFERENCE_UNKNOWN": + return nil + case "KIDS_CORPUS_PREFERENCE_YOUNGER": + return nil + case "KIDS_CORPUS_PREFERENCE_TWEEN": + return nil + case "KIDS_CORPUS_PREFERENCE_PAM_YOUNGER": + return nil + case "KIDS_CORPUS_PREFERENCE_PAM_TWEEN": + return nil + case "KIDS_CORPUS_PREFERENCE_PRESCHOOL": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} +func (s KidsAppContentSettingsKidsNoSearchMode) Validate() error { + switch s { + case "YT_KIDS_NO_SEARCH_MODE_UNKNOWN": + return nil + case "YT_KIDS_NO_SEARCH_MODE_ON": + return nil + case "YT_KIDS_NO_SEARCH_MODE_OFF": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} +func (s *KidsAppInfo) Validate() error { + var failures []validate.FieldError + if err := func() error { + if s.ContentSettings.Set { if err := func() error { - if err := (validate.Float{}).Validate(float64(s.MaxAgeSeconds.Value)); err != nil { - return errors.Wrap(err, "float") + if err := s.ContentSettings.Value.Validate(); err != nil { + return err } return nil }(); err != nil { @@ -359,7 +577,44 @@ func (s *ResponseContext) Validate() error { return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "maxAgeSeconds", + Name: "contentSettings", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *RequestClient) Validate() error { + var failures []validate.FieldError + if err := func() error { + if err := s.KidsAppInfo.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "kidsAppInfo", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} +func (s *RequestContext) Validate() error { + var failures []validate.FieldError + if err := func() error { + if err := s.Client.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "client", Error: err, }) } @@ -482,41 +737,16 @@ func (s *SectionListRendererContentsItem) Validate() error { } return nil } -func (s *Thumbnail) Validate() error { +func (s *Text) Validate() error { var failures []validate.FieldError if err := func() error { - if s.Width.Set { - if err := func() error { - if err := (validate.Float{}).Validate(float64(s.Width.Value)); err != nil { - return errors.Wrap(err, "float") - } - return nil - }(); err != nil { - return err - } + if s.Runs == nil { + return errors.New("nil is invalid value") } return nil }(); err != nil { failures = append(failures, validate.FieldError{ - Name: "width", - Error: err, - }) - } - if err := func() error { - if s.Height.Set { - if err := func() error { - if err := (validate.Float{}).Validate(float64(s.Height.Value)); err != nil { - return errors.Wrap(err, "float") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "height", + Name: "runs", Error: err, }) }