elysiajs / elysia

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

Merge group schema with route schema #697

Open StrangeBytesDev opened 1 week ago

StrangeBytesDev commented 1 week ago

What is the problem this feature would solve?

Currently, values set in a group guard over overwritten if also defined in a route. For example:

new Elysia()
    .group(
        '/something'
        {
            response: {
                default: t.Object({message: t.String()})
            }
        },
        (app) => app
            .get('/hello', () => 'hello', {response: {200: t.String()})
    )

The response object for the "/hello" route will only contain the entry for the 200 response. If instead the response object was merged together, it'd be useful for adding default responses to a group. This would be especially useful for the "default" response which is really handy for handling errors.

What is the feature you are proposing to solve the problem?

Merge together the group guard response with the route defined response.

What alternatives have you considered?

No response