Skip to content

Instantly share code, notes, and snippets.

@sashka
Last active June 15, 2019 10:30
Show Gist options
  • Save sashka/46f8e766a2b48b6c7e009806a3e2ccfc to your computer and use it in GitHub Desktop.
Save sashka/46f8e766a2b48b6c7e009806a3e2ccfc to your computer and use it in GitHub Desktop.
@0xa43f2b7624cae18b;
using Common = import "common.capnp";
# Общий контейнер для любого типа запроса.
struct Request(T) {
# ID запроса для диагностики.
id @0 :Text;
# Некий волшебный токен, который позволяет возвращать в ответ только то,
# что случилось после предыдущей синхронизации, не передавая то, что не изменилось.
syncToken @1 :Text;
# Список тегов, которые должны быть заполнены в ответе.
# Позволяет вернуть только то, что запрошено, не заполнять всю структуру.
# TODO(soon): разделить requestFieldPath и responseFieldPath.
fieldPath @2 :Common.FieldPath;
# Собственно, тело запроса.
request @3 :T;
}
# Общий контейнер для любого типа ответа.
struct Response(T) {
# ID запроса.
id @0 :Text;
# Новый токен.
syncToken @1 :Text;
# Поля, которые были запрошены (и теперь заполнены).
fieldPath @2 :FieldPath;
# Список ошибок, которые случились в процессе обработки (если есть).
errors @3 :List(Error);
# Собственно, тело ответа.
response @4 :T;
struct Error {
id @0 :Text;
name @1 :Text;
detail @2 :Text;
severity @3 :Severity;
}
}
struct WorkspaceHandler {
struct Request {
text @0 :Text;
sentSec @1 :Int64;
attachments @2 :List(Bool);
}
struct Response {
sentMessage @0 :Message;
}
struct Message {
text @0 :Text;
}
}
# Authorization: Bearer <token>
interface Workspace {
# Тестовый запрос в формате `foo(request) -> (response)`
# Кодогенератор должен делать функцию
# `Workspace.foo(self, path, compound_obj): returns self.http_request(path, compound_obj)`
foo @0 (req :Request(WorkspaceHandler.Request)) -> (resp :Response(WorkspaceHandler.Response));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment