a231e5aa5489b3b7628ef2e5636f14fb2bed7f97
[ccsdk/cds.git] / docs / modelingconcepts / data-type.rst
1 .. This work is a derivative of https://wiki.onap.org/display/DW/Modeling+Concepts#Concepts-1581473264
2 .. This work is licensed under a Creative Commons Attribution 4.0
3 .. International License. http://creativecommons.org/licenses/by/4.0
4 .. Copyright (C) 2020 Deutsche Telekom AG.
5
6 .. _data_type:
7
8 Data type
9 ---------
10
11 Represents the **schema** of a specific type of **data**.
12
13 Supports both **primitive** and **complex** data types:
14
15 .. list-table::
16    :widths: 50 50
17    :header-rows: 1
18
19    * - Primitive
20      - Complex
21    * - * string
22        * integer
23        * float
24        * double
25        * boolean
26        * timestamp
27        * null
28      - * json
29        * list
30        * array
31
32 For complex data type, an **entry schema** is required, defining the
33 type of value contained within the complex type, if list or array.
34
35 Users can **create** as many **data type** as needed.
36
37 .. note::
38
39    **Creating Custom Data Types:**
40
41    To create a custom data-type you can use a POST call to CDS endpoint:
42    "<cds-ip>:<cds-port>/api/v1/model-type"
43
44    .. code-block:: python
45       :caption: **Payload:**
46
47       {
48        "model-name": "<model-name>",
49        "derivedFrom": "tosca.datatypes.Root",
50        "definitionType": "data_type",
51        "definition": {
52           "description": "<description>",
53           "version": "<version-number: eg 1.0.0>",
54           "properties": {<add properties of your custom data type in JSON format>},
55           "derived_from": "tosca.datatypes.Root"
56        },
57        "description": "<description",
58        "version": "<version>",
59        "tags": "<model-name>,datatypes.Root.data_type",
60        "creationDate": "<creation timestamp>",
61        "updatedBy": "<name>"
62       }
63
64 Data type are useful to manipulate data during resource resolution.
65 They can be used to format the JSON output as needed.
66
67 List of existing data type:
68 `<https://github.com/onap/ccsdk-cds/tree/master/components/model-catalog/definition-type/starter-type/data_type>`_
69
70 `TOSCA specification
71 <http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.2/csd01/TOSCA-Simple-Profile-YAML-v1.2-csd01.html#_Toc494454187>`_
72
73 **Below is a list of existing data types**
74
75 .. tabs::
76
77    .. tab:: resource-assignment
78
79       **datatype-resource-assignment**
80
81       Used to define entries within artifact-mapping-resource
82       (see tab Artifact Type -> artifact-mapping-resource)
83
84       That datatype represent a **resource** to be resolved. We also refer
85       this as an **instance of a data dictionary** as it's directly linked to
86       its definition.
87
88       .. list-table::
89          :widths: 50 50
90          :header-rows: 1
91
92          * - Property
93            - Description
94          * - property
95            - Defines how the resource looks like (see datatype-property on the right tab)
96          * - input-param
97            - Whether the resource can be provided as input.
98          * - dictionary-name
99            - Reference to the name of the data dictionary (see :ref:`data_dictionary`).
100          * - dictionary-source
101            - Reference the source to use to resolve the resource (see :ref:`resource source`).
102          * - dependencies
103            - List of dependencies required to resolve this resource.
104          * - updated-date
105            - Date when mapping was upload.
106          * - updated-by
107            - Name of the person that updated the mapping.
108
109       `<https://github.com/onap/ccsdk-cds/blob/master/components/model-catalog/definition-type/starter-type/data_type/datatype-resource-assignment.json>`_
110
111       .. code-block:: JSON
112          :caption: **datatype-resource-assignment**
113
114         {
115           "version": "1.0.0",
116           "description": "This is Resource Assignment Data Type",
117           "properties": {
118             "property": {
119               "required": true,
120               "type": "datatype-property"
121             },
122             "input-param": {
123               "required": true,
124               "type": "boolean"
125             },
126             "dictionary-name": {
127               "required": false,
128               "type": "string"
129             },
130             "dictionary-source": {
131               "required": false,
132               "type": "string"
133             },
134             "dependencies": {
135               "required": true,
136               "type": "list",
137               "entry_schema": {
138                 "type": "string"
139               }
140             },
141             "updated-date": {
142               "required": false,
143               "type": "string"
144             },
145             "updated-by": {
146               "required": false,
147               "type": "string"
148             }
149           },
150           "derived_from": "tosca.datatypes.Root"
151         }
152
153    .. tab:: property
154
155       **datatype-property**
156
157       Used to defined the **property** entry of a **resource assignment**.
158
159       .. list-table::
160          :widths: 25 75
161          :header-rows: 1
162
163          * - Property
164            - Description
165          * - type
166            - Whether it's a primitive type, or a defined data-type
167          * - description
168            - Description of for the property
169          * - required
170            - Whether it's required or not
171          * - default
172            - If there is a default value to provide
173          * - entry_schema
174            - If the type is a complex one, such as list, define what is the type of element within the list.
175
176       `<https://github.com/onap/ccsdk-cds/blob/master/components/model-catalog/definition-type/starter-type/data_type/datatype-property.json>`_
177
178       .. code-block:: JSON
179          :caption: **datatype-property**
180
181          {
182            "version": "1.0.0",
183            "description": "This is Resource Assignment Data Type",
184            "properties": {
185              "property": {
186                    "required": true,
187                    "type": "datatype-property"
188              },
189              "input-param": {
190                    "required": true,
191                    "type": "boolean"
192              },
193              "dictionary-name": {
194                    "required": false,
195                    "type": "string"
196              },
197              "dictionary-source": {
198                    "required": false,
199                    "type": "string"
200              },
201              "dependencies": {
202                    "required": true,
203                    "type": "list",
204                    "entry_schema": {
205                       "type": "string"
206                    }
207              },
208              "updated-date": {
209                    "required": false,
210                    "type": "string"
211              },
212              "updated-by": {
213                    "required": false,
214                    "type": "string"
215              }
216            },
217            "derived_from": "tosca.datatypes.Root"
218          }