Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation of an invalid OpenAPI schema, when "examples" field is used in the URL parameters schema. #941

Open
flysand7 opened this issue Dec 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@flysand7
Copy link

flysand7 commented Dec 15, 2024

What version of Elysia is running?

No response

What platform is your computer?

Linux 6.8.0-49-generic x86_64 unknown

What steps can reproduce the bug?

  1. Create a type schema that will be used for the uid URL parameter. To reproduce, the schema parameter should contain the examples field.
import { Elysia, t } from "elysia";

const UidT = t.Number({
    description: "Уникальный идентификатор пользователя",
    examples: [ 1 ],
});
  1. Expose a route that defines a param with the above-defined type.
import { swagger } from "@elysiajs/swagger";

new Elysia({})
    .use(swagger({
        provider: "swagger-ui",
        path: '/docs',
    }))
    .get("/:uid/tokens",
        (req) => console.log(req.params.uid),
        {
            params: t.Object({
                uid: UidT,
            }),
        },
    )
    .listen(3000);

What is the expected behavior?

After navigating to the /docs route on the server, the generated OpenAPI schema should contain a valid specification for the uid parameter in the /:uid/tokens route.

The swagger UI providers (both scalar and swagger-ui) should also be able to allow the user to test the route with the specified example.

What do you see instead?

Currently, when a schema with examples field is passed to the params object of the request schema, the generated OpenAPI schema contains examples in the parameters object, i.e.:

                "parameters": [
                    {
                        "description": "Уникальный идентификатор пользователя",
                        "examples": [
                            1
                        ],
                        "schema": {
                            "type": "number"
                        },
                        "in": "path",
                        "name": "uid",
                        "required": true
                    }
                ],

Which, according to the OpenAPI specification should be valid, but apparently swagger-ui and scalar don't like this (?).

Furthermore whilst swagger-ui provider shows "Could not render Parameters, see the console" error on that specific route (I still don't know which console it asks me to see, because it didn't print anything to stdout), scalar does not show any error and when hitting the "Test" button it shows a different route (I haven't tested what happens when there's no other route).

Additional information

Although I believe I have the latest version of Elysia as of this point (2024-12-16), I haven't figured out how to run the Elysia --revision command. With default installation (bun install elysia) my shell (ash) simply says:

/app # Elysia --revision
sh: Elysia: not found

I tried installing globally (bun install -g elysia), which also didn't help. Is there anything I'm missing? I'm running elysia under a docker container (alpine linux). Just in case, the versions in the lockfile are:

> bun ./bun.lockb | grep -A1 \"elysia
"elysia@>= 1.1.0", elysia@^1.1.26:
  version "1.1.26"

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

Yes, the issue still reproduces.

@flysand7 flysand7 added the bug Something isn't working label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant