summaryrefslogtreecommitdiffstats
path: root/docs/guides/onap-developer/how-to-use-docs/api-swagger-guide.rst
blob: 9d3a7f6fc89d4bf1fc0776a103fef59fa6d9f183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.. This work is licensed under a Creative Commons Attribution 4.0
.. International License. http://creativecommons.org/licenses/by/4.0
.. Copyright 2019 Orange.  All rights reserved.

.. _api-swagger-guide:

API documentation
=================

Swagger
-------

The API should be described using OpenAPI specifications and available as a
`JSON file <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md>`_

A Swagger editor is available here `<http://editor.swagger.io/>`_ to generate
such JSON files.

As a result, you should get one JSON file per API. For example the project
**my** has 2 API: **myAPI1** and **myAPI2**.

- myAPI1.json
- myAPI2.json

Global API table
----------------
It is recommended to list the following API available with an access to the
Swagger JSON files to help the developers/users to play with JSON.

We propose the following table:

.. csv-table::
   :header: "API name", "Swagger JSON"
   :widths: 10,5

   "myAPI1", ":download:`link <myAPI1.json>`"
   "myAPI12", ":download:`link <myAPI2.json>`"

.. note::
   During documentation merge/publish at RTD, any file referenced in an RST file with
   ':download:' and relative path to a contributing project repository is copied, uniquely
   named, and published with the generated HTML pages.

The code is available here:

.. code:: rst

   .. csv-table::
      :header: "API name", "Swagger JSON"
      :widths: 10,5

      "myAPI1", ":download:`link <myAPI1.json>`"
      "myAPI2", ":download:`link <myAPI2.json>`"

.. note::
   The syntax of <myAPI1.json> is to be taken literally. Keep '<' and '>'.

.. note::
   Note the “v” in  swaggerv2doc!
   If your JSON file has multiple endpoints, this directive does not preserve the order.

API Swagger
-----------
For each API, the ``swaggerv2doc`` directive must be used as follows:

.. code:: rst

   myAPI1
   ......
   .. swaggerv2doc:: myAPI1.json

   myAPI2
   ......
   .. swaggerv2doc:: myAPI2.json

It will produce the following output:

myAPI1
......
.. swaggerv2doc:: myAPI1.json

myAPI2
......
.. swaggerv2doc:: myAPI2.json