Compile error due to enum created on parent and child when using allOf #432

Closed
opened 2024-12-05 15:01:32 +01:00 by gschlueter-jaconi · 1 comment
gschlueter-jaconi commented 2024-12-05 15:01:32 +01:00 (Migrated from github.com)

Given this very simple example of a parent/child relationship:

components:
  schemas:
    Parent:
      type: object
      properties:
        id:
          type: string
        state:
          enum: [
            "on",
            "off",
          ]
    Child:
      allOf:
        - type: object
          properties:
            name:
              type: string
        - $ref: "#/components/schemas/Parent"

The sources generated with the latest version of the generator (4.4.1) lead to a compile error:

[ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/Child.java:[5,14] com.example.enumtest.Child is not abstract and does not override abstract method setState(com.example.enumtest.Parent.State) in com.example.enumtest.Parent
[ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/Child.java:[78,22] getState() in com.example.enumtest.Child cannot implement getState() in com.example.enumtest.Parent
  return type com.example.enumtest.Child.State is not compatible with com.example.enumtest.Parent.State
[ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/ParentDefault.java:[5,14] com.example.enumtest.ParentDefault is not abstract and does not override abstract method setState(com.example.enumtest.Parent.State) in com.example.enumtest.Parent
[ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/ParentDefault.java:[67,22] getState() in com.example.enumtest.ParentDefault cannot implement getState() in com.example.enumtest.Parent
  return type com.example.enumtest.ParentDefault.State is not compatible with com.example.enumtest.Parent.State

This happens because there is an enum Parent.State as well as Child.State which are of course incompatible.

I also created a small demo here: https://github.com/gschlueter-jaconi/generator-enum-demo. When building with ./mvnw clean install the compile error can be observed.

Given this very simple example of a parent/child relationship: ``` components: schemas: Parent: type: object properties: id: type: string state: enum: [ "on", "off", ] Child: allOf: - type: object properties: name: type: string - $ref: "#/components/schemas/Parent" ``` The sources generated with the latest version of the generator (4.4.1) lead to a compile error: ``` [ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/Child.java:[5,14] com.example.enumtest.Child is not abstract and does not override abstract method setState(com.example.enumtest.Parent.State) in com.example.enumtest.Parent [ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/Child.java:[78,22] getState() in com.example.enumtest.Child cannot implement getState() in com.example.enumtest.Parent return type com.example.enumtest.Child.State is not compatible with com.example.enumtest.Parent.State [ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/ParentDefault.java:[5,14] com.example.enumtest.ParentDefault is not abstract and does not override abstract method setState(com.example.enumtest.Parent.State) in com.example.enumtest.Parent [ERROR] enum-demo/target/generated-sources/openapi/generated-sources/openapi/com/example/enumtest/ParentDefault.java:[67,22] getState() in com.example.enumtest.ParentDefault cannot implement getState() in com.example.enumtest.Parent return type com.example.enumtest.ParentDefault.State is not compatible with com.example.enumtest.Parent.State ``` This happens because there is an enum `Parent.State` as well as `Child.State` which are of course incompatible. I also created a small demo here: https://github.com/gschlueter-jaconi/generator-enum-demo. When building with `./mvnw clean install` the compile error can be observed.
sschnabe commented 2024-12-12 08:48:47 +01:00 (Migrated from github.com)

Released with 4.4.2

Released with [4.4.2](https://github.com/kokuwaio/micronaut-openapi-codegen/releases/tag/4.4.2)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
kokuwaio/micronaut-openapi-codegen#432
No description provided.