Skip to content

Commit

Permalink
🐛 Make sure that paginators are aliased to pagination.IStaticPage e…
Browse files Browse the repository at this point in the history
…tc. as the mappers were not enough (#43)

<!--
Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors.
All rights reserved.
SPDX-License-Identifier: Proprietary
-->
### Description

<!--
Please add any detail or context that would be useful to a reviewer.
-->

Make sure that paginators are aliased to `pagination.IStaticPage` etc.
as the mappers were not enough. It was impossible to cast between the
mapped struct and the various structs we want to map between due to type
mismatches between `client.IStaticPage` and `pagination.IStaticPage`.
This is the simplest solution.

### Test Coverage

<!--
Please put an `x` in the correct box e.g. `[x]` to indicate the testing
coverage of this change.
-->

- [x]  This change is covered by existing or additional automated tests.
- [ ] Manual testing has been performed (and evidence provided) as
automated testing was not feasible.
- [ ] Additional tests are not required for this change (e.g.
documentation update).

---------

Co-authored-by: joshjennings98 <[email protected]>
Co-authored-by: Adrien CABARBAYE <[email protected]>
  • Loading branch information
3 people committed May 22, 2024
1 parent 96d3644 commit 79bc018
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 364 deletions.
1 change: 1 addition & 0 deletions changes/20240508103622.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:bug: Make sure that paginators are aliased to pagination.IStaticPage etc. as the mappers were not enough
1 change: 1 addition & 0 deletions changes/20240516125141.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated client due to schema changes
1 change: 1 addition & 0 deletions changes/20240516125941.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated client due to schema changes
1 change: 1 addition & 0 deletions changes/20240516135153.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated client due to schema changes
124 changes: 124 additions & 0 deletions client/extension_entities.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,130 @@ func NewNotificationMessageIterator(elements []NotificationMessageObject) (IIter
}, nil
}

// ============================================================================================
// This extends BuildMessageItem definitions
// ============================================================================================

// FetchType returns the resource type
func (o *BuildMessageItem) FetchType() string {
return "Notification messages"
}

// FetchLinks returns the resource links if present
func (o *BuildMessageItem) FetchLinks() (links any, err error) {
if !o.Links.IsSet() {
err = errors.New("missing links")
return
}
links = o.GetLinks()
return
}

// FetchName returns the resource name if present, or else an error
func (o *BuildMessageItem) FetchName() (string, error) {
return o.GetName(), nil
}

// FetchTitle returns the resource title if present, or else an error
func (o *BuildMessageItem) FetchTitle() (string, error) {
return o.GetTitle(), nil
}

func (o *BuildMessageItem) HasNext() bool {
if links, has := o.GetLinksOk(); has {
return links.HasNext()
}
return false
}

func (o *BuildMessageItem) HasFuture() bool {
if links, has := o.GetLinksOk(); has {
return links.HasFuture()
}
return false
}

func (o *BuildMessageItem) GetItemIterator() (IIterator, error) {
return NewMessageIterator(o.GetMessages())
}

func (o *BuildMessageItem) GetItemCount() (count int64, err error) {
m, ok := o.GetMetadataOk()
if !ok {
err = fmt.Errorf("missing metadata: %v", o)
return
}
count = int64(m.GetCount())
return
}

// NewBuildMessageItemMessageStream returns a message stream.
func NewBuildMessageItemMessageStream() IMessageStream {
return NewBuildMessageItemWithDefaults()
}

// ============================================================================================
// This extends IntellisenseMessageItem definitions
// ============================================================================================

// FetchType returns the resource type
func (o *IntellisenseMessageItem) FetchType() string {
return "Notification messages"
}

// FetchLinks returns the resource links if present
func (o *IntellisenseMessageItem) FetchLinks() (links any, err error) {
if !o.Links.IsSet() {
err = errors.New("missing links")
return
}
links = o.GetLinks()
return
}

// FetchName returns the resource name if present, or else an error
func (o *IntellisenseMessageItem) FetchName() (string, error) {
return o.GetName(), nil
}

// FetchTitle returns the resource title if present, or else an error
func (o *IntellisenseMessageItem) FetchTitle() (string, error) {
return o.GetTitle(), nil
}

func (o *IntellisenseMessageItem) HasNext() bool {
if links, has := o.GetLinksOk(); has {
return links.HasNext()
}
return false
}

func (o *IntellisenseMessageItem) HasFuture() bool {
if links, has := o.GetLinksOk(); has {
return links.HasFuture()
}
return false
}

func (o *IntellisenseMessageItem) GetItemIterator() (IIterator, error) {
return NewMessageIterator(o.GetMessages())
}

func (o *IntellisenseMessageItem) GetItemCount() (count int64, err error) {
m, ok := o.GetMetadataOk()
if !ok {
err = fmt.Errorf("missing metadata: %v", o)
return
}
count = int64(m.GetCount())
return
}

// NewIntellisenseMessageItemMessageStream returns a message stream.
func NewIntellisenseMessageItemMessageStream() IMessageStream {
return NewIntellisenseMessageItemWithDefaults()
}

// ============================================================================================
// This extends NotificationFeed definitions
// ============================================================================================
Expand Down
19 changes: 4 additions & 15 deletions client/extension_model_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// It includes the definition of request/response types as well as provides helpers for calling specific helpers.
package client

import "github.com/ARM-software/golang-utils/utils/collection/pagination"

// *************************************************************************************
// NOTE: this file is not generated.
// It defines generic models.
Expand All @@ -25,22 +27,9 @@ type IModel interface {

// The following definitions match what is in golang-utils for [pagination](https://github.com/ARM-software/golang-utils/blob/master/utils/collection/pagination/interfaces.go)

type IIterator interface {
// HasNext returns whether there are more items available or not.
HasNext() bool
// GetNext returns the next item.
GetNext() (interface{}, error)
}
type IIterator = pagination.IIterator

// IStaticPage defines a generic page for a collection.
type IStaticPage interface {
// HasNext states whether more pages are accessible.
HasNext() bool
// GetItemIterator returns a new iterator over the page's items.
GetItemIterator() (IIterator, error)
// GetItemCount returns the number of items in this page
GetItemCount() (int64, error)
}
type IStaticPage = pagination.IStaticPage

// IMessageStream defines a page for a collection which does not have any known ending.
type IMessageStream interface {
Expand Down
60 changes: 0 additions & 60 deletions client/extension_model_interface_mappers.go

This file was deleted.

102 changes: 0 additions & 102 deletions client/extension_model_interface_mappers_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/ARM-software/golang-utils/utils v1.63.0
github.com/go-faker/faker/v4 v4.4.1
github.com/stretchr/testify v1.9.0
)

Expand All @@ -15,6 +14,5 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/text v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 0 additions & 4 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/Sqc
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-faker/faker/v4 v4.4.1 h1:LY1jDgjVkBZWIhATCt+gkl0x9i/7wC61gZx73GTFb+Q=
github.com/go-faker/faker/v4 v4.4.1/go.mod h1:HRLrjis+tYsbFtIHufEPTAIzcZiRu0rS9EYl2Ccwme4=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand All @@ -18,8 +16,6 @@ go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Loading

0 comments on commit 79bc018

Please sign in to comment.