oasis-open / tosca-community-contributions

OASIS TC Open Repository: Manages TOSCA profiles, tests, and templates that are maintained by the TOSCA community. They are intended to be used as examples to help developers get started with TOSCA and to test compliance of TOSCA implementations with the standard.
https://github.com/oasis-open/tosca-community-contributions
Apache License 2.0
39 stars 25 forks source link

Are functions allowed in constraint clauses #129

Closed lauwers closed 1 year ago

lauwers commented 2 years ago

I believe we all agree that functions are allowed in filter definitions (which in v1.3 were defined using constraint clauses). But what about regular constraint clauses in property definitions? Are functions allowed in those definitions? For example, is the following valid?

tosca_definitions_version: tosca_simple_yaml_1_3

node_types:

  NodeType:
    properties:
      minimum_instances:
        type: integer
        constraints:
          - greater_or_equal: 0 # positive integer
      maximum_instances:
        type: integer
        constraints:
          - greater_or_equal: { get_property: [SELF, minimum_instances]}
      default_instances:
        type: integer
        constraints:
          - greater_or_equal: { get_property: [SELF, minimum_instances]}
          - less_or_equal: { get_property: [SELF, maximum_instances]}
        required: false
lauwers commented 2 years ago

I believe we all decided the use case above is valid. Here is what this would look like after converting to TOSCA Version 2:

tosca_definitions_version: tosca_2_0

node_types:

  NodeType:
    properties:
      minimum_instances:
        type: integer
        validation: { $greater_or_equal: [ $value,  0 ] }  # positive integer
      maximum_instances:
        type: integer
        validation: { $greater_or_equal: [ $value, { $get_property: [ SELF, minimum_instances ] } ] }
      default_instances:
        type: integer
        validation:
          $and:
            - { $greater_or_equal: [ $value, { $get_property: [ SELF, minimum_instances ] } ] }
            - { $less_or_equal: [ $value, { $get_property: [ SELF, maximum_instances ] } ] }
        required: false
lauwers commented 1 year ago

The example above is deemed valid and is shown in Section 5.4.6.3 of https://docs.oasis-open.org/tosca/TOSCA/v2.0/csd05/TOSCA-v2.0-csd05.html