Attributes
Attributes are annotations that attach metadata to types, fields, and methods. IonPath supports both built-in and custom attributes.
Declaring Custom Attributes
Declare a custom attribute with the attribute keyword:
attribute @deprecated(version: string, reason: string); attribute @description(text: string); attribute @maxLength(n: i4);
Attribute arguments can only be scalar types — string, i4, bool, etc. Using a non-scalar type triggers ION0004.
Applying Attributes
Apply attributes with the @ prefix before a declaration:
@deprecated("2.0", "Use UserV2 instead") msg User { @description("The unique user identifier") id: u4; name: string; } @deprecated("3.0", "Use NewService") service OldService() { DoThing(): void; }
Built-in Attributes
These attributes are provided by the standard library and used internally by the compiler:
Attribute Description
@builtin Marks a type as part of the standard library. Internal use only.
@scalar Marks a type as scalar (no indirection). Used for primitives.
@tag(n) CBOR tag annotation — wraps the encoded value with a CBOR tag number.
@deadline(ms) Request timeout in milliseconds. Applied to service methods.
@deprecated Marks a type, field, or method as deprecated.
@internal Marks a declaration as internal/hidden.
@bits(n) Specifies the bit count for numeric types.
@union Automatically applied to union types.
@unionCase Automatically applied to union case types.
Validation
- ION0004 — Using a non-scalar type in attribute arguments (e.g., a message type)
- ION0005 — Referencing an attribute that is not declared or imported