You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where schema is for example the following JSON schema
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The ID of the node"
},
"name": {
"type": "string",
"description": "The name of the node"
},
"status": {
"type": "object",
"description": "The status of the node",
"properties": {
"vm": {
"type": "string"
},
"app": {
"type": "string"
}
}
},
"url": {
"type": "string",
"format": "uri",
"description": "The URL of the node"
}
}
}
The expected result is a table with the following "qualified names":
id
name
status
status.vm
status.app
url
However the variable nodeName seems to scoped per declaration (i.e. there is only one instance) and not scoped per invocation. This means that changes to nodeName in recursive calls of typeTable can be seen by the caller. This results in the following "qualified names":
id
id.name
id.name.status
id.name.status.vm
id.name.status.vm.app
id.name.status.vm.app.url
The text was updated successfully, but these errors were encountered:
The workaround for this issue is to not use any variables in macros that are called recursively. Instead, declare all local variables as parameters with default values. I.e. instead of
{% macro typeTable(node, prefix = "", name = "" %}
{% set nodeName = prefix + ("." if prefix) + name) %}
...
write
{% macro typeTable(node, prefix = "", name = "", nodeName = prefix + ("." if prefix) + name) %}
...
Nevertheless, it would be nice if variables in macros worked as expected
Consider the following template that renders a list of fully qualified property names from a JSON schema:
Where
schema
is for example the following JSON schemaThe expected result is a table with the following "qualified names":
However the variable
nodeName
seems to scoped per declaration (i.e. there is only one instance) and not scoped per invocation. This means that changes tonodeName
in recursive calls oftypeTable
can be seen by the caller. This results in the following "qualified names":The text was updated successfully, but these errors were encountered: