Annotations
Annotations describe a declaration’s wire shape, lifecycle, transport mapping, or target metadata. Place them immediately before the declaration or member they describe. Each annotation has its own allowed positions and arguments; being recognized by the parser does not mean every generator implements it.
Reference by responsibility
Section titled “Reference by responsibility”| Reference | Annotations |
|---|---|
| Wire shape | @rename, @name, @rename_all, @skip, @optional, @flatten, @omitempty |
| Defaults and constraints | @default, @range, @min, @max, @unit |
| Lifecycle | @version, @added, @removed, @deprecated |
| HTTP mapping | @get, @post, @put, @patch, @delete, @head, @options, @path, @query, @header, @cookie, @body, @request, @response, @http, @webhooks, @cors |
| Security and streams | @http_basic, @http_bearer, @api_key, @no_security, @server_stream, @client_stream, @bidi_stream, @stream_codec, @upgrade |
| Target extensions | @derive, @rust; the rust-, rust_, ts-, and ts_ extension prefixes |
| IDL type metadata | @id, @autoid, @position, @value, @default_literal, @extensibility, @final, @appendable, @mutable, @key, @must_understand, @hashid, @bit_bound, @external, @nested, @default_nested, @ignore_literal_names, @try_construct, @non_serialized, @data_representation, @verbatim, @service, @oneway, @ami, @topic, @choice, @empty |
Argument forms
Section titled “Argument forms”Use the form documented for the particular annotation:
/// Public account fields.@rename_all("snake_case")struct Account { @rename(name = "account_id") string id; @optional string displayName;};- A marker, such as
@skip, takes no arguments. - A single-value annotation can accept a positional value or a named
value. Some also accept a specific alias:@rename(name = "account_id")and@rename("account_id")are equivalent. - Named-argument annotations have their own required keys. For example,
@api_key(in = "header", name = "X-Api-Key")requires both keys. - Do not mix positional and named arguments in one annotation or repeat a named key.
- Built-in names ignore ASCII case. String values follow the rules of their consumer; for example, naming rules use the exact spellings listed in the wire reference.
An annotation only applies to its declaration unless its reference explicitly
defines inheritance, such as interface-level HTTP defaults. For example,
@optional does not make every member of a struct optional.
Checking annotations
Section titled “Checking annotations”Run the annotation checker before generating code:
xidlc lint api.idl shared.idlxidlc lint --deny warnings api.idllint checks built-in names, declaration positions, and argument shapes. It
checks only the files explicitly passed on the command line. Include the
imported files when checking a split contract.
| Diagnostic | Severity | Example |
|---|---|---|
misspelled-annotation |
error | @remvoed suggests @removed |
misplaced-annotation |
error | @optional on an interface |
bad-annotation-args |
error | @api_key without name |
unknown-annotation |
warning | a project-specific @relay_audit |
Warnings remain visible without making the command fail. --deny warnings
makes them fail the check. Target extension prefixes bypass built-in argument
and position checks; that is not a guarantee of generated behavior.
gen does not run this whole lint pass. Semantic validation and individual
targets check the contracts they consume; for example, generation validates
@webhooks placement and arguments before version projection. A clean lint
result alone does not prove a route, stream, or target combination is valid.
Generate the intended targets as well:
xidlc gen --out-dir out typescript-rest --client --server api.idlxidlc gen --out-dir out openapi api.idlEditor integrations can use xidl_parser::lint::BUILTIN_ANNOTATIONS for
completion metadata and xidl_parser::lint::lint(&typed_ast::Specification)
for structured diagnostics.
Compose independent concerns
Section titled “Compose independent concerns”| Concern | Primitive | What it does not decide |
|---|---|---|
| Wire name | @rename, @rename_all |
How to translate a value between versions |
| Presence | @optional |
A business default for an omitted value |
| Availability | @added, @removed |
Which version a request selects |
| Transport | @path, @query, @body |
Authentication or business authorization |
| HTTP publication | @webhooks |
Delivery retries, signing, or event storage |
Combine these declarations to describe a contract. Keep version selection, business conversions, persistence, authorization, and delivery policy in the application. The generated types, validators, and OpenAPI documents show the result for each target and version.
Frequently used annotations
Section titled “Frequently used annotations”@rename
Section titled “@rename”Selects a wire name without changing the IDL identifier. Syntax, alias, and precedence.
@rename_all
Section titled “@rename_all”Sets a container’s wire naming rule where the target consumes it. Supported rules and positions.
Excludes supported fields or parameters from their wire representation. Target differences.
@optional
Section titled “@optional”Marks a field or parameter as potentially absent. Presence and HTTP restrictions.
Maintaining this reference
Section titled “Maintaining this reference”The built-in registry defines recognized names, positions, and argument shapes. The typed annotation model defines the grammar-specific forms. Semantic passes and target renderers define the effects described on the linked pages. When adding or changing an annotation, update its reference and verify both lint and the generated output; do not infer implementation support from a registered name alone.