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