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 | |
| 14 | {% for object in proto.messages|sort(attribute='name') %} |
| 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':{}} -%} |
| 23 | {%- for field in (xproto_base_fields(object, proto.message_table) + object.fields + [id_field]) | sort(attribute='name')%} |
Scott Baker | c59f1bc | 2017-12-04 16:55:05 -0800 | [diff] [blame] | 24 | {%- 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 Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 27 | oneof {{ field.name }}_present { |
| 28 | {{ xproto_api_type(field) }} {{ field.name }}{% if field.link -%}_id{% endif %} = {{ loop.index }}{{ xproto_api_opts(field) }}; |
| 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 | |
| 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 | |
| 42 | message {{ xproto_pluralize(object) }} { |
| 43 | repeated {{ object.name }} items = 1; |
| 44 | } |
| 45 | |
| 46 | {%- endif %} |
| 47 | {% endfor %} |
| 48 | |
| 49 | service 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 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 | |