Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Path parameters were incorrectly serialized when using paramsStructure: 'flat' in the SDK plugin. A call like getServer({ id: '123' }) would generate URL /servers/id,123 instead of /servers/123.

Root Cause

The code generator was passing field configs directly to buildClientParams:

const params = buildClientParams([parameters], [
  { in: 'path', key: 'id' }
]);

This caused buildClientParams to treat the entire parameters object as a positional argument instead of iterating over its properties.

Changes

Modified packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts:

  • Added conditional check for plugin.config.paramsStructure === 'flat'
  • When flat, wrap field configs in an args array to signal object iteration mode
  • Preserve existing behavior for grouped params

Generated code now correctly wraps fields:

const params = buildClientParams([parameters], [
  {
    args: [
      { in: 'path', key: 'id' }
    ]
  }
]);

This tells buildClientParams to iterate over parameters properties and extract individual values, producing correct path parameter serialization.

Original prompt

This section details on the original issue you should resolve

<issue_title>Path parameter incorrectly serialized as /servers/id, instead of /servers/ on paramsStructure flat</issue_title>
<issue_description>### Description

Hi, I encountered an issue when calling (with paramsStructure flat) a generated GET method.
The request path is incorrectly serialized as:
/servers/id,1335279038599663729

But it should be:
/servers/1335279038599663729

This looks like the {id} placeholder is not replaced properly and the value is appended with a comma.

Let me know if you need any further details or if I can provide additional logs or config.

Reproducible example or configuration

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
	input: './scripts/openapi-spec.json',
	output: { path: './src/api/client', importFileExtension: '.js' },
	plugins: [
		'@hey-api/schemas',
		{
			name: '@hey-api/typescript',
			topType: "any",
			enums: {
				case: 'preserve',
				enabled: true,
				mode: 'typescript'
			}
		},
		{
			name: '@hey-api/sdk',
			asClass: true,
			responseStyle: 'data',
			paramsStructure: 'flat',
			classNameBuilder: (name) => `${name}Service`
		}
	]
});

OpenAPI specification (optional)

    "/servers/{id}": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IServer"
                }
              }
            }
          }
        },
        "tags": [
          "Servers"
        ],
        "security": [],
        "operationId": "GetServer"
      },

System information (optional)

@hey-api/openapi-ts: 0.87.5</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Nov 15, 2025

⚠️ No Changeset found

Latest commit: f040aef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Nov 15, 2025 2:58am

When using paramsStructure: 'flat' with the SDK plugin, path parameters were being incorrectly serialized. The issue was that buildClientParams was treating the flat parameters object as a positional argument instead of iterating over its properties.

Fixed by wrapping field configs in an args array when paramsStructure is 'flat', which tells buildClientParams to iterate over the flattened object properties instead of treating the entire object as a single positional argument.

Co-authored-by: mrlubos <[email protected]>
Copilot AI changed the title [WIP] Fix path parameter serialization issue in GET method Fix path parameter serialization with flat params structure Nov 15, 2025
Copilot AI requested a review from mrlubos November 15, 2025 03:01
Copilot finished work on behalf of mrlubos November 15, 2025 03:01
@fiftyy
Copy link

fiftyy commented Nov 15, 2025

Generated code now correctly wraps fields:

const params = buildClientParams([parameters], [
  {
    args: [
      { in: 'path', key: 'id' }
    ]
  }
]);

This tells buildClientParams to iterate over parameters properties and extract individual values, producing correct path parameter serialization.

Tested it by replacing my function with this. Works good.

@fiftyy
Copy link

fiftyy commented Nov 15, 2025

Can we trigger a test build with pkg-pr-new bot? @mrlubos

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.

Path parameter incorrectly serialized as /servers/id,<id> instead of /servers/<id> on paramsStructure flat

3 participants