id | title |
---|---|
operations |
Operations |
Operations describe service endpoints and consist of an operation name, parameters, and return type.
Operations are declared using the op
keyword:
op ping(): void;
The operation's parameters describe a model, so anything you can do in a model you can do in a parameter list as well, including using the spread operator:
op feedDog(...CommonParams, name: string): void;
Often an endpoint returns one of any number of models. For example, there might be a return type for when an item is found, and a return type for when an item isn't found. Unions are used to describe this pattern:
model DogNotFound {
error: "Not Found";
}
op getDog(name: string): Dog | DogNotFound;
Operation signatures can be reused using the is
keyword. Given an operation
op Delete(id: string): void;
its signature can be reused like this:
op deletePet is Delete;
This means that deletePet
will have the same parameters, return type and decorators as the Delete
operation.
This pattern is most commonly used in combination with operation templates
See templates for details on templates.
op ReadResource<T>(id: string): T;
The operation template can then be referenced via is
:
op readPet is ReadResource<Pet>;
Model properties can be referenced using the .
operator for identifiers.
alias PetName = Pet.name;
Some operation meta types can be referenced using ::
Name | Example | Description |
---|---|---|
parameters | readPet::parameters |
Reference the parameters model expression |
returnType | readPet::returnType |
Reference the operation return type |