OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] Incorrect handling of arbitrary query parameters via `style: form` + `explode: true`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When an API endpoint specifies a combination of style: form and explode: true, it should generate code that handles adding query parameters exactly as they are and not nest them under the additionalProperties field; i.e., the URL used should be
http://api.example.com/v1/users?hello=world&foo=bar&additionalProp3=string
but the generated code generates this URL,
http://api.example.com/v1/users?additionalProperties[hello]=world&additionalProperties[foo]=bar&additionalProperties[additionalProp3]=string
This is the generated code block that causes the problem,
async usersGetRaw(requestParameters: UsersGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<object>> {
const queryParameters: any = {};
if (requestParameters['additionalProperties'] != null) {
// this line,
queryParameters['additionalProperties'] = requestParameters['additionalProperties'];
// should be this instead (potentially)
queryParameters = requestParameters['additionalProperties'];
}
const headerParameters: runtime.HTTPHeaders = {};
const response = await this.request({
path: `/users`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
return new runtime.JSONApiResponse<any>(response);
}
openapi-generator version
7.17.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 1.0.0
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/users:
get:
summary: Returns a list of users.
description: Optional extended description in CommonMark or HTML.
parameters:
- in: query
name: additionalProperties
description: Allow arbitrary key name and values to be included as query parameters in the share-url.
style: form
explode: true
schema:
type: object
additionalProperties:
type: string
responses:
"200": # status code
description: A JSON array of user names
content:
application/json:
schema:
type: object
Generation Details
No configuration file needed to reproduce this problem
Steps to reproduce
docker run --rm \
-v ".:/local" \
openapitools/openapi-generator-cli:latest generate \
-g "typescript-fetch" \
-i "/local/openapi.yml" \
-o /local/src
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenAPI YAML in the issue and run the provided Docker typescript-fetch generation command. Inspect the generated usersGetRaw method and its query construction; done means the arbitrary object properties produce flat query parameters such as hello=world and foo=bar, rather than additionalProperties[...] keys.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100