Skip to content

Array-typed query parameters are incorrectly expanded #643

@nuthanmunaiah

Description

@nuthanmunaiah

VsoClient.queryParamsToStringHelper is incorrectly expanding array-typed query parameters. Query parameters of type string[] must be expanded such that the query parameter name is repeated for each value in the array-typed value. For instance, to filter commits in Commits - Get Commits endpoint, searchCriteria.ids must be specified for each commit to be filtered. However, when using IGitApi.getCommits, the URL that gets generated when searchCriteria.ids is specified has a .n appended to the name of the query string parameter (where n is the index of the value in the searchCriteria.ids). For example, searchCriteria.ids.0=e7514f6eb6d7b0a159b8c9059fcfc9cf53e57c02&searchCriteria.ids.1=d35a7a4f31b2d72eadb2e87f9808c88647b6087d is the query string parameter string that gets generated when two commit identifiers are specified in searchCriteria.ids As a result, the filtering is broken because query parameters with .n in the name are ignored by the service.


Demonstration

import { getPersonalAccessTokenHandler, WebApi } from "./WebApi";
import { GitQueryCommitsCriteria } from "./interfaces/GitInterfaces";

async function main() {
  const token = process.env.AZURE_DEVOPS_PAT || "";
  const handler = getPersonalAccessTokenHandler(token);
  const webApi = new WebApi("https://dev.azure.com/organization/", handler);
  const gitApi = await webApi.getGitApi();
  
  const repository = await gitApi.getRepository("project", "repository");
  if (repository?.id) {
    var searchCriteria: GitQueryCommitsCriteria = {
      ids: [
        "e7514f6eb6d7b0a159b8c9059fcfc9cf53e57c02",
        "d35a7a4f31b2d72eadb2e87f9808c88647b6087d",
      ],
    };
    var commits = await gitApi.getCommits(repository.id, searchCriteria);
    console.log(`# Commits: ${commits.length}`);
    console.log("5 Most Recent Commits\n");
    commits.slice(0, 5).forEach((commit, idx) => {
      console.log(`  ${idx + 1}. ${commit.commitId}`);
    });
  }
}

main();

Output

searchCriteria.ids is expected to filter the commits to only those specified but, as shown in the output below, 100 commits (the default number of commits) are returned.

$ npx ts-node api/scratch.ts
# Commits: 100
5 Most Recent Commits

  1. e7514f6eb6d7b0a159b8c9059fcfc9cf53e57c02
  2. d35a7a4f31b2d72eadb2e87f9808c88647b6087d
  3. 97e6de8b8dc8edcbe0477d2520d31c7502e2034f
  4. 5af4f0554285b7c89c54bf6c8ddf5620203c8b09
  5. 7157c2513b3ef1585326f589cbdbc34f279cf13d

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions