Skip to content

Enhancement: Add input validation for API client methods #14

@rbansal42

Description

@rbansal42

Overview

API client methods don't validate that required parameters are non-empty before making API calls. This leads to confusing API errors instead of clear validation messages.

Affected Methods

Workspaces API (internal/api/workspaces.go)

  • GetWorkspace(ctx, workspaceSlug) - workspaceSlug could be empty
  • ListWorkspaceMembers(ctx, workspaceSlug, opts) - workspaceSlug could be empty

Projects API (internal/api/projects.go)

  • ListProjects(ctx, workspaceSlug, opts)
  • GetProject(ctx, workspaceSlug, projectKey)
  • CreateProject(ctx, workspaceSlug, opts)
  • UpdateProject(ctx, workspaceSlug, projectKey, opts)
  • DeleteProject(ctx, workspaceSlug, projectKey)

Branches API (internal/api/branches.go)

  • ListBranches(ctx, workspace, repoSlug, opts)
  • GetBranch(ctx, workspace, repoSlug, branchName)
  • CreateBranch(ctx, workspace, repoSlug, opts)
  • DeleteBranch(ctx, workspace, repoSlug, branchName)

Also in existing code (internal/api/repositories.go)

  • Same pattern exists in repository methods

Proposed Solution

Add validation at the start of each method:

func (c *Client) GetProject(ctx context.Context, workspaceSlug, projectKey string) (*ProjectFull, error) {
    if workspaceSlug == "" {
        return nil, fmt.Errorf("workspaceSlug is required")
    }
    if projectKey == "" {
        return nil, fmt.Errorf("projectKey is required")
    }
    // ... rest of method
}

Benefits

  • Clear error messages for invalid input
  • Fail fast before making network request
  • Easier debugging

Acceptance Criteria

  • Add validation for all API methods with required parameters
  • Add test cases for validation errors
  • Consistent error message format

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions