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

Bug: functions in map keys cannot be repeated if they have the same arguments #134

Closed tliron closed 1 year ago

tliron commented 2 years ago

The following is a valid use case, but currently cannot be expressed in TOSCA:

node_types:

  MyNode:
    properties:
      hints:
        type: map
        entry_schema: integer

service_template:

  node_templates:

    my-node:
      type: MyNode
      properties:
        hints:
          hint1: 12
          { $keygen: [ UUID ] }: 34 # invalid
          { $keygen: [ UUID ] }: 56 # invalid
          { $keygen: [ UUID ] }: 78 # invalid

The problem is that the last 3 lines are a YAML syntax error because we have a YAML map in which 3 keys are identical.

To be clear, this not a TOSCA issue, but strictly a YAML one. A TOSCA processor would know to call each of these three functions separately. (It would have to then map sure that their values are unique in that map, but that is a separate concern.) But YAML does not allow us to express this.

I propose the following workaround: allow for a special character in function names after which TOSCA will ignore all characters. This allows users to create unique names in YAML for this use case while allowing them to be considered the same name in TOSCA. We might as well re-use the "$" character for this purpose. Example:

    my-node:
      type: MyNode
      properties:
        hints:
          hint1: 12
          { $keygen: [ UUID ] }: 34
          { $keygen$1: [ UUID ] }: 56
          { $keygen$2: [ UUID ] }: 78

There is no YAML syntax error here. The TOSCA processor will ignore the the $1 and $2 suffixes, ensuring that all three of these keys are calling the same function.

We should also for this "middle $" to be escapable. Example:

$convert$$to€

The actual name of the function above would be convert$to€.

lauwers commented 1 year ago

This proposal has been accepted. It is documented in Section 5.14.4 of https://docs.oasis-open.org/tosca/TOSCA/v2.0/csd05/TOSCA-v2.0-csd05.html