thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
77 stars 14 forks source link

examples with properties named "schemas" are rewritten to an object #91

Closed fantapop closed 6 months ago

fantapop commented 7 months ago

I have an api endpoint like this:

           "CreateGroupRequest": {
                "example": {
                    "displayName": "Test SCIM",
                    "members": [],
                    "schemas": [
                        "urn:ietf:params:scim:schemas:core:2.0:Group"
                    ]
                },
                "properties": {
                    "displayName": {
                        "type": "string"
                    },
                    "externalId": {
                        "type": "string"
                    },
                    "members": {
                        "items": {
                            "$ref": "#/components/schemas/ScimResource"
                        },
                        "type": "array"
                    },
                    "schemas": {
                        "items": {
                            "type": "string"
                        },
                        "type": "array"
                    }
                },
                "required": [
                    "displayName"
                ],
                "title": "CreateGroupRequest",
                "type": "object"
            },

After running this through openapi-format, the example is rewritten like so:

        "example": {
          "displayName": "Test SCIM",
          "members": [],
          "schemas": [
            {
              "0": "u",
              "1": "r",
              "2": "n",
              "3": ":",
              "4": "i",
              "5": "e",
              "6": "t",
              "7": "f",
              "8": ":",
              "9": "p",
              "10": "a",
              "11": "r",
              "12": "a",
              "13": "m",
              "14": "s",
              "15": ":",
              "16": "s",
              "17": "c",
              "18": "i",
              "19": "m",
              "20": ":",
              "21": "s",
              "22": "c",
              "23": "h",
              "24": "e",
              "25": "m",
              "26": "a",
              "27": "s",
              "28": ":",
              "29": "c",
              "30": "o",
              "31": "r",
              "32": "e",
              "33": ":",
              "34": "2",
              "35": ".",
              "36": "0",
              "37": ":",
              "38": "G",
              "39": "r",
              "40": "o",
              "41": "u",
              "42": "p"
            }
          ]
        },

Could this be due to some kind of recursive handling of the open api "schemas" field? Thanks in advance for taking a look.

thim81 commented 7 months ago

hi @fantapop

This is indeed an uncovered case as a result of the recursive handling. I'll try to create a fix in the coming period, by excluding the "schemas" when it is part of the "example" node.

Thanks for reporting this.

thim81 commented 6 months ago

hi @fantapop

There is a new release v1.14.2 that contains the bug fix for this issue. I added a test that uses your example as input with the correct output after the conversion. https://github.com/thim81/openapi-format/tree/main/test/json-example-schemas

Can you verify, if the new version solves your issue?

fantapop commented 6 months ago

Hey, sorry I meant to test this. I did just now. Its fixed! Thank you so much for upkeeping this library.