blob: 2311b98c1f041dcf3f2bc7d890435713918d559c [file] [log] [blame]
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02001syntax = "proto3";
2
3package xos;
4
5import "google/protobuf/empty.proto";
Zack Williams6bdd3ea2018-03-26 15:21:05 -07006import "annotations.proto";
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02007import "common.proto";
8import "xosoptions.proto";
9
10// Note: all fields are wrapped in a "oneof". This causes proto3 to always send
11// fields that are set by the caller, regardless if they are set to a default
12// value. XOS uses this to know when to apply a default value.
13
14{% for object in proto.messages|sort(attribute='name') %}
15{% if object.name != 'XOSBase' -%}
16message {{ object.name }} {
17 {%- if object.name=='CordSubscriberRoot' %}
18 option (contentTypeId) = "rcord.{{ object.name | lower }}";
19 {%- else %}
20 option (contentTypeId) = "{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}.{{ object.name | lower }}";
21 {%- endif %}
22 {%- set id_field = {'type':'int32', 'name':'id', 'options':{}} -%}
Scott Bakerc237f882018-09-28 14:12:47 -070023 {%- for field in xproto_fields(object, proto.message_table) | sort(attribute='id')%}
Scott Bakerc59f1bc2017-12-04 16:55:05 -080024 {%- if field.options.type == "link" and field.options.link_type == "manytomany" %}
Scott Bakerc237f882018-09-28 14:12:47 -070025 repeated int32 {{ field.name }}_ids = {{ field.id }} [(manyToManyForeignKey).modelName = "{{ field.options.model }}"];
Scott Bakerc59f1bc2017-12-04 16:55:05 -080026 {%- else %}
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020027 oneof {{ field.name }}_present {
Scott Bakerc237f882018-09-28 14:12:47 -070028 {{ xproto_api_type(field) }} {{ field.name }}{% if field.link -%}_id{% endif %} = {{ field.id }} {{ xproto_api_opts(field) }};
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020029 }
Scott Bakerc59f1bc2017-12-04 16:55:05 -080030 {%- endif -%}
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020031 {%- endfor -%}
32
Scott Bakerc237f882018-09-28 14:12:47 -070033 {%- for ref in xproto_rlinks(object, proto.message_table) | sort(attribute='id') %}
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020034 {%- if '+' not in ref.src_port and '+' not in ref.dst_port %}
Scott Bakerc237f882018-09-28 14:12:47 -070035 repeated int32 {{ ref.src_port }}_ids = {{ ref["id"] }} [(reverseForeignKey).modelName = "{{ ref.peer.name }}"];
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020036 {%- endif -%}
37 {%- endfor %}
Scott Bakerc237f882018-09-28 14:12:47 -070038 string class_names = 2046;
39 string self_content_type_id = 2047;
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020040}
41
42message {{ xproto_pluralize(object) }} {
43 repeated {{ object.name }} items = 1;
44}
45
46{%- endif %}
47{% endfor %}
48
49service xos {
50{% for object in proto.messages | sort(attribute='name')%}
51{% if object.name != 'XOSBase' -%}
52 rpc List{{ object.name }}(google.protobuf.Empty) returns ({{ xproto_pluralize(object) }}) {
Zack Williams6bdd3ea2018-03-26 15:21:05 -070053 option (googleapi.http) = {
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020054 {%- if object.name=='CordSubscriberRoot' %}
55 get: "/xosapi/v1/rcord/{{ xproto_pluralize(object) | lower }}"
56 {%- else %}
57 get: "/xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}"
58 {%- endif %}
59 };
60 }
61 rpc Filter{{ object.name }}(Query) returns ({{ xproto_pluralize(object) }}) {
62 }
63 rpc Get{{ object.name }}(ID) returns ({{ object.name }}) {
Zack Williams6bdd3ea2018-03-26 15:21:05 -070064 option (googleapi.http) = {
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020065 {%- if object.name=='CordSubscriberRoot' %}
66 get: "/xosapi/v1/rcord/{{ xproto_pluralize(object) | lower }}/{id}"
67 {%- else %}
68 get: "/xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}/{id}"
69 {%- endif %}
70 };
71 }
72 rpc Create{{ object.name }}({{ object.name }}) returns ({{ object.name }}) {
Zack Williams6bdd3ea2018-03-26 15:21:05 -070073 option (googleapi.http) = {
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020074 post: "/xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}"
75 body: "*"
76 };
77 }
78 rpc Update{{ object.name }}({{ object.name }}) returns ({{ object.name }}) {
Zack Williams6bdd3ea2018-03-26 15:21:05 -070079 option (googleapi.http) = {
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020080 put: "/xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}/{id}"
81 body: "*"
82 };
83 }
84 rpc Delete{{ object.name }}(ID) returns (google.protobuf.Empty) {
Zack Williams6bdd3ea2018-03-26 15:21:05 -070085 option (googleapi.http) = {
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020086 delete: "/xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}/{id}"
87 };
88 }
89{%- endif %}
90{% endfor %}
91}
92