Skip to content

Mismatch of behavior between Elysia, Eden Treaty & Open API generation #1142

@matthewlilley

Description

@matthewlilley

What version of Elysia is running?

latest

What platform is your computer?

Linux 5.15.167.4-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Here's the mismatch @SaltyAom:

If you write limit: t.Number({ default: 10 }) you get perfect TypeScript usage for handlers but the generated OpenAPI says limit is required and so does the Eden Treaty client.

If you write limit: t.Optional(t.Number({ default: 10 })) you get the correctly generated OpenAPI & Eden Treaty client but in handlers it is also optional, despite knowing that Elysia has already set these based on the defaults, forcing you to do a redundant fallback in code for every optional param with a default e.g.

const enableFee = query.enableFee ?? false

What is the expected behavior?

I expect that if default is set, Elysia will consider that and strongly type the query, params & body, whilst keeping optional for open api generation and eden treaty client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions