how to refer generated object in another pkl file #1060
-
I have created below pkl file to dynamically generate schema configuration for each token.
When run the pkl command "pkl eval q11.pkl, the output contain all token detais as "JsonSchemaConfig" objects inside "jsonSchema" property of the module "template_schemas".
My requirement is to refer the generated token (token1, token2, ..) in another pkl file. Like below -
How can I refer the token generated in a pkl file into another pkl file? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The core issue is that you're attempting property access when you want to be subscripting. There are a couple more design/style things you may want to consider:
Here's how I might write this accounting for this (and following the style guide): module template_schemas
class JsonSchemaConfig {
type: String = "template"
templateId: String
config: Map
}
class StConfig { // Service Token Config
token: String
config: Mapping
}
jsonSchema: Mapping<String, JsonSchemaConfig> = new {
for (_tid, _stcl in tempIdConfigMap) {
for (_stc in _stcl) {
["\(_stc.token)"] {
templateId = _tid
config = _stc.config
}
}
}
}
tempIdConfigMap: Mapping<String, Listing<StConfig>> = new {
["schemaStr"] {
new { token = "token1"; config { ["param_1"] = "scc" } }
new { token = "token2"; config { ["param_1"] = "mcc" } }
}
["schemaArrays"] {
new { token = "token3"; config { ["param_1"] = "pl"; ["param_2"] = "pnp"; ["minItems"] = 1; ["maxItems"] = 10 } }
}
["schemaArray"] {
new { token = "token4"; config { ["param_1"] = "scc" } }
new { token = "token5"; config { ["param_1"] = "pl" } }
new { token = "token6"; config { ["param_1"] = "pn" } }
}
) Then in your other module: module another_module
import "template_schemas.pkl"
class TokenConfig {
token: String // token id
users: Listing<String>
jsonSchema: String // value from previous pkl file for the token
}
mainConfig: Mapping<String, TokenConfig> {
for (_tok in tokenList) {
["c1"] { // not sure this makes sense as it'll result in duplicate mapping entries
...
jsonSchema = template_schemas.jsonSchema[_tok]
}
}
}
tokenList: Listing<String> = new { "token1"; "token2" } |
Beta Was this translation helpful? Give feedback.
The core issue is that you're attempting property access when you want to be subscripting. There are a couple more design/style things you may want to consider:
;
-separatedHere's how I might write this accounting for this (and following the style guide):