DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_validator / checker / src / main / resources / tosca / tosca_simple_yaml_1_1.grammar
1 _status_values: &status_values  
2   enum:
3     - supported
4     - unsupported
5     - experimental
6     - deprecated
7
8 #I do not know that the lists and maps qualify as 'primitive' ..
9 _primitive_types: &primitive_types
10   enum: [string,integer,float,boolean,timestamp,list,map,version,range,scalar-unit.size,scalar_unit.frequency,scalar_unit.time]
11
12 #needs custom validation as we have to make sure there are 2 elements and allow for the
13 #UNBOUNDED keyword as second element
14 _range_definition: &range_definition
15   desc: "Section used to declare additional metadata information"
16   required: no
17   type: seq
18   name: range_definition
19   sequence:
20     - type: scalar
21
22 _version_definition: &version_definition
23   desc: "An optional TOSCA version number"
24   required: no
25   type: str
26   name: version_definition
27 #  pattern: <major_version>.<minor_version>[.<fix_version>[.<qualifier>[-<build_version] ] ]
28
29 #common metadata defintion syntax
30 _metadata_definition: &metadata_definition
31   desc: "Section used to declare additional metadata information"
32   required: no
33   type: map
34   mapping:
35     =:
36       type: str
37
38 #see A.5.2
39 #this is where the need of verifying the size of a collection (sequence/map) came from
40 #this is specified as a sequence where each entry is a map with one entry??
41 _constraints_sequence: &constraints_sequence
42   name: constraints_sequence
43   short: 0
44   type: seq
45   sequence:
46     - type: map
47 #      length: 1
48       mapping:
49         equal:
50           desc: "Constrains a property or parameter to a value equal to the value declared."
51           type: any
52           required: no
53         greater_than:
54           desc: "Constrains a property or parameter to a value greater than the value declared"
55           type: scalar
56           required: no
57         greater_or_equal:
58           desc: "Constrains a property or parameter to a value greater than or equal to the value declared."
59           type: scalar
60           required: no
61         less_than:
62           desc: "Constrains a property or parameter to a value less than the value declared"
63           type: scalar
64           required: no
65         less_or_equal:
66           desc: "Constrains a property or parameter to a value less than or equal to the value declared."
67           type: scalar
68           required: no
69         in_range:
70           desc: "Constrains a property or parameter to a value in range of (inclusive) the two values declared."
71           type: seq
72 #          length: 2
73           sequence:
74             - type: scalar
75           required: no
76         valid_values:
77           desc: "Constrains a property or parameter to a value that is in the list of declared values"
78           type: seq
79           sequence:
80             - type: scalar
81           required: no
82         length:
83           desc: "Constrains the property or parameter to a value of a given length."
84           type: int
85           required: no
86         min_length:
87           desc: "Constrains the property or parameter to a value to a minimum length"
88           type: scalar
89           required: no
90         max_length:
91           desc: "Constrains the property or parameter to a value to a maximum length"
92           type: scalar
93           required: no
94         pattern:    
95           desc: "Constrains the property or parameter to a value that is allowed by the provided regular expression."
96           type: str
97           required: no
98
99 # section A.5.3 property_filter_definition
100 # it is a constraints sequence that gets attached to a property ..
101 _property_filter_definition: &property_filter_definition
102   name: property_filter_definition
103   type: map
104   mapping:
105     =:
106       *constraints_sequence
107
108 #section A.5.4 node_filter_definition
109 _node_filter_definition: &node_filter_definition
110   type: map
111   name: node_filter_definition
112   mapping:
113     properties:
114       desc: "property names to constraints to be applied to those properties"
115       required: no
116       type: seq
117       sequence:
118          - *property_filter_definition
119 #        - type: map
120 #          mapping: 
121 #            =:
122 #              *constraints_sequence
123     capabilities:
124       desc: ""
125       required: no
126       type: seq
127       sequence:
128         - type: map
129           name: node_filter_capabilities_sequence
130           desc: "the key is a capability name or type"
131           mapping:
132             =: 
133               name: node_filter_capabilities_entry
134               type: map
135               mapping:
136                 properties:
137                   desc: "the capability properties and their constraints"
138                   name: node_filter_capabilities_properties
139                   type: seq        
140                   sequence:
141                     - type: map
142                       name: node_filter_capabilities_property
143                       mapping:
144                         =: *constraints_sequence
145
146 #used in property and attribute definitions
147 _entry_schema_definition: &entry_schema_definition
148   desc: "The optional key that is used to declare the name of the Datatype definition for entries of set types such as the TOSCA list or map"
149   name: entry_schema_definition
150   required: no
151   type: map
152   short: type
153   mapping: 
154     "type":
155       desc: "collection element type"
156       required: yes
157       type: str
158     description:
159       required: no
160       type: str
161     constraints:
162       *constraints_sequence
163
164 # see section A.5.5
165 _artifact_definition: &artifact_definition
166   type: map
167   name: artifact_definition
168   short: implementation # assumes type can be inferred ..
169   mapping:
170     "type":
171       desc: "The required artifact type for the artifact definition"
172       required: yes
173       type: str
174     description:
175       desc: "The optional description for the artifact definition"
176       required: no
177       type: str
178     file:
179       desc: "The optional URI string (relative or absolute) which can be used to locate the artifacts file."
180       required: no
181       type: str
182     repository:
183       desc: "The optional name of the repository definition which contains the location of the external repository that contains the artifact"
184       required: no
185       type: str
186     deploy_path:    
187       desc: "The file path the associated file would be deployed into within the target nodes container."
188       required: no
189       type: str
190
191 # see section 3.5.5
192 _repository_definition: &repository_definition
193   type: map
194   name: repository_definition
195   short: url
196   mapping:
197     description:
198       desc: "The optional description for the repository."
199       required: no
200       type: str
201     url:
202       desc: "The required URL or network address used to access the repository"
203       required: yes
204       type: str
205     credential:
206       desc: "The optional Credential used to authorize access to the repository"
207       required: no
208       type: str
209
210 #see section 3.5.7
211 _import_definition: &import_definition
212   type: map
213   name: import_definition
214   short: file
215   mapping:
216     file:
217       desc: "file URI"
218       required: yes
219       type: str
220     repository:
221       desc: "symbolic name of the repository definition where the imported file can be found"
222       required: no
223       type: str
224     namespace_uri:
225       desc: "namespace URI to that will be applied to type definitions found within the imported file"
226       required: no
227       type: str
228     namespace_prefix:
229       desc: "optional namespace prefix (alias) that will be used to indicate the namespace_uri when forming a qualified name (i.e., qname) when referencing type definitions from the imported"
230       required: no
231       type: str
232
233 #see section 3.5.8
234 _property_definition: &property_definition
235   type: map
236   name: property_definition
237   mapping:
238     "type":
239       type: str
240       required: yes
241 #not as easy, it can be an user defined data type
242 #      <<: *primitive_types
243     description:
244       type: str
245       required: no
246     constraints:
247       desc: "The optional list of sequenced constraint clauses for the Data Type."
248       required: no
249       <<: *constraints_sequence
250     default:
251       type: any
252       required: no
253     "required":
254       type: bool
255       required: no
256     status:
257       type: str
258       required: no
259       <<: *status_values
260     entry_schema:
261       <<: *entry_schema_definition
262 #      desc: "used to declare the name of the Datatype definition for entries of set types such as the TOSCA list or map."
263 #      type: str
264 #      required: no
265
266 #see section A.5.8
267 #_property_assignment_definition: &property_assignment_definition
268
269 #see 3.5.10
270 _attribute_definition: &attribute_definition
271   type: map
272   name: attribute_definition
273   mapping:
274     "type":
275       type: str
276       required: yes
277 #      <<: *primitive_types
278     description:
279       type: str
280       required: no
281     default:
282       type: any
283       required: no
284     status:
285       desc: "The optional status of the attribute relative to the specification or implementation"
286       type: str
287       required: no
288       <<: *status_values
289     entry_schema:
290       <<: *entry_schema_definition
291
292 #see section 3.5.11
293 #here again, we must support the short form which is the most common
294 _attribute_assignment_definition: &attribute_assignment_definition
295   type: map
296   name: attribute_assignment_definition
297   mapping:
298     description:
299       desc: "The optional description of the attribute."
300       required: no
301       type: str
302     value:
303 #actually 'value | value_expression'
304       desc: "represent the type-compatible value to assign to the named attribute. Attribute values may be provided as the result from the evaluation of an expression or a function"
305       required: yes
306       type: any
307
308
309 #see 3.5.12
310 _parameter_definition: &parameter_definition
311   type: map
312   name: parameter_definition
313   mapping:
314     "type":
315       type: str
316       required: no
317 #not as easy, it can be an user defined data type
318 #      <<: *primitive_types
319     description:
320       type: str
321       required: no
322     constraints:
323       desc: "The optional list of sequenced constraint clauses for the Data Type."
324       required: no
325       <<: *constraints_sequence
326     default:
327       type: any
328       required: no
329     "required":
330       type: bool
331       required: no
332     status:
333       type: str
334       required: no
335       <<: *status_values
336     value:
337       desc: "represent the type-compatible value to assign to the named parameter. Parameter values may be provided as the result from the evaluation of an expression or a function"
338       required: yes
339       type: any
340     entry_schema:
341       <<: *entry_schema_definition
342
343
344
345
346 # see spec section 3.5.13
347
348 # see spec section 3.5.13.2: variant to be used in node or relationship type definitions 
349 _type_operation_definition: &type_operation_definition
350   type: map
351   name: type_operation_definition
352   short: implementation
353   mapping:
354     description:
355       desc: "The optional description string for the associated named operation."
356       required: no
357       type: str
358     implementation:
359       desc: "The optional implementation artifact name (e.g., a script file name within a TOSCA CSAR file)"
360       required: no
361       type: str
362     inputs:
363       desc: ""
364       required: no
365       type: map
366       mapping:
367         =:
368           desc: "a property value or an expression providing a input value"
369           name: property_assignment
370           type: any
371
372 # from 3.5.13.2.3
373 _template_operation_definition: &template_operation_definition
374   type: map
375   name: template_operation_definition
376   short: implementation
377   mapping:
378     description:
379       desc: "The optional description string for the associated named operation."
380       required: no
381       type: str
382     implementation:
383       desc: "The optional implementation artifact name (e.g., a script file name within a TOSCA CSAR file)"
384       name: template_operation_implementation_definition
385       required: no
386       short: primary
387       type: map
388       mapping:
389         primary:
390           desc: "The optional implementation artifact name (e.g., the primary script file name within a TOSCA CSAR file). "
391           required: no
392           type: str
393         dependencies:
394           desc: "The optional list of one or more dependent or secondary implementation artifact name which are referenced by the primary implementation artifact (e.g., a library the script installs or a secondary script)"
395           required: no
396           type: seq
397           sequence: 
398             - type: str
399     inputs:
400       desc: ""
401       required: no
402       type: map
403       mapping:
404         =:
405           desc: "a property value or an expression providing a input value"
406           name: property_assignment
407           type: any
408
409
410 # see section 3.5.14, specifically 3.5.14.2.1 : definition to be used in node or relationship type definition
411 _type_interface_definition: &type_interface_definition
412   type: map
413   name: type_interface_definition
414   mapping:
415     "type":
416       desc: "represents the required name of the Interface Type for the interface definition"
417       required: yes
418       type: str
419     inputs:
420       desc: "The optional list of input property definitions available to all defined operations"
421       type: map
422       mapping:
423         =:
424           *property_definition
425     =:
426       *type_operation_definition
427
428 # see section 3.5.14.2.2, extended notation to be used in node or relationship template definitions
429 _template_interface_definition: &template_interface_definition
430   type: map
431   name: template_interface_definition
432   mapping:
433     inputs:
434       desc: "The optional list of input property definitions available to all defined operations"
435       type: map
436       mapping:
437         =:
438           desc: "a property value or an expression providing a property value"
439           name: property_assignment
440           type: any
441     =:
442       *template_operation_definition
443
444 # see section 3.5.15
445 _event_filter_definition: &event_filter_definition
446   type: map
447   name: event_filter_definition
448   mapping:
449     node:
450       desc: "The required name of the node type or template that contains either the attribute to be monitored or contains the requirement  that references the node that contains the attribute to be monitored"
451       required: yes
452       type: str
453     requirement:
454       desc: "The optional name of the requirement within the filter\92s node that can be used to locate a referenced node that contains an attribute to monitor."
455       required: no
456       type: str
457     capability:
458       desc: "The optional name of a capability within the filter\92s node or within the node referenced by its requirement that contains the attribute to monitor."
459       required: no
460       type: str
461
462 # see section 3.5.16
463 # to be revised, based on working version
464 _trigger_definition: &trigger_definition
465   type: map
466   name: trigger_definition
467   mapping:
468     description:
469       desc: ""
470       required: no
471       type: str
472     event_type:
473       desc: "The required name of the event type that activates the trigger\92s action."
474       required: yes
475       short: type
476       type: map
477       mapping:
478         type:
479           required: yes
480           type: str
481     schedule:
482       desc: ""
483       required: no
484       type: str
485     target_filter:
486       desc: ""
487       required: no
488       <<: *event_filter_definition
489 #the section made up of condition/constraint/period/evaluations/method has a mistmatching example in the spec doc ..
490     condition:
491       desc: ""
492       required: no
493       <<: *constraints_sequence
494     constraint:
495       desc: ""
496       required: no
497       <<: *constraints_sequence
498     period:
499       desc: "The optional period to use to evaluate for the condition"
500       required: no
501       type: int
502     evaluations:
503       desc: ""
504       required: no
505       type: int
506     method:
507       desc: "The optional statistical method name to use to perform the evaluation of the condition"
508       required: no
509       type: str
510     actions:
511       desc: "The if of the workflow to be invoked when the event is triggered and the condition is met (i.e, evaluates to true) OR the required operation to invoke when the event is triggered and the condition is met (i.e., evaluates to true)."
512       required: yes
513       type: str # or operation definition?
514
515
516 # see section 3.5.17
517 # to be revised, based on working version
518 # example on 3.5.17.4 shows this as a sequence of maps, each with one entry @!?
519 _workflow_activity_definition: &workflow_activity_definition
520   type: map
521   name: workflow_activity_definition
522   mapping:
523     delegate:
524       desc: ""
525       required: no
526       type: str
527     set_state:
528       desc: ""
529       required: no
530       type: str
531     call_operation:
532       desc: ""
533       required: no
534       type: str
535     inline:
536       desc: ""
537       required: no
538       type: str
539
540
541 # see section 3.5.18
542 # to be revised, based on working version
543 _workflow_assertion_definition: &workflow_assertion_definition
544   name: workflow_assertion_definition
545   type: map
546   mapping:
547     =:
548       *constraints_sequence
549
550
551 # see section 3.5.19
552 # to be revised, based on working version
553 # it employs a recursive definition which yaml allows but teh parsers we've tried complain about, i.e the pattern
554 #    foo: &foo
555 #      bar: *foo
556 # is theoretically allowed in YAML
557 _workflow_condition_clause_definition: &workflow_condition_clause_definition
558   name: workflow_condition_clause_definition
559   type: seq
560   sequence:
561     - type: map
562       name: workflow_condition_clause_entry
563       # here too length=1 would be good as a map can have only one entry
564       mapping:
565         assert:
566           <<: *workflow_assertion_definition
567         and:
568           # recursive definition ! yaml parser cannot deal with it
569           # <<: *workflow_condition_clause_definition
570           type: seq
571           sequence:
572             -type: map
573         or:
574           # recursive definition ! yaml parser cannot deal with it
575           # <<: *workflow_condition_clause_definition
576           type: seq
577           sequence:
578             -type: map
579   
580
581
582 # see section 3.5.20
583 # to be revised, based on working version
584 # here too, not clear if this a map or a sequence .. there is no example
585 _workflow_precondition_definition: &workflow_precondition_definition
586   name: workflow_precondition_definition
587   type: map
588   mapping:
589     target:
590       required: yes
591       type: str
592     target_relationship:
593       required: no
594       type: str
595     condition:
596       desc: "list of condition clause definition .. !@#$%"
597       <<: *workflow_condition_clause_definition
598
599
600 # see section 3.5.21
601 # to be revised, based on working version
602 _workflow_step_definition: &workflow_step_definition
603   name: workflow_step_definition
604   desc: "A workflow step allows to define one or multiple sequenced activities in a workflow and how they are connected to other steps in the workflow. They are the building blocks of a declarative workflow."
605   type: map
606   mapping:
607     target:
608       required: yes
609       type: str
610       desc: "The target of the step (this can be a node template name, a group name)"
611     target_relationship:
612       required: no
613       type: str
614     operation_host:
615       required: no
616       type: str
617     filter:
618       desc: "Filter is a map of attribute name, list of constraint clause that allows to provide a filtering logic"
619       type: map
620       mapping:
621         =:
622           *constraints_sequence
623     activities:
624       desc: ""
625       type: seq
626       sequence:
627         <<: *workflow_activity_definition
628     on_success:
629       desc: "The optional list of step names to be performed after this one has been completed with success (all activities has been correctly processed)."
630       type: seq
631       sequence:
632         - type: str
633     on_failure:
634       desc: "The optional list of step names to be called after this one in case one of the step activity failed."
635       type: seq
636       sequence:
637         - type: str
638
639
640
641
642 # 3.6 section: type specific definitions
643
644 # see section 3.6.1
645 _capability_definition: &capability_definition
646   type: map
647   name: capability_definition
648   short: type
649   mapping:
650     "type":
651       desc: "The required name of the Capability Type the capability definition is based upon"
652       required: yes
653       type: str
654     description:
655       desc: "The optional description of the Capability definition"
656       required: no
657       type: str
658     properties:
659       desc: ""
660       required: no
661       type: map
662       mapping:
663        =:
664           *property_definition
665     attributes:
666       desc: "An optional list of property definitions for the Capability definition"
667       required: no
668       type: map
669       mapping:
670         =:
671           *attribute_definition
672     valid_source_types:
673       desc: ""
674       required: no
675       type: seq
676       sequence:
677         - type: str
678     occurrences:
679       desc: "The optional minimum and maximum occurrences for the capability."
680       required: no
681       <<: *range_definition
682
683
684
685
686 # see section A.6.2
687 #
688 _requirement_definition: &requirement_definition
689   type: map
690   name: requirement_definition
691   short: capability  #as per A.6.2.2.1
692   mapping:
693     capability:
694       desc: "The required reserved keyname used that can be used to provide the name of a valid Capability Type that can fulfil the requirement"
695       required: yes
696       type: str
697     node:
698       desc: "The optional reserved keyname used to provide the name of a valid Node Type that contains the capability definition that can be used to fulfil the requirement. "
699       required: no
700       type: str
701     relationship:
702 # and from section A.6.2.1, this one is an oddball
703       desc: "The optional reserved keyname used to provide the name of a valid Relationship Type to construct when fulfilling the requirement."
704       required: no
705       name: requirement_relationship_definition
706       short: type
707       type: map
708       mapping:
709         type:
710           desc: "The optional reserved keyname used to provide the name of the Relationship Type for the requirement definitions relationship keyname.
711 "
712           required: yes
713           type: str
714         interfaces:
715           #not clear which interface definition is to be used here
716           desc: "allows augmentation (additional properties and operations) of the interfaces defined by the relationship type indicated above"
717           required: no
718           type: map
719           mapping:
720             =:
721               *type_interface_definition
722     occurrences:
723       desc: "The optional minimum and maximum occurrences for the requirement."
724       required: no
725       <<: *range_definition
726
727 # see section 3.6.4
728 _artifact_type_definition: &artifact_type_definition
729   type: map
730   name: artifact_type_definition
731   mapping:
732     derived_from:
733       desc: "An optional parent Artifact Type name the Artifact Type derives from"
734       required: no
735       type: str
736     version:
737       <<: *version_definition
738     metadata:
739       <<: *metadata_definition
740     description:
741       desc: "An optional description for the Artifact Type."
742       required: no
743       type: str
744     mime_type:
745       desc: "The required mime type property for the Artifact Type."
746       required: no
747       type: str
748     file_ext:
749       desc: "The required file extension property for the Artifact Type"
750       required: no
751       type: seq
752       sequence:
753         - type: str
754     properties:
755       desc: "An optional list of property definitions for the Artifact Type"
756       required: no
757       type: map
758       mapping:
759         =:
760           *property_definition
761
762 #see spec section #3.6.5
763 _interface_type_definition: &interface_type_definition
764   type: map
765   name: interface_type_definition
766   mapping:
767     derived_from:
768       desc: "The name of the Interface Type this Interface Type definition derives from"
769       required: no
770       type: str
771     description:
772       desc: "The optional description for the Interface Type."
773       required: no
774       type: str
775     version:
776       <<: *version_definition
777     metadata:
778       <<: *metadata_definition
779     inputs:
780       desc: "The optional list of input property definitions available to all defined operations"
781       type: map
782       mapping:
783         =:
784           type: str
785           desc: "property_name to property_value(_expression) mapping"
786     =:
787       *type_operation_definition
788
789 #see spec section #3.6.6
790 _data_type_definition: &data_type_definition
791   type: map
792   name: data_type_definition
793   mapping:
794     derived_from:
795       desc: "The optional key used when a datatype is derived from an existing TOSCA Data Type."
796       required: no
797       type: str
798     description:
799       desc: "The optional description for the Data Type."
800       required: no
801       type: str
802     version:
803       <<: *version_definition
804     metadata:
805       <<: *metadata_definition
806     constraints:
807       desc: "The optional list of sequenced constraint clauses for the Data Type."
808       <<: *constraints_sequence
809     properties:
810       desc: "The optional list property definitions that comprise the schema for a complex Data Type in TOSCA"
811       type: map
812       mapping:
813         =:
814           *property_definition
815
816 # see section A.6.6
817 _capability_type_definition: &capability_type_definition
818   type: map
819   name: capability_type_definition
820   mapping:
821     derived_from:
822       desc: "An optional parent capability type name this new Capability Type derives from."
823       required: no
824       type: str
825     description:
826       desc: "An optional description for the Capability Type"
827       required: no
828       type: str
829     properties:
830       desc: "An optional list of property definitions for the Capability Type."
831       required: no
832       type: map
833       mapping:
834         =:
835           *property_definition
836     attributes:
837       desc: "An optional list of attribute definitions for the Capability Type"
838       required: no
839       type: map
840       mapping:
841         =:
842           *attribute_definition
843     valid_source_types:
844       desc: "An optional list of one or more valid names of Node Types that are supported as valid sources of any relationship established to the declared Capability Type"
845       required: no
846       type: seq
847       sequence:
848         - type: str
849
850 # section A.6.7 requirement definition: TOSCA YAML profile relies on capability types to 
851 # define requirements 
852
853 # see section #3.6.10
854 _relationship_type_definition: &relationship_type_definition
855   type: map
856   name: relationship_type_definition
857   mapping:
858     derived_from:
859       desc: "An optional parent Relationship Type name the Relationship Type derives from"
860       required: no
861       type: str
862     description:
863       desc: "An optional description for the Relationship Type."
864       required: no
865       type: str
866     version:
867       <<: *version_definition
868     metadata:
869       <<: *metadata_definition
870     properties:
871       desc: "An optional list of property definitions for the Relationship Type"
872       required: no
873       type: map
874       mapping:
875         =:
876           *property_definition
877     attributes:
878       desc: "An optional list of attribute definitions for the Relationship Type"
879       required: no
880       type: map
881       mapping:
882         =:
883           *attribute_definition
884     interfaces:
885       desc: "An optional list of interface definitions interfaces supported by the Relationship Type"
886       required: no
887       type: map
888       mapping:
889         =:
890           *type_interface_definition
891     valid_target_types:
892       desc: "An optional list of one or more names of Capability Types that are valid targets for this relationship. "
893       required: no
894       type: seq
895       sequence:
896         - type: str
897
898 #see section 3.6.11
899 _group_type_definition: &group_type_definition
900   type: map
901   name: group_type_definition
902   mapping:
903     derived_from:
904       desc: "An optional parent Group Type name this new Group Type derives from"
905       required: no
906       type: str
907     description:
908       desc: "An optional description for the Group Type"
909       required: no
910       type: str
911     version:
912       <<: *version_definition
913     metadata:
914       <<: *metadata_definition
915     properties:
916       desc: "An optional list of property definitions for the Group Type."
917       required: no
918       type: map
919       mapping:
920         =:
921           *property_definition
922     targets:
923       desc: "An optional list of one or more names of Node Types that are valid
924 (allowed) as members of the Group Type."
925       required: no
926       type: seq
927       sequence:
928         - type: str
929     interfaces:
930       desc: "An optional list of interface definitions supported by the Group Type"
931       required: no
932       type: map
933       mapping:
934         =:
935           *type_interface_definition
936 #TODO: group types have gained capabilities and requirements
937
938
939 #see section 3.6.12
940 _policy_type_definition: &policy_type_definition
941   type: map
942   name: policy_type_definition
943   mapping:
944     derived_from:
945       desc: "An optional parent Policy Type name this new Policy Type derives from"
946       required: no
947       type: str
948     description:
949       desc: "An optional description for the Policy Type"
950       required: no
951       type: str
952     version:
953       <<: *version_definition
954     metadata:
955       <<: *metadata_definition
956     properties:
957       desc: "An optional list of property definitions for the Policy Type."
958       required: no
959       type: map
960       mapping:
961         =:
962           *property_definition
963     targets:
964       desc: "An optional list of valid Node Types or Group Types the Policy Type
965 can be applied to"
966       required: no
967       type: seq
968       sequence:
969         - type: str
970 #TODO:
971 #    triggers:
972
973 # see section #3.6.9
974 _node_type_definition: &node_type_definition
975   type: map
976   name: node_type_definition
977   mapping:
978     derived_from:
979       desc: "An optional parent Node Type name this new Node Type derives from"
980       required: no
981       type: str
982     description:
983       desc: "An optional description for the Node Type"
984       required: no
985       type: str
986     version:
987       <<: *version_definition
988     metadata:
989       <<: *metadata_definition
990     properties:
991       desc: "An optional list of property definitions for the Node Type."
992       required: no
993       type: map
994       mapping:
995         =:
996           *property_definition
997     attributes:
998       desc: "An optional list of attribute definitions for the Node Type.
999 "
1000       required: no
1001       type: map
1002       mapping:
1003         =:
1004           *attribute_definition
1005     requirements:
1006       desc: "An optional sequenced list of requirement definitions for the Node Type.
1007 "
1008       required: no
1009       type: seq
1010       sequence:
1011         - type: map
1012           mapping:
1013             =:
1014               *requirement_definition
1015     capabilities:
1016       desc: "An optional list of capability definitions for the Node Type"
1017       required: no
1018       type: map
1019       mapping:
1020         =:
1021           *capability_definition
1022     interfaces:
1023       desc: ""
1024       required: no
1025       type: map
1026       mapping:
1027         =:
1028           *type_interface_definition
1029     artifacts:
1030       desc: "An optional list of named artifact definitions for the Node Type"
1031       required: no
1032       type: map
1033       mapping:
1034         =:
1035           *artifact_definition
1036
1037 # A.7 Template specific definitions
1038
1039 # see section A.7.1
1040 _capability_assignment_definition: &capability_assignment_definition
1041   type: map
1042   name: capability_assignment_definition
1043   mapping:
1044     properties:
1045       # list of property assignments
1046       desc: "An optional list of property definitions for the Capability definition"
1047       required: no
1048       type: map
1049       mapping:
1050         =:
1051           desc: "a property value or an expression providing a property value"
1052           name: property_assignment
1053           type: any
1054     attributes:
1055       # list of attribute assignments
1056       desc: "An optional list of attribute definitions for the Capability definition"
1057       required: no
1058       type: map
1059       mapping:
1060         =:
1061           desc: ""
1062           name: attribute_assignment
1063           type: any
1064
1065 # see section A.7.2
1066 _requirement_assignment_definition: &requirement_assignment_definition
1067   type: map
1068   name: requirement_assignment_definition
1069   short: node
1070   mapping:
1071     capability:
1072       desc: " used to provide the name of either a: Capability definition within a target node template that can fulfill the requirement or Capability Type that the provider will use to select a type-compatible target node template to fulfill the requirement at runtime."
1073       required: no
1074       type: str
1075     node:
1076 #why is this a reference to a node type and not to a node template??
1077       desc: "used to identify the target node of a relationship: Node Template name that can fulfil the target node requirement or Node Type name that the provider will use to select a type-compatible node template to fulfil the requirement at runtime"
1078       required: no
1079       type: str
1080     relationship:
1081       desc: ""
1082       required: no
1083 #fins a better name      name: relationship_definition
1084       type: map
1085       short: type
1086       mapping:
1087         "type":
1088           desc: "The optional reserved keyname used to provide the name of the Relationship Type for the requirement assignments relationship keyname"
1089           required: no
1090           type: str
1091         properties:
1092           desc: ""
1093           required: no
1094           type: map
1095           mapping:
1096             =:
1097               desc: "a property value or an expression providing a property value"
1098               name: property_assignment
1099               type: any
1100         interfaces:
1101           desc: "from A.5.12.2.2, right?"
1102           required: no
1103           type: map
1104           mapping:
1105             =:
1106               *template_interface_definition
1107     node_filter:
1108       desc: "The optional filter definition that TOSCA orchestrators or providers would use to select a type-compatible target node that can fulfill the associated abstract requirement at runtime."
1109       required: no
1110       <<: *node_filter_definition
1111
1112 # see section 3.7.3
1113 _node_template_definition: &node_template_definition
1114   type: map
1115   name: node_template_definition
1116   mapping:
1117     "type":
1118       desc: "The required name of the Node Type the Node Template is based upon"
1119       required: yes
1120       type: str
1121     description:
1122       desc: "An optional description for the Node Template"
1123       required: no
1124       type: str
1125     metadata:
1126       <<: *metadata_definition
1127     directives:
1128       desc: "An optional list of directive values to provide processing instructions to orchestrators and tooling."
1129       required: no
1130       type: seq
1131       sequence:
1132         - type: str
1133     properties:
1134 #custom check needs to be added: the value or expression providing the property value
1135 #needs to be compatible with the property definition
1136       desc: "An optional list of property value assignments for the Node Template."
1137       required: no
1138       type: map
1139       mapping:
1140         =:
1141           type: any
1142           name: property_assignment
1143           desc: "a property value or an expression providing a property value"
1144     attributes:
1145       desc: "An optional list of attribute value assignments for the Node Template"
1146       required: no
1147       type: map
1148       mapping:
1149         =:
1150           *attribute_assignment_definition
1151     requirements:
1152       desc: "An optional sequenced list of requirement assignments for the Node Template."
1153       required: no
1154       type: seq
1155       sequence:
1156         - type: map
1157           mapping:
1158             =:
1159               *requirement_assignment_definition
1160     capabilities:
1161       desc: "An optional list of capability assignments for the Node Template."
1162       required: no
1163       type: map
1164       mapping:
1165         =:
1166           *capability_assignment_definition
1167     interfaces:
1168       desc: "An optional list of named interface definitions for the Node Template"
1169       required: no
1170       type: map
1171       mapping:
1172         =:
1173           *template_interface_definition
1174     artifacts:
1175       desc: "An optional list of named artifact definitions for the Node Template.
1176 "
1177       required: no
1178       type: map
1179       mapping:
1180         =:
1181           *artifact_definition
1182     node_filter:
1183       desc: "The optional filter definition that TOSCA orchestrators would use to select the correct target node. This keyname is only valid if the directive has the value of 'selectable' set."
1184       required: no
1185       <<: *node_filter_definition 
1186     copy:
1187       desc: "The optional (symbolic) name of another node template to copy into (all keynames and values) and use as a basis for this node template."
1188       required: no
1189       type: str
1190
1191 # see section 3.7.4
1192 _relationship_template_definition: &relationship_template_definition
1193   type: map
1194   name: relationship_template_definition
1195   mapping:
1196     "type":
1197       desc: "The required name of the Relationship Type the Relationship Template is based upon"
1198       required: yes
1199       type: str
1200     description:
1201       desc: "An optional description for the Relationship Template"
1202       required: no
1203       type: str
1204     metadata:
1205       <<: *metadata_definition
1206     properties:
1207       desc: "An optional list of property assignments for the Relationship Template."
1208       required: no
1209       name: properties_assignment_validation
1210       type: map
1211       mapping:
1212         =:
1213           type: any
1214 #scalar
1215           desc: "an expression providing a property value"
1216     attributes:
1217       desc: "An optional list of attribute value assignments for the Relationship Template"
1218       required: no
1219       name: attributes_assignment_validation
1220       type: map
1221       mapping:
1222         =: 
1223           type: scalar
1224           desc: "an expression providing an attribute value"
1225     interfaces:
1226       desc: "An optional list of named interface definitions for the Relationship Template ('augmentation' is allowed here)"
1227       required: no
1228       type: map
1229       mapping:
1230         =:
1231           *template_interface_definition
1232     copy:
1233       desc: "The optional (symbolic) name of another relationship template to copy into (all keynames and values) and use as a basis for this relationship template."
1234       required: no
1235       type: str
1236
1237
1238 # see section 3.7.5
1239 _group_definition: &group_definition
1240   type: map
1241   name: group_definition
1242   mapping:
1243     "type":
1244       desc: "The required name of the group type the group definition is based upon"
1245       required: yes
1246       type: str
1247     description:
1248       desc: "The optional description for the group definition"
1249       required: no
1250     metadata:
1251       <<: *metadata_definition
1252     properties:
1253       desc: " represents the optional list of property assignments for the group definition that provide values for properties defined in its declared Group Type"
1254       required: no
1255       type: map
1256       mapping:
1257         =:
1258           type: any
1259           name: property_assignment
1260     members:
1261       desc: "contains the required list of one or more node template names (within the same topology template) that are members of this logical group"
1262       required: yes
1263       type: seq
1264       sequence:
1265         - type: str
1266     interfaces:
1267       desc: "represents the optional list of interface definitions for the group definition that augment those provided by its declared Group Type"
1268       required: no
1269       type: map
1270       mapping:
1271         =:
1272           *template_interface_definition
1273
1274 # see section 3.7.6
1275 _policy_template_definition: &policy_template_definition
1276   type: map
1277   name: policy_definition
1278   mapping:
1279     "type":
1280       desc: "The required name of the policy type the policy definition is based upon"
1281       required: yes
1282       type: str
1283     description:
1284       desc: "The optional description for the policy definition"
1285       required: no
1286     metadata:
1287       <<: *metadata_definition
1288     properties:
1289       desc: "represents the optional list of property assignments for the policy definition that provide values for properties defined in its declared Policy Type"
1290       required: no
1291       type: map
1292       mapping:
1293         =:
1294           type: any
1295           name: property_assignment
1296     targets:
1297       desc: "represents the optional list of names of node templates or groups that the policy is to applied to"
1298       required: no
1299       type: seq
1300       sequence:
1301         - type: str
1302
1303 #see section 3.7.7, obviously incomplete spec
1304 _workflow_definition: &workflow_definition
1305   type: map
1306   name: workflow_definition
1307   mapping:
1308     description:
1309       desc: "The optional description for the workflow definition"
1310       required: no
1311     metadata:
1312       <<: *metadata_definition
1313     inputs:
1314       desc: "optional list of input parameter definitions"
1315       required: no
1316       type: map
1317       mapping:
1318         =:
1319           *property_definition
1320     preconditions:
1321       desc: "List of preconditions to be validated before the workflow can be processed."
1322       required: no
1323       type: any #incomplete spec 
1324     steps:
1325       desc: ""
1326       required: no
1327       type: any #incomplete spec 
1328
1329
1330 # see section 3.8 Topology Template definition:  defines the topology template of a cloud application.
1331 # described as a a reusable grammar as it can be a part of a service template definition 
1332 _topology_template_definition: &topology_template_definition
1333   type: map
1334   name: topology_template_definition
1335   mapping:
1336     description:
1337       desc: "a description of the topology template"
1338       required: no
1339       type: str
1340     inputs:
1341       desc: "definition of input parameters for the topology template"
1342       name: inputs
1343       required: no
1344       type: map
1345       mapping:
1346         =:
1347           *property_definition
1348     node_templates:
1349       desc: "definition of the node templates of the topology"
1350       name: node_templates
1351       required: no
1352       type: map
1353       mapping:
1354         =:
1355           *node_template_definition
1356     relationship_templates:
1357       desc: "definition of the relationship templates of the topology"
1358       required: no
1359       name: relationship_templates
1360       type: map
1361       mapping:
1362         =:
1363           *relationship_template_definition
1364     outputs:
1365       desc: "definition of output parameters for the topology template"
1366       name: outputs
1367       required: no
1368       type: map
1369       mapping:
1370         =:
1371           *attribute_assignment_definition
1372     groups:
1373       desc: "An optional list of Group definitions whose members are node templates defined within this same Topology Template"
1374       name: groups
1375       required: no
1376       type: map
1377       mapping:
1378         =:
1379           *group_definition
1380     policies:
1381  # see 8.2.3, initially the list is not described as sequenced but then the grammar shows it as such !?
1382       desc: "An optional sequenced?? list of Policy definitions for the Topology Template."
1383       name: policies
1384       required: no
1385       type: seq
1386       sequence:
1387         - type: map
1388           mapping:
1389             =:
1390               *policy_template_definition
1391     workflows:
1392       desc: "optional map of imperative workflow definition for the Topology Template"
1393       name: workflows
1394       required: no
1395       type: map
1396       mapping:
1397         =:
1398           *workflow_definition
1399     substitution_mappings:
1400 # one possible short-coming that is visible here is that the definition of the capability
1401 # and requirements mappings are given in the spec only with the short/inline version of a 
1402 # YAML list/sequence, which cannot be enforced here .. 
1403       desc: " a description of the topology template"
1404       name: substitution_mappings
1405       required: no
1406       type: map
1407       mapping:
1408         node_type:
1409           desc: "node type name"
1410           required: yes
1411           type: str
1412         capabilities:
1413           desc: "map_of_capability_mappings_to_expose"
1414           type: map
1415           mapping:
1416             =:
1417               type: seq
1418               sequence:
1419                 - type: str
1420         requirements:      
1421           desc: "map_of_requirement_mapping_to_expose"
1422           type: map
1423           mapping:
1424             =:
1425               type: seq
1426               sequence:
1427                 - type: str
1428
1429
1430 # see A.9 Service Template definition: A TOSCA Service Template (YAML) document contains
1431 # element definitions of building blocks for cloud application, or complete models of cloud applications. 
1432
1433 type: map
1434 name: service_template_definition
1435 mapping:
1436   tosca_definitions_version:
1437     desc: "Required TOSCA Definitions version string"
1438     required: yes
1439     type: str
1440     enum: [tosca_simple_yaml_1_1, tosca_simple_yaml_1_1_0]
1441
1442   tosca_default_namespace:
1443     desc: "Optional. default namespace (for type schema)"
1444     required: no
1445     type: str
1446
1447   metadata:
1448     desc: "Optional metadata keyname: value pairs"
1449     name: metadata
1450     required: no
1451     type: map
1452     mapping:
1453       template_name:
1454         desc: "Optional name of this service template"
1455         required: no
1456         type: str
1457       template_author:
1458         desc: "Optional author of this service template"
1459         required: no
1460         type: str
1461       template_version:
1462         desc: "Optional version of this service template"
1463         required: no
1464         type: str
1465       =:
1466         desc: "User defined entry"
1467         required: no
1468         type: str
1469
1470 #to add, the spec says: "Optional list of domain or profile specific metadata keynames"
1471
1472   description:
1473     desc: "Optional description of the definitions inside the file"
1474     required: no
1475     type: str
1476
1477   imports:
1478     desc: "ordered list of import statements for importing other definitions files"
1479     name: imports
1480     required: no
1481     type: seq
1482     sequence:
1483       - type: map
1484         mapping:
1485           =:
1486             *import_definition
1487
1488   dsl_definitions:
1489     desc: "list of YAML alias anchors (or macros)"
1490     name: dsl_definitions
1491     required: no
1492     type: map
1493     mapping:
1494       =:
1495         desc: "some piece of valid yaml that makes the anchor/alias definition" 
1496         type: any
1497         required: no
1498
1499   repositories:
1500     desc: "list of external repository definitions which host TOSCA artifacts"
1501     name: repositories
1502     required: no
1503     type: map
1504     mapping:
1505       =:
1506         *repository_definition
1507
1508   data_types:
1509     desc: "list of TOSCA datatype definitions"
1510     name: data_types
1511     required: no
1512     type: map
1513     mapping:
1514       =:
1515         *data_type_definition
1516
1517   node_types:
1518     desc: "list of node type definitions"
1519     name: node_types
1520     required: no
1521     type: map
1522     mapping:
1523       =:
1524         *node_type_definition
1525
1526   capability_types:
1527     desc: "list of capability type definitions"
1528     name: capability_types
1529     required: no
1530     type: map
1531     mapping:
1532       =:
1533         *capability_type_definition
1534
1535   relationship_types:
1536     desc: "list of relationship type definitions"
1537     name: relationship_types
1538     required: no
1539     type: map
1540     mapping:
1541       =:
1542         *relationship_type_definition
1543
1544   artifact_types:
1545     desc: "list of artifact type definitions"
1546     name: artifact_types
1547     required: no
1548     type: map
1549     mapping:
1550       =:
1551         *artifact_type_definition
1552
1553   interface_types:
1554     desc: "list of interface type definitions"
1555     name: interface_types
1556     required: no
1557     type: map
1558     mapping:
1559       =:
1560         *interface_type_definition
1561
1562   group_types:
1563     desc: "list of group type definitions"
1564     name: group_types
1565     required: no
1566     type: map
1567     mapping:
1568       =:
1569         *group_type_definition
1570
1571   policy_types:
1572     desc: "list of policy type definitions"
1573     name: policy_types
1574     required: no
1575     type: map
1576     mapping:
1577       =:
1578         *policy_type_definition
1579
1580   topology_template:
1581     desc: "topology template definition of the cloud application or service"
1582     required: no
1583     <<: *topology_template_definition