Usage of variables files

Prerequisites

Modules

Checkout branches

git checkout origin/osp-web-configuration .
git checkout origin/osp-variables-configuration .

Example configuration

git checkout origin/template-variables-file .

Description

In this tutorial you will learn how to create a variables value with a default extracted from a variables.ospp.

Steps

1. Create a value and his owner

The default is directly extracted from the variables.ospp.

root/final/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/final/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ]
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

Which result in the following owner.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.final/owner.variables" as v :\
{\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

v -> t : Variables file
state "root.variables/variables.ospp" as t  : \
{\n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

v --> result : Result after the aggregation

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My content"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml

2. Redefine the default value inside the owner

The default is overridden by the locally define one.

root/redefine/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/redefine/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ],
    "templateVariables": {
        "default-value": "My new content"
    }
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

Which result in the following owner as the default-value define on the root.redefine/owner.ospp is overriding the one define on root.variables/variables.ospp.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.redefine/owner.variables" as v :\
{\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ],\n\
    "templateVariables" : {\n\
        "default-value" : <color:red>"My new content"</color>\n\
    }\n\
}

v -> t : Variables files
state "root.variables/variables.ospp" as t  : \
{\n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

v --> result : Result

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My new content"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml

3. Use variables from a sub variables file

The default is overridden by the locally define one and add a new variable.

root/sub-variables/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/sub-variables/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ],
    "templateVariables": {
        "default-value": "My new content is [${content}]"
    }
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

root/variables/sub/variables.ospp

{
    "variables": {
        "content": "A message"
    }
}

Which result in the following owner as the default-value define on the root.sub-variables/owner.ospp is overriding the one define on root.variables/variables.ospp and use content define on root.variables.sub/variables.ospp.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.redefine/owner.variables" as v :\
{ \n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ],\n\
    "templateVariables" : {\n\
        "default-value" : <color:red>"My new content is [<color:blue>${content}</color><color:red>]"</color>\n\
    }\n\
}

v -> t : Variables file
state "root.variables/variables.ospp" as t  : \
{ \n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

t -> t2 : Variables file
state "root.variables.sub/variables.ospp" as t2  : \
{\n\
    "variables": { \n\
        "content": <color:blue>"A message"</color>\n\
    }\n\
}

v --> result : Result

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My new content is [<color:blue>A message</color><color:red>]"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml