Docs: Update all API docs with example
[pti/o2.git] / o2ims / views / api_ns.py
1 # Copyright (C) 2021-2022 Wind River Systems, Inc.
2 #
3 #  Licensed under the Apache License, Version 2.0 (the "License");
4 #  you may not use this file except in compliance with the License.
5 #  You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS,
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #  See the License for the specific language governing permissions and
13 #  limitations under the License.
14
15 from flask import request
16 from flask_restx import Resource, fields
17
18 from o2common.views.route import O2Namespace
19
20
21 api_ims_inventory = O2Namespace(
22     "O2IMS-InfrastructureInventory",
23     description='O2 IMS Inventory related operations.')
24
25 api_provision_v1 = O2Namespace(
26     "PROVISION",
27     description='Provision related operations.')
28
29 api_ims_monitoring = O2Namespace(
30     "O2IMS-InfrastructureMonitoring",
31     description='O2 IMS Monitoring related operations.')
32
33
34 @api_ims_inventory.route('/api_versions')
35 class InventoryVersion(Resource):
36     api_version = api_ims_inventory.model(
37         'InventoryApiVersionStructure',
38         {
39             'version': fields.String(
40                 required=True,
41                 example='1.0.0',
42                 description='Identifies a supported version.'
43             )
44         },
45         mask='{version,}'
46     )
47     model = api_ims_inventory.model(
48         "InventoryAPIVersion",
49         {
50             'uriPrefix': fields.String(
51                 required=True,
52                 example='https://128.224.115.36:30205/' +
53                 'o2ims-infrastructureInventory',
54                 description='Specifies the URI prefix for the API'),
55             'apiVersions': fields.List(
56                 fields.Nested(api_version),
57                 example=[{'version': '1.0.0'}],
58                 description='Version(s) supported for the API ' +
59                 'signaled by the uriPrefix attribute.'),
60         },
61         mask='{uriPrefix,apiVersions}'
62     )
63
64     @api_ims_inventory.doc('Get Inventory Version')
65     @api_ims_inventory.marshal_with(model)
66     def get(self):
67         return {
68             'uriPrefix': request.base_url.rsplit('/', 1)[0],
69             'apiVersions': [{
70                 'version': '1.0.0',
71                 # 'isDeprecated': 'False',
72                 # 'retirementDate': ''
73             }]
74         }
75
76
77 @api_ims_monitoring.route('/api_versions')
78 class MonitoringVersion(Resource):
79     api_version = api_ims_inventory.model(
80         'MonitoringApiVersionStructure',
81         {
82             'version': fields.String(
83                 required=True,
84                 example='1.0.0',
85                 description='Identifies a supported version.'
86             )
87         },
88         mask='{version,}'
89     )
90     model = api_ims_inventory.model(
91         "MonitoringAPIVersion",
92         {
93             'uriPrefix': fields.String(
94                 required=True,
95                 example='https://128.224.115.36:30205/' +
96                 'o2ims-infrastructureMonitoring',
97                 description='Specifies the URI prefix for the API'),
98             'apiVersions': fields.List(
99                 fields.Nested(api_version),
100                 example=[{'version': '1.0.0'}],
101                 description='Version(s) supported for the API ' +
102                 'signaled by the uriPrefix attribute.'),
103         },
104         mask='{uriPrefix,apiVersions}'
105     )
106
107     @api_ims_monitoring.doc('Get Monitoring Version')
108     @api_ims_monitoring.marshal_with(model)
109     def get(self):
110         return {
111             'uriPrefix': request.base_url.rsplit('/', 1)[0],
112             'apiVersions': [{
113                 'version': '1.0.0',
114                 # 'isDeprecated': 'False',
115                 # 'retirementDate': ''
116             }]
117         }