Skip to content

feat: add 'team' schema'#552

Open
leecalcote wants to merge 1 commit intomasterfrom
schemas/team
Open

feat: add 'team' schema'#552
leecalcote wants to merge 1 commit intomasterfrom
schemas/team

Conversation

@leecalcote
Copy link
Copy Markdown
Member

Signed-off-by: Lee Calcote lee.calcote@layer5.io

Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @leecalcote, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new 'team' schema to the project, enabling the definition and management of team-related entities, including team details, payloads for creation/updates, and mappings to organizations and users. This foundational change supports future features requiring team-based access control and organization. Alongside this, the PR updates Go module dependencies to accommodate the new schema's requirements and regenerates existing OpenAPI-generated Go models due to an 'oapi-codegen' version upgrade.

Highlights

  • New Team Schema Introduction: A comprehensive 'team' schema has been added, defining structures for Team entities, payloads, and mappings between teams, organizations, and users. This includes Go models, OpenAPI definitions, and a JSON template.
  • Go Module Dependency Updates: New Go dependencies, 'github.com/gobuffalo/nulls' and 'github.com/gobuffalo/pop', have been introduced to support the new schema's data handling requirements.
  • OpenAPI Codegen Version Bump: The 'oapi-codegen' tool version has been updated from 'v2.4.1' to 'v2.5.1', leading to the regeneration of various existing Go model files across different API versions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new 'team' schema, including the OpenAPI specification, generated Go models, and associated tests. The changes are well-structured. I've identified a few areas for improvement:

  • It is critical to run go mod tidy after changes to go.mod to ensure module consistency, as per repository rules.
  • The new OpenAPI specification for the team API has some design inconsistencies, such as incorrect response types for several endpoints and non-standard JSON field naming.
  • The new tests could be more comprehensive to ensure full coverage of the new data structures.

My detailed comments provide specific suggestions to address these points.

Comment on lines +6 to +7
github.com/gobuffalo/nulls v0.4.2
github.com/gobuffalo/pop v4.13.1+incompatible
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Running go mod tidy is a mandatory step, especially after changes to go.mod, to ensure module consistency and proper dependency management. This aligns with the rule that go mod tidy must be run after updating the Go version in go.mod.

References
  1. After updating the Go version in go.mod, go mod tidy must be run.

Comment on lines +286 to +291
"201":
description: Created team
content:
application/json:
schema:
$ref: "#/components/schemas/teamsPage"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Several endpoints in this API definition are returning page schemas (e.g., teamsPage, usersTeamsMappingPage) for operations that should return a single resource. This is unconventional for a RESTful API and can be confusing for clients.

For example:

  • POST /api/identity/orgs/{orgId}/teams (createTeam) should return the created team object, not a teamsPage.
  • GET /api/identity/orgs/{orgId}/teams/{teamId} (getTeamById) should return a single team object, not a teamsPage.
  • PUT /api/identity/orgs/{orgId}/teams/{teamId} (updateTeam) should return the updated team object, not a teamsPage.
  • DELETE /api/identity/orgs/{orgId}/teams/{teamId} (deleteTeam) should return the deleted team object or a 204 No Content response, not a teamsPage.
  • POST /api/identity/orgs/{orgId}/teams/{teamId}/users/{userId} (addUserToTeam) should return the created usersTeamsMapping object, not a usersTeamsMappingPage.
  • DELETE /api/identity/orgs/{orgId}/teams/{teamId}/users/{userId} (removeUserFromTeam) should return the removed usersTeamsMapping object or a 204 No Content response, not a usersTeamsMappingPage.

Please review these endpoints and adjust their response schemas to return single resource objects where appropriate.

        "201":
          description: Created team
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/team"

Comment on lines +13 to +49
func TestTeamSerialization(t *testing.T) {
teamID := uuid.Must(uuid.NewV4())
ownerID := uuid.Must(uuid.NewV4())
now := time.Now()

team := Team{
ID: teamID,
Name: "Test Team",
Description: "A test team description",
Owner: ownerID,
Metadata: nil,
CreatedAt: now,
UpdatedAt: now,
DeletedAt: sql.NullTime{},
}

// Test JSON serialization
jsonBytes, err := json.Marshal(team)
if err != nil {
t.Fatalf("Failed to marshal Team to JSON: %v", err)
}

var unmarshaled Team
if err := json.Unmarshal(jsonBytes, &unmarshaled); err != nil {
t.Fatalf("Failed to unmarshal Team from JSON: %v", err)
}

if unmarshaled.ID != team.ID {
t.Errorf("ID mismatch: got %v, want %v", unmarshaled.ID, team.ID)
}
if unmarshaled.Name != team.Name {
t.Errorf("Name mismatch: got %v, want %v", unmarshaled.Name, team.Name)
}
if unmarshaled.Owner != team.Owner {
t.Errorf("Owner mismatch: got %v, want %v", unmarshaled.Owner, team.Owner)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The serialization tests are a great start! However, they only verify a subset of the fields in the structs. This could lead to undetected serialization issues if other fields are changed in the future.

To make the tests more robust, I recommend using assert.Equal from the github.com/stretchr/testify/assert package to compare the entire original struct with the unmarshaled one. This ensures all fields are correctly serialized and deserialized.

For time.Time fields, you might need to use assert.True(t, team.CreatedAt.Equal(unmarshaled.CreatedAt)) to handle potential timezone or precision differences after JSON marshaling.

This principle also applies to TestTeamPayloadSerialization and TestTeamsPageSerialization.

func TestTeamSerialization(t *testing.T) {
	teamID := uuid.Must(uuid.NewV4())
	ownerID := uuid.Must(uuid.NewV4())
	now := time.Now().UTC().Truncate(time.Second) // Use UTC and truncate for consistency

	team := Team{
		ID:          teamID,
		Name:        "Test Team",
		Description: "A test team description",
		Owner:       ownerID,
		Metadata:    nil,
		CreatedAt:   now,
		UpdatedAt:   now,
		DeletedAt:   sql.NullTime{},
	}

	// Test JSON serialization
	jsonBytes, err := json.Marshal(team)
	assert.NoError(t, err, "Failed to marshal Team to JSON")

	var unmarshaled Team
	err = json.Unmarshal(jsonBytes, &unmarshaled)
	assert.NoError(t, err, "Failed to unmarshal Team from JSON")

	// Compare time fields separately to avoid timezone/precision issues
	assert.True(t, team.CreatedAt.Equal(unmarshaled.CreatedAt))
	assert.True(t, team.UpdatedAt.Equal(unmarshaled.UpdatedAt))

	// Set time fields to be the same before comparing the whole struct
	unmarshaled.CreatedAt = team.CreatedAt
	unmarshaled.UpdatedAt = team.UpdatedAt

	assert.Equal(t, team, unmarshaled)
}

x-go-name: ID
x-oapi-codegen-extra-tags:
db: id
json: ID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSON tag for id is ID. It is a common convention in Go to use lowercase camelCase (like id) for JSON keys for consistency. I recommend using "id".

            json: "id"

x-go-name: ID
x-oapi-codegen-extra-tags:
db: id
json: ID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSON tag for id is ID. It is a common convention in Go to use lowercase camelCase (like id) for JSON keys for consistency. I recommend using "id".

            json: "id"

@hortison hortison requested a review from aabidsofi19 January 13, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant