Skip to content

Commit

Permalink
Update UserTeamIncluded to include teams (#2482)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Apr 26, 2024
1 parent f692d34 commit bc3149e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-23 18:21:34.263127",
"spec_repo_commit": "50a32b2b"
"regenerated": "2024-04-25 19:06:48.200292",
"spec_repo_commit": "6c17af3e"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-23 18:21:34.280620",
"spec_repo_commit": "50a32b2b"
"regenerated": "2024-04-25 19:06:48.217920",
"spec_repo_commit": "6c17af3e"
}
}
}
1 change: 1 addition & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22472,6 +22472,7 @@ components:
description: Included resources related to the team membership
oneOf:
- $ref: '#/components/schemas/User'
- $ref: '#/components/schemas/Team'
UserTeamPermission:
description: A user's permissions for a given team
properties:
Expand Down
32 changes: 32 additions & 0 deletions api/datadogV2/model_user_team_included.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// UserTeamIncluded - Included resources related to the team membership
type UserTeamIncluded struct {
User *User
Team *Team

// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject interface{}
Expand All @@ -21,6 +22,11 @@ func UserAsUserTeamIncluded(v *User) UserTeamIncluded {
return UserTeamIncluded{User: v}
}

// TeamAsUserTeamIncluded is a convenience function that returns Team wrapped in UserTeamIncluded.
func TeamAsUserTeamIncluded(v *Team) UserTeamIncluded {
return UserTeamIncluded{Team: v}
}

// UnmarshalJSON turns data into one of the pointers in the struct.
func (obj *UserTeamIncluded) UnmarshalJSON(data []byte) error {
var err error
Expand All @@ -42,9 +48,27 @@ func (obj *UserTeamIncluded) UnmarshalJSON(data []byte) error {
obj.User = nil
}

// try to unmarshal data into Team
err = datadog.Unmarshal(data, &obj.Team)
if err == nil {
if obj.Team != nil && obj.Team.UnparsedObject == nil {
jsonTeam, _ := datadog.Marshal(obj.Team)
if string(jsonTeam) == "{}" { // empty struct
obj.Team = nil
} else {
match++
}
} else {
obj.Team = nil
}
} else {
obj.Team = nil
}

if match != 1 { // more than 1 match
// reset to nil
obj.User = nil
obj.Team = nil
return datadog.Unmarshal(data, &obj.UnparsedObject)
}
return nil // exactly one match
Expand All @@ -56,6 +80,10 @@ func (obj UserTeamIncluded) MarshalJSON() ([]byte, error) {
return datadog.Marshal(&obj.User)
}

if obj.Team != nil {
return datadog.Marshal(&obj.Team)
}

if obj.UnparsedObject != nil {
return datadog.Marshal(obj.UnparsedObject)
}
Expand All @@ -68,6 +96,10 @@ func (obj *UserTeamIncluded) GetActualInstance() interface{} {
return obj.User
}

if obj.Team != nil {
return obj.Team
}

// all schemas are nil
return nil
}

0 comments on commit bc3149e

Please sign in to comment.