Skip to content

Conversation

@justinpolygon
Copy link
Collaborator

@justinpolygon justinpolygon commented Dec 5, 2025

This PR addresses a bug in the client-js library where API function signatures were generated with positional parameters (it the openapi-generator-cli default), leading to cluttered function calls, especially for endpoints with many optional parameters. This mismatched user expectations and the documented examples, forcing developers to pass explicit undefined values for skipped optional params. Positional parameters are the default for how openapi-generator-cli generate the library and this went unnoticed for a long time since the example endpoints I was using to test/verify the library did not contain enough optional parameters.

Before (Buggy Behavior):
API methods accepted individual positional arguments for each parameter (e.g., path, query, header, body). For endpoints with numerous optional params, this resulted in verbose calls where developers had to list out all params in order, using undefined as placeholders for unused ones.

Example (from MASS-579 report):

import { restClient } from '@massive.com/client-js';

const apiKey = "XXXXX";
const rest = restClient(apiKey, 'https://api.massive.com');

async function example_listTickers() {
  try {
    const response = await rest.listTickers(
      undefined,
      undefined,
      market,
      undefined,
      undefined,
      undefined,
      undefined,
      search,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      undefined,
      limit
    );
    console.log('Response:', response);
  } catch (e) {
    console.error('An error happened:', e);
  }
}

example_listTickers();

This was cumbersome and did not align with the intuitive, object-based usage shown in examples.

After (Fixed Behavior):
By adding useSingleRequestParameter=true to the OpenAPI generator command for the typescript-axios target, all request parameters are now bundled into a single required object (e.g., requestParameters). This cleans up the function signatures, making them more readable and flexible. Developers can pass only the needed properties in a named object, with optional ones omitted.

Updated generator command:

openapi-generator-cli generate -g typescript-axios -o $CLIENT_DIRECTORY -i ./src/openapi.json -t ./templates/typescript-axios --additional-properties=supportsES6=true,stringEnums=true,useSingleRequestParameter=true

Example (expected and now working usage):

import { restClient } from '@massive.com/client-js';

const apiKey = "XXXXX";
const rest = restClient(apiKey, 'https://api.massive.com');

async function example_listTickers() {
  try {
    const response = await rest.listTickers({
      market: "stocks",
      active: "true",
      order: "asc",
      limit: "100",
      sort: "ticker"
    });
    console.log('Response:', response);
  } catch (e) {
    console.error('An error happened:', e);
  }
}

example_listTickers();

Impact and Release Plan:
This is a breaking change as it alters all API function signatures across the library. The developer impact is significant, requiring updates to existing codebases, but it better matches expectations and improves usability. We will release this as a major version bump to v10.x to signal the breakage.

Testing:

  • Regenerated/installed the client and verified function signatures in key endpoints (e.g., listTickers). I tested most of the current code examples across the website and this works as expected.
  • Ran example calls to confirm the single object parameter works as expected.
  • Ensured no regressions in core functionality.

This change brings the library in line with modern TypeScript practices and reduces friction for users.

@justinpolygon justinpolygon changed the title Fix API function signatures to use single request parameter object (MASS-579) [MASS-579] Fix API function signatures to use single request parameter object Dec 5, 2025
Copy link
Collaborator

@tharnach tharnach left a comment

Choose a reason for hiding this comment

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

🚀

@justinpolygon justinpolygon merged commit f69b126 into master Dec 8, 2025
3 checks passed
@justinpolygon justinpolygon deleted the fix/MASS-579-single-request-parameter branch December 8, 2025 17:10
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.

3 participants