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"; |
| 6 | import "google/api/annotations.proto"; |
| 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')%} |
| 24 | oneof {{ field.name }}_present { |
| 25 | {{ xproto_api_type(field) }} {{ field.name }}{% if field.link -%}_id{% endif %} = {{ loop.index }}{{ xproto_api_opts(field) }}; |
| 26 | } |
| 27 | {%- endfor -%} |
| 28 | |
| 29 | {%- for ref in xproto_base_rlinks(object, proto.message_table) + object.rlinks | sort(attribute='src_port') %} |
| 30 | {%- if '+' not in ref.src_port and '+' not in ref.dst_port %} |
| 31 | repeated int32 {{ ref.src_port }}_ids = {{ loop.index + 100 }} [(reverseForeignKey).modelName = "{{ ref.peer.name }}"]; |
| 32 | {%- endif -%} |
| 33 | {%- endfor %} |
| 34 | string class_names = 201; |
| 35 | string self_content_type_id = 202; |
| 36 | } |
| 37 | |
| 38 | message {{ xproto_pluralize(object) }} { |
| 39 | repeated {{ object.name }} items = 1; |
| 40 | } |
| 41 | |
| 42 | {%- endif %} |
| 43 | {% endfor %} |
| 44 | |
| 45 | service xos { |
| 46 | {% for object in proto.messages | sort(attribute='name')%} |
| 47 | {% if object.name != 'XOSBase' -%} |
| 48 | rpc List{{ object.name }}(google.protobuf.Empty) returns ({{ xproto_pluralize(object) }}) { |
| 49 | option (google.api.http) = { |
| 50 | {%- if object.name=='CordSubscriberRoot' %} |
| 51 | get: "/xosapi/v1/rcord/{{ xproto_pluralize(object) | lower }}" |
| 52 | {%- else %} |
| 53 | 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 }}" |
| 54 | {%- endif %} |
| 55 | }; |
| 56 | } |
| 57 | rpc Filter{{ object.name }}(Query) returns ({{ xproto_pluralize(object) }}) { |
| 58 | } |
| 59 | rpc Get{{ object.name }}(ID) returns ({{ object.name }}) { |
| 60 | option (google.api.http) = { |
| 61 | {%- if object.name=='CordSubscriberRoot' %} |
| 62 | get: "/xosapi/v1/rcord/{{ xproto_pluralize(object) | lower }}/{id}" |
| 63 | {%- else %} |
| 64 | 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}" |
| 65 | {%- endif %} |
| 66 | }; |
| 67 | } |
| 68 | rpc Create{{ object.name }}({{ object.name }}) returns ({{ object.name }}) { |
| 69 | option (google.api.http) = { |
| 70 | 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 }}" |
| 71 | body: "*" |
| 72 | }; |
| 73 | } |
| 74 | rpc Update{{ object.name }}({{ object.name }}) returns ({{ object.name }}) { |
| 75 | option (google.api.http) = { |
| 76 | 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}" |
| 77 | body: "*" |
| 78 | }; |
| 79 | } |
| 80 | rpc Delete{{ object.name }}(ID) returns (google.protobuf.Empty) { |
| 81 | option (google.api.http) = { |
| 82 | 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}" |
| 83 | }; |
| 84 | } |
| 85 | {%- endif %} |
| 86 | {% endfor %} |
| 87 | } |
| 88 | |