[CORD-1796] Generate swagger spec from xproto
Change-Id: Ia5697b386b216d677bef73f08c36c022e28038ca
diff --git a/lib/xos-genx/xosgenx/targets/swagger.xtarget b/lib/xos-genx/xosgenx/targets/swagger.xtarget
new file mode 100644
index 0000000..3d089b9
--- /dev/null
+++ b/lib/xos-genx/xosgenx/targets/swagger.xtarget
@@ -0,0 +1,135 @@
+swagger: "2.0"
+info:
+ title: "XOS REST APIs"
+ description: "XOS - REST API Docs"
+ version: "1.0.0"
+ contact:
+ email: "cord-dev@opencord.org"
+
+{#tags:#}
+{#{%- for object in proto.messages %}#}
+{#- name: "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"#}
+{# description: "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }} Models"#}
+{# externalDocs:#}
+{# description: "Find out more"#}
+{# url: "https://guide.opencord.org/xos/core_models.html"#}
+{#{% endfor %}#}
+
+paths:
+{%- for object in proto.messages %}
+ /xosapi/v1/{{ xproto_unquote(xproto_first_non_empty([object.options.name, object.options.app_label, options.name, context.app_label])) }}/{{ xproto_pluralize(object) | lower }}/:
+ get:
+ tags:
+ - "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"
+ summary: "List {{xproto_pluralize(object)}}"
+ responses:
+ 200:
+ description: OK
+ 401:
+ description: "Unauthorized"
+ 403:
+ description: "Forbidden"
+ 500:
+ description: "Internal Server Error"
+ post:
+ tags:
+ - "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"
+ summary: "Create {{object.name}}"
+ parameters:
+ - in: "body"
+ name: "body"
+ description: "{{object.name}} model properties"
+ required: true
+ schema:
+ $ref: "#/definitions/{{object.name}}"
+ responses:
+ 200:
+ description: OK
+ 401:
+ description: "Unauthorized"
+ 403:
+ description: "Forbidden"
+ 500:
+ description: "Internal Server Error"
+ /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}:
+ get:
+ tags:
+ - "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"
+ summary: "Get {{object.name}}"
+ parameters:
+ - in: "path"
+ name: "id"
+ description: "ID of {{ object.name }} to return"
+ required: true
+ type: "integer"
+ format: "int64"
+ responses:
+ 200:
+ description: OK
+ 401:
+ description: "Unauthorized"
+ 403:
+ description: "Forbidden"
+ 500:
+ description: "Internal Server Error"
+ put:
+ tags:
+ - "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"
+ summary: "Get {{object.name}}"
+ parameters:
+ - in: "path"
+ name: "id"
+ description: "ID of {{ object.name }} to return"
+ required: true
+ type: "integer"
+ format: "int64"
+ responses:
+ 200:
+ description: OK
+ 401:
+ description: "Unauthorized"
+ 403:
+ description: "Forbidden"
+ 500:
+ description: "Internal Server Error"
+ delete:
+ tags:
+ - "{{ xproto_unquote(xproto_first_non_empty([object.options.app_label, object.options.name])) }}"
+ summary: "Delete {{object.name}}"
+ parameters:
+ - in: "path"
+ name: "id"
+ description: "ID of {{ object.name }} to return"
+ required: true
+ type: "integer"
+ format: "int64"
+ responses:
+ 200:
+ description: OK
+ 401:
+ description: "Unauthorized"
+ 403:
+ description: "Forbidden"
+ 500:
+ description: "Internal Server Error"
+{% endfor %}
+
+definitions:
+{%- for object in proto.messages %}
+ {{ object.name }}:
+ type: "object"
+ properties:
+{%- for f in object.fields %}
+ {{ f.name }}:
+ type: {{ xproto_type_to_swagger_type(f) }}
+{%- if xproto_field_to_swagger_enum(f) %}
+ enum:
+{%- for e in xproto_field_to_swagger_enum(f) %}
+ - {{ e }}
+{%- endfor %}
+{%- endif %}
+{%- if f.options.help_text %}
+ description: "{{ xproto_unquote(f.options.help_text) }}"
+{% endif %}
+{%- endfor %}
+{% endfor %}