Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9070
Closed
Open
Issue created Mar 24, 2021 by Administrator@rootContributor1 of 1 checklist item completed1/1 checklist item

[BUG] Typescript fetch URLEncoding for nested JSON object

Created by: tusharchutani

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
Description

We have a requirement for passing in a JSON object in a GET url as query string. Currently if we don't provide an option of queryParamsStringify url for a nested query object such as this

{
  "name":"Jordan",
    "address": {
      	"city":"NY",
	    "state":"NY",
    	"house":1002,
	    "st": "wall st"
    }
}

the queryParamsStringify will return this name=Jordan&address[city]=NY&address[state]=NY&address[house]=1002&address[st]=wall st

Now I am not sure if this is a desired result. I am under the impression that address json object should be percent-encoded

and response should be

%7B%22name%22%3A%22Jordan%22%2C%22address%22%3A%7B%22city%22%3A%22NY%22%2C%22state%22%3A%22NY%22%2C%22house%22%3A1002%2C%22st%22%3A%22wall+st%22%7D%7D
openapi-generator version

2.2.0

Suggest a fix

We can change the runtime.ts in our client

export default function querystring(params: any, prefix: string = ''): string {
    return Object.keys(params)
        .map((key) => {
            const fullKey = prefix + (prefix.length ? `[${key}]` : key);
            const value = params[key];
            if (value instanceof Array) {
                const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
                    .join(`&${encodeURIComponent(fullKey)}=`);
                return `${encodeURIComponent(fullKey)}=${multiValue}`;
            }
            if (value instanceof Object) {
                return `${encodeURIComponent(fullKey)}=${encodeURIComponent(JSON.stringify(value))}`;;
            }
            return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
        })
        .filter(part => part.length > 0)
        .join('&');
}

I can make a PR to change the said file

File: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L223

Assignee
Assign to
Time tracking