Repository: OpenAPITools/openapi-generator (language: python)

Issue:
[BUG] [JAVA] allOf object are not correctly generated with properties REF_AS_PARENT_IN_ALLOF=true and REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true
#### Bug Report Checklist

- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator ([example](https://apidevtools.org/swagger-parser/online/))?
- [x] Have you [tested with the latest master](https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-to-test-with-the-latest-master-of-openapi-generator) to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?

##### Description

Since release of 7.9.0 allOf objects don´t extend the parent anymore when normalizer REF_AS_PARENT_IN_ALLOF=true and REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true are used.

I expect the child object extends the parent object which works as expected until 7.9.0. Below generated code from 7.8.0:
```java
public class Child1 extends Parent {
...
}
```

below code is generated code from 7.9.0

```java
public class Child1 {
...
}
```

##### openapi-generator version

7.9.0

##### OpenAPI declaration file content or url
test.yaml
```yaml
openapi: 3.0.0
info:
  title: 'AllOf does not work'
  description: 'Minimal yaml to showcase allOf does not work anymore'
  version: info
paths:
  /allOf:
    get:
      operationId: allOf
      responses:
        "200":
          description: oke
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Parent'
components:
  schemas:
    Parent:
      type: object
      properties:
        p1:
          type: integer
    Child1:
      properties:
        p2:
          type: string
      allOf:
        - $ref: '#/components/schemas/Parent'

```

##### Generation Details

I'm using the openapi-generator-maven-plugin

```xml
<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.9.0</version>
                <configuration>
                    <openapiNormalizer>REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true</openapiNormalizer>
                    <generatorName>spring</generatorName>
                    <configOptions>
                        <useSpringBoot3>true</useSpringBoot3>
                        <interfaceOnly>true</interfaceOnly>
                    </configOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>allOf</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${basedir}/src/main/resources/openapi/Showcase.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <generateSupportingFiles>true</generateSupportingFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
```

##### Steps to reproduce
java -jar openapi-generator-cli.jar generate -g spring -i test.yaml -o output/ --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true




Discussion / hints:
thanks for reporting the issue. i will try to take a look over the weekend


Fix patch:
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java
index 6776414d2b10..788e74c42ec1 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java
@@ -755,6 +755,9 @@ private Schema normalizeAllOfWithProperties(Schema schema, Set<Schema> visitedSc
             return schema;
         }
 
+        // process rule to refactor properties into allOf sub-schema
+        schema = processRefactorAllOfWithPropertiesOnly(schema);
+
         for (Object item : schema.getAllOf()) {
             if (!(item instanceof Schema)) {
                 throw new RuntimeException("Error! allOf schema is not of the type Schema: " + item);
@@ -762,8 +765,6 @@ private Schema normalizeAllOfWithProperties(Schema schema, Set<Schema> visitedSc
             // normalize allOf sub schemas one by one
             normalizeSchema((Schema) item, visitedSchemas);
         }
-        // process rules here
-        schema = processRefactorAllOfWithPropertiesOnly(schema);
 
         return schema;
     }
@@ -1325,9 +1326,8 @@ private Schema processRefactorAllOfWithPropertiesOnly(Schema schema) {
         schema.setTitle(null);
 
         // at this point the schema becomes a simple allOf (no properties) with an additional schema containing
-        // the properties
-
-        return schema;
+        // the properties. Normalize it before returning.
+        return normalizeSchema(schema, new HashSet<>());
     }
 
     /**


Test patch:
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java
index f8a4c15c8804..c7713234d74a 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java
@@ -56,6 +56,30 @@ public void testOpenAPINormalizerRefAsParentInAllOf() {
         assertEquals(schema5.getExtensions().get("x-parent"), "abstract");
     }
 
+    @Test
+    public void testOpenAPINormalizerRefAsParentInAllOfAndRefactorAllOfWithProperties() {
+        // to test the both REF_AS_PARENT_IN_ALLOF and REFACTOR_ALLOF_WITH_PROPERTIES_ONLY
+        OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOf_extension_parent.yaml");
+
+        Schema schema = openAPI.getComponents().getSchemas().get("Child");
+        assertNull(schema.getExtensions());
+
+        Schema schema2 = openAPI.getComponents().getSchemas().get("Ancestor");
+        assertNull(schema2.getExtensions());
+
+        Map<String, String> options = new HashMap<>();
+        options.put("REF_AS_PARENT_IN_ALLOF", "true");
+        options.put("REFACTOR_ALLOF_WITH_PROPERTIES_ONLY", "true");
+        OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, options);
+        openAPINormalizer.normalize();
+
+        Schema schema3 = openAPI.getComponents().getSchemas().get("Ancestor");
+        assertEquals(schema3.getExtensions().get("x-parent"), true);
+
+        Schema schema4 = openAPI.getComponents().getSchemas().get("Child");
+        assertNull(schema4.getExtensions());
+    }
+
     @Test
     public void testOpenAPINormalizerEnableKeepOnlyFirstTagInOperation() {
         OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/enableKeepOnlyFirstTagInOperation_test.yaml");
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
index b193ec296628..6789b897591a 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
@@ -1776,7 +1776,7 @@ public void testJdkHttpClientWithAndWithoutParentExtension() {
         List<File> files = generator.opts(configurator.toClientOptInput()).generate();
 
         validateJavaSourceFiles(files);
-        assertThat(files).hasSize(27);
+        assertThat(files).hasSize(33);
         assertThat(output.resolve("src/main/java/xyz/abcdef/model/Child.java"))
                 .content().contains("public class Child extends Person {");
         assertThat(output.resolve("src/main/java/xyz/abcdef/model/Adult.java"))
diff --git a/modules/openapi-generator/src/test/resources/3_0/allOf_extension_parent.yaml b/modules/openapi-generator/src/test/resources/3_0/allOf_extension_parent.yaml
index 873cc7a3788f..8d9a1146c790 100644
--- a/modules/openapi-generator/src/test/resources/3_0/allOf_extension_parent.yaml
+++ b/modules/openapi-generator/src/test/resources/3_0/allOf_extension_parent.yaml
@@ -101,4 +101,15 @@ components:
       description: allOf with a single item
       nullable: true
       allOf:
-        - $ref: '#/components/schemas/AnotherParent'
\ No newline at end of file
+        - $ref: '#/components/schemas/AnotherParent'
+    Ancestor:
+      type: object
+      properties:
+        p1:
+          type: integer
+    Offspring:
+      properties:
+        p2:
+          type: string
+      allOf:
+        - $ref: '#/components/schemas/Ancestor'
\ No newline at end of file