Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 1 | syntax = "proto3"; |
| 2 | |
| 3 | package xos; |
| 4 | |
| 5 | import "google/protobuf/empty.proto"; |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 6 | import "annotations.proto"; |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 7 | import "common.proto"; |
| 8 | import "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 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 14 | {% for object in proto.messages|selectattr("is_included")|sort(attribute='name') %} |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 15 | {% if object.name != 'XOSBase' -%} |
| 16 | message {{ 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 Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 23 | {%- for field in xproto_fields(object, proto.message_table) | sort(attribute='id')%} |
Scott Baker | c59f1bc | 2017-12-04 16:55:05 -0800 | [diff] [blame] | 24 | {%- if field.options.type == "link" and field.options.link_type == "manytomany" %} |
Scott Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 25 | repeated int32 {{ field.name }}_ids = {{ field.id }} [(manyToManyForeignKey).modelName = "{{ field.options.model }}"]; |
Scott Baker | c59f1bc | 2017-12-04 16:55:05 -0800 | [diff] [blame] | 26 | {%- else %} |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 27 | oneof {{ field.name }}_present { |
Scott Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 28 | {{ xproto_api_type(field) }} {{ field.name }}{% if field.link -%}_id{% endif %} = {{ field.id }} {{ xproto_api_opts(field) }}; |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 29 | } |
Scott Baker | c59f1bc | 2017-12-04 16:55:05 -0800 | [diff] [blame] | 30 | {%- endif -%} |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 31 | {%- endfor -%} |
| 32 | |
Scott Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 33 | {%- for ref in xproto_rlinks(object, proto.message_table) | sort(attribute='id') %} |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 34 | {%- if '+' not in ref.src_port and '+' not in ref.dst_port %} |
Scott Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 35 | repeated int32 {{ ref.src_port }}_ids = {{ ref["id"] }} [(reverseForeignKey).modelName = "{{ ref.peer.name }}"]; |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 36 | {%- endif -%} |
| 37 | {%- endfor %} |
Scott Baker | c237f88 | 2018-09-28 14:12:47 -0700 | [diff] [blame] | 38 | string class_names = 2046; |
| 39 | string self_content_type_id = 2047; |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | message {{ xproto_pluralize(object) }} { |
| 43 | repeated {{ object.name }} items = 1; |
| 44 | } |
| 45 | |
| 46 | {%- endif %} |
| 47 | {% endfor %} |
| 48 | |
| 49 | service xos { |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 50 | {% for object in proto.messages | selectattr("is_included") | sort(attribute='name')%} |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 51 | {% if object.name != 'XOSBase' -%} |
| 52 | rpc List{{ object.name }}(google.protobuf.Empty) returns ({{ xproto_pluralize(object) }}) { |
Zack Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 53 | option (googleapi.http) = { |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 54 | {%- 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 Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 64 | option (googleapi.http) = { |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 65 | {%- 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 Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 73 | option (googleapi.http) = { |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 74 | 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 Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 79 | option (googleapi.http) = { |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 80 | 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 Williams | 6bdd3ea | 2018-03-26 15:21:05 -0700 | [diff] [blame] | 85 | option (googleapi.http) = { |
Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 86 | 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 | |