diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index dbc3ee854bdc..a13db5121fb6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3856,10 +3856,20 @@ public CodegenOperation fromOperation(String path, // add form/body parameter (if any) to the end of all parameter list if (!prependFormOrBodyParameters) { for (CodegenParameter cp : formParams) { + if (ensureUniqueParams) { + if (!isParameterNameUnique(cp, allParams)) { + cp.paramName = generateNextName(cp.paramName); + } + } allParams.add(cp.copy()); } for (CodegenParameter cp : bodyParams) { + if (ensureUniqueParams) { + if (!isParameterNameUnique(cp, allParams)) { + cp.paramName = generateNextName(cp.paramName); + } + } allParams.add(cp.copy()); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 4be29a74cb99..1d3ab8c22e95 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -409,6 +409,20 @@ public void testConsistentParameterNameAfterUniquenessRename() throws Exception Assert.assertTrue(queryParamsNames.contains("myparam2")); } + @Test + public void testUniquenessRenameOfFormParameters() throws Exception { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/form-duplicated-parameter.yaml"); + DefaultCodegen codegen = new DefaultCodegen(); + codegen.setOpenAPI(openAPI); + Operation operation = openAPI.getPaths().get("/form-param-poc/{id}").getPut(); + CodegenOperation co = codegen.fromOperation("/form-param-poc/{id}", "put", operation, null); + Assert.assertEquals(co.path, "/form-param-poc/{id}"); + Assert.assertEquals(co.allParams.size(), 2); + List allParamsNames = co.allParams.stream().map(p -> p.paramName).collect(Collectors.toList()); + Assert.assertTrue(allParamsNames.contains("id")); + Assert.assertTrue(allParamsNames.contains("id2")); + } + @Test public void testGetSchemaTypeWithComposedSchemaWithOneOf() { final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/composed-oneof.yaml"); diff --git a/modules/openapi-generator/src/test/resources/3_0/form-duplicated-parameter.yaml b/modules/openapi-generator/src/test/resources/3_0/form-duplicated-parameter.yaml new file mode 100644 index 000000000000..86f2189eda49 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/form-duplicated-parameter.yaml @@ -0,0 +1,50 @@ +openapi: 3.0.1 +info: + title: FormData Test Api Documentation + description: Minimal OpenAPI spec file to showcase duplicated params for formData. + version: 0.0.1 +servers: + - url: /backend/rest +tags: + - name: form-param-poc + description: File storage resource for Fiscalization France standard +paths: + '/form-param-poc/{id}': + put: + tags: + - form-param-poc + summary: fullUpdate + operationId: form-param-poc_update + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/FormParameters' + responses: + '200': + description: OK. + security: + - oAuthConfig: [] +components: + schemas: + FormParameters: + type: object + properties: + id: + type: integer + format: int64 + readOnly: true + securitySchemes: + oAuthConfig: + type: oauth2 + flows: + implicit: + authorizationUrl: ../backend/login/openid + scopes: {}