Attributes
An attribute is typed metadata attached to a module, a controller or a handler. It does nothing by itself: a guard or an interceptor reads it from ctx.route to decide what to do, and tools such as the OpenAPI plugin read it from app.routes().
Creating an attribute
The schema can be any Standard Schema. It must validate synchronously, because an attribute is applied while classes are being defined. An invalid value throws at that point, so @Roles([]) here stops the process at start-up rather than failing a request later.
An attribute is identified by its symbol. Use Symbol.for('name') when the attribute may be loaded from two copies of a package, and a plain Symbol('name') otherwise.
Applying an attribute
Calling an attribute gives a decorator for a module, a controller or a handler.
On a class, place the attribute above @Controller or @Module. On a method, its position relative to @Endpoint does not matter, but a method with an attribute and no @Endpoint fails at init().
Calling an attribute also returns its value, which the attributes option of @Module, @Controller and handler() accepts:
Reading an attribute
AttributeFactory reads from a RouteInfo. During a request that is ctx.route.
CurrentUser is the context key set by the guard from Authentication with JWT. With the controller above, purge needs the admin role and stats needs staff or admin; a user with neither gets 403.
For the module level, the nearest module that sets the attribute wins: the route's own module, else the module that imports it, and so on outwards. When several modules import the route's module, they have to agree: init() fails if one gives the route the attribute and another does not, or gives another value. Set the attribute on the controllers or handlers it is meant for then, or on the module itself.
get returns one level's value and does not merge levels. @Roles(['admin']) on purge replaces the controller's ['staff', 'admin'] for that handler. When you want the levels combined, as tags usually are, use getAll.
Attributes do not cancel each other. A @Public() handler in a controller marked @Roles([...]) still carries the roles, and each guard decides what that means. The RolesGuard above denies such a route to an anonymous caller; check Public in it too if a public route should win.
Reading outside a request
app.routes() returns the same RouteInfo objects after init(), so a script or a plugin can inspect every route's attributes:
A plugin receives the same list in its onBootstrap hook. This is how @navios/openapi turns ApiTag, ApiSummary and its other attributes into a document without touching the request pipeline.