Examples
TypeSpec provide 2 decorators @example
and @opExample
to provide some examples for the types and operations.
With those decorators the examples must be provided as TypeSpec values that should be assignable to the type or operation parameter/return types.
Type Examples
To give an example for a type you can use the @example
decorator. The decorator first argument is the example value it MUST be assignable to the type it is targetting.
Additionally a title and/or description can be provided in the options.
Simple primitive types
Scalar types
For scalar types the value must be defined with the scalar constructor.
This allows emitters to render the example in the correct protocol following the encoding of those scalar and the values set by @encode
.
Provide title or description
Multiple examples
Define typed examples using const
Operation examples
Operation example are provided with the @opExample
decorator. Similar to the @example
decorator the first argument is the example value however it takes both the parameters
and returnType
example.
The values passed to parameters
MUST be assignable to the operation parameters and the value passed to returnType
MUST be assignable to the operation return type.
Additionally a title and/or description can be provided in the options.