blob: 183bacd951eda99cf3c3a054ad8ff51054738346 [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':{}} -%}
23 {%- for field in (xproto_base_fields(object, proto.message_table) + object.fields + [id_field]) | sort(attribute='name')%}
Scott Bakerc59f1bc2017-12-04 16:55:05 -080024 {%- if field.options.type == "link" and field.options.link_type == "manytomany" %}
25 repeated int32 {{ field.name }}_ids = {{ loop.index }} [(manyToManyForeignKey).modelName = "{{ field.options.model }}"];
26 {%- else %}
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020027 oneof {{ field.name }}_present {
28 {{ xproto_api_type(field) }} {{ field.name }}{% if field.link -%}_id{% endif %} = {{ loop.index }}{{ xproto_api_opts(field) }};
29 }
Scott Bakerc59f1bc2017-12-04 16:55:05 -080030 {%- endif -%}
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020031 {%- endfor -%}
32
33 {%- for ref in xproto_base_rlinks(object, proto.message_table) + object.rlinks | sort(attribute='src_port') %}
34 {%- if '+' not in ref.src_port and '+' not in ref.dst_port %}
35 repeated int32 {{ ref.src_port }}_ids = {{ loop.index + 100 }} [(reverseForeignKey).modelName = "{{ ref.peer.name }}"];
36 {%- endif -%}
37 {%- endfor %}
38 string class_names = 201;
39 string self_content_type_id = 202;
40}
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