elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.64k stars 226 forks source link

Response validation fails when first request is to Swagger page #860

Open firatoezcan opened 1 month ago

firatoezcan commented 1 month ago

What version of Elysia is running?

1.1.17

What platform is your computer?

Linux 6.5.13-7-MANJARO x86_64 unknown

What steps can reproduce the bug?

I created a repo with a reproduction https://github.com/firatoezcan/elysia-reproduction

In short, it happens when the first request for the server is for the Swagger documentation. This somehow makes it that the response schema (and maybe also other schemas?) are not in the correct shape

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

The value of schema at the location where the error occurs is:

{
    "description": "OK",
    "content": {
        "application/json": {
            "schema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "username": {
                                    "type": "string"
                                },
                                "created_at": {
                                    "type": "string"
                                },
                                "updated_at": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "email",
                                "username",
                                "created_at",
                                "updated_at"
                            ]
                        }
                    }
                },
                "required": [
                    "data"
                ]
            }
        },
        "multipart/form-data": {
            "schema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "username": {
                                    "type": "string"
                                },
                                "created_at": {
                                    "type": "string"
                                },
                                "updated_at": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "email",
                                "username",
                                "created_at",
                                "updated_at"
                            ]
                        }
                    }
                },
                "required": [
                    "data"
                ]
            }
        },
        "text/plain": {
            "schema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "username": {
                                    "type": "string"
                                },
                                "created_at": {
                                    "type": "string"
                                },
                                "updated_at": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "email",
                                "username",
                                "created_at",
                                "updated_at"
                            ]
                        }
                    }
                },
                "required": [
                    "data"
                ]
            }
        }
    }
}

It should instead be:

{
    "description": "OK",
    "type": "object",
    "properties": {
        "data": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string"
                    },
                    "username": {
                        "type": "string"
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "updated_at": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "email",
                    "username",
                    "created_at",
                    "updated_at"
                ]
            }
        }
    },
    "required": [
        "data"
    ],
    "additionalProperties": false
}

Have you try removing the node_modules and bun.lockb and try again yet?

yes