bkbnio / kompendium

Ktor OpenAPI Spec Generator
https://bkbn.gitbook.io/kompendium
MIT License
152 stars 23 forks source link

Return type with a list of enums breaks redoc #551

Closed ESchouten closed 9 months ago

ESchouten commented 10 months ago

Describe the bug v3.6.0, PR #368 breaks redoc when an endpoints return type contains a list of Enums. Redoc error: Error: "Self-referencing circular pointer"

When inspecting the generated components/models the following difference is observed; since 3.6.0 the lists items property contains "type": "string" v3.5.0:

"User": {
    "type": "object",
    "properties": {
        "authorities": {
            "items": {
                "enum": [
                    "ADMIN",
                    "USER"
                ]
            },
            "type": "array"
        },
    },
    "required": [
        "authorities"
    ]
},

v3.6.0:

"User": {
    "type": "object",
    "properties": {
        "authorities": {
            "items": {
                "type": "string",
                "enum": [
                    "ADMIN",
                    "USER"
                ]
            },
            "type": "array"
        },
    },
    "required": [
        "authorities"
    ]
}
brizzbuzz commented 10 months ago

huh... out of curiosity, do you know if this is actually invalid json schema? or is this just causing issues w/ ReDoc and their parser?

Either way, worth fixing in the next version of Kompendium, but, this project has fallen pretty far off my personal priorities, so, can't guarantee when the next release will be. Hopefully some time early 2024, will probably wait for Ktor 3 to come out and fix up any compatibility issues that occur as well.

ESchouten commented 10 months ago

@unredundant I am not sure, my OpenAPI client generator does not fall over this difference, just Redoc, so it could be either way

brizzbuzz commented 9 months ago

CleanShot 2024-01-15 at 11 40 15@2x

fwiw, the intellij openapi inspection tool (this screenshot is inspecting one of the kompendium tests) is powered by redoc, and seems to render totally fine.

With that said, from poking around the json schema docs, it does seem like the general expectation for enums is that they omit the type value.

So, i'm guessing that this is technically a bug in Kompendium, but one that only impacts certain versions of redoc.

will be fixed in v4 :)

brizzbuzz commented 9 months ago

oh nvm i forgot this was only for list

can replicate error now :)

brizzbuzz commented 9 months ago

oh man I definitely just did something dumb in the code haha

"schemas": {
      "TestEnum": {
        "$ref": "#/components/schemas/TestEnum"
      },
      "List-TestEnum": {
        "items": {
          "enum": [
            "YES",
            "NO"
          ]
        },
        "type": "array"
      }
    },

for some reason, when the code hits a type of List<Enum> it puts the type information inside of the list schema, and then just does a self reference inside of the actual enum definition.