cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

multipart/form-data arrays with one element are not sent as arrays #316

Open ViacheslavKlavdiiev opened 9 months ago

ViacheslavKlavdiiev commented 9 months ago

ng-openapi-gen v0.51.0

Describe the bug you're encountering When you have a path definition of a multipart/form-data with a schema that contains an array and you pass just one element in this array, the backend receives a single value and not an array with just one element.

Request with one link image

Request with 2 links image

In my case link should be Array with strings

Problem with this function image

Need to add something like this

        for (const key of Object.keys(value)) {
          const val = value[key];
          if (val instanceof Array) {
            val.forEach((v, i) => {
              const toAppend = this.formDataValue(v);
              if (toAppend !== null) {
                formData.append(`${key}[${[i]}]`, toAppend);
              }
            })
          } else {
            const toAppend = this.formDataValue(val);
            if (toAppend !== null) {
              formData.set(key, toAppend);
            }
          }
        }
      }

Request with fix and one link image

Could you please check this issue and provide a decision for my case with 'multipart/form-data' ?

luisfpg commented 1 month ago

Different server-side technologies handle request parameters differently. Having multiple times the same parameter being sent is the same as having an array. Personally, I work with Java in the backend and application servers always work like this. The way request is generated is correct IMHO.