[BUG] multipart/form-data parameters can conflict with other parameters
Created by: alexrashed
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
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?
Description
When using the content type "multipart/form-data", the form parameters are not encapsulated in a generated model interface - as it is for all other content types - but they are added to the list of parameters. However, their parameter names are not being checked if they may collide with an existing parameter. This allows form parameters to conflict with other parameters (like path, query, header, or cookie params).
openapi-generator version
4.3.1 + master
OpenAPI declaration file content or url
Generation Details
I am facing this issue with the following arguments (but it should affect most or all languages):
generatorName: typescript-angular
outputDir: generated
inputSpec: input/openapi-generator-form-param-issue.json
additionalProperties:
ngVersion: 10.0.0
useSingleRequestParameter: true
Steps to reproduce
Run the generator with the provided OpenAPI spec file:
java -jar .\openapi-generator-cli.jar generate --config .\config.yaml
The resulting TypeScript code does not compile (since it defines the duplicated parameter as a variable twice).
Actual output:
...
export interface FormParamPocUpdateRequestParams {
id: number;
id?: number;
}
...
public formParamPocUpdate(requestParameters: FormParamPocUpdateRequestParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined}): Observable<any> {
const id = requestParameters.id;
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling formParamPocUpdate.');
}
const id = requestParameters.id;
...
Expected output:
...
export interface FormParamPocUpdateRequestParams {
id: number;
id2?: number;
}
...
public formParamPocUpdate(requestParameters: FormParamPocUpdateRequestParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined}): Observable<any> {
const id = requestParameters.id;
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling formParamPocUpdate.');
}
const id2 = requestParameters.id2;
...
Suggest a fix
This code section is missing the check if the parameter is unique (as it is done a few lines above).
PR
I'm on to create a PR for the fix.