tliron / puccini

Cloud topology management and deployment tools based on TOSCA
https://puccini.cloud
Apache License 2.0
88 stars 20 forks source link

Inconsistent `$map` representation #136

Closed Shishqa closed 1 year ago

Shishqa commented 1 year ago

Consider a small template:

tosca_definitions_version: tosca_simple_yaml_1_3
topology_template:
  inputs:
    test:
      type: map
      default: {}
      key_schema:
        type: string
      entry_schema:
        type: string

Let's parse it and dump to yaml:

> puccini-tosca parse test.yaml
description: ""
nodeTemplates: {}
groups: {}
policies: {}
inputs:
  test:
    $meta:
      type: map
      key:
        type: string
      value:
        type: string
    $map: []
outputs: {}
workflows: {}
substitution: null
metadata: {}
scriptletNamespace: {}

Here we have $map: []

Let's compile it and dump:

properties:
  tosca:
    description: ""
    inputs:
      test:
        $map: null
        $meta:
          key:
            type: string
          type: map
          value:
            type: string
    metadata: {}
    outputs: {}
vertexes: {}

Here we have $map: null

Let's parse and dump to json:

> puccini-tosca parse test.yaml -f json
{
  "description": "",
  "groups": {},
  "inputs": {
    "test": {
      "$map": null,
      "$meta": {
        "key": {
          "type": "string"
        },
        "type": "map",
        "value": {
          "type": "string"
        }
      }
    }
  },
  "metadata": {},
  "nodeTemplates": {},
  "outputs": {},
  "policies": {},
  "scriptletNamespace": {},
  "substitution": null,
  "workflows": {}
}

Here $map: null

Expected

I expect that $map is equal to an empty list [], as I have provided a default value {}.

tliron commented 1 year ago

So, parse is different from compile and is meant more for debugging. Is there a specific use case for you?

Shishqa commented 1 year ago

Sorry for the belated reply!

I expect [] in $map as I have provided a default value {}. It is confusing to see null in both cases: when the value is undefined and when I explicitly define it with an empty map. And parse (in yaml) provides a correct output for me, but compile doesn't.

Maybe I miss something regarding the design of the API, and null should be always considered an empty collection?

tliron commented 1 year ago

OK, I see now -- I would indeed consider this a bug in compile. There should be a consistent zero value according to the type.

tliron commented 1 year ago

I did some testing, I think the issue is that you are not coercing the values. If you run with -c you will get consistent results. (This is still a bug, I think specifically with inputs)

tliron commented 1 year ago

Fixed, but note that maps appear in Clout as lists of entries, not maps. But now you will get an empty list instead of null.