1 module config; 2 3 import boilerplate; 4 import dyaml; 5 import std.json; 6 import std.typecons; 7 import text.json.Decode; 8 import ToJson; 9 10 Config loadConfig(string path) 11 { 12 const root = Loader.fromFile(path).load; 13 const JSONValue jsonValue = root.toJson(No.ordered); 14 15 return decodeJson!(Config, decodeConfig)(jsonValue); 16 } 17 18 const(string)[] decodeConfig(T : const(string)[])(const JSONValue value) 19 { 20 if (value.type == JSONType..string) 21 { 22 return [value.str]; 23 } 24 return value.decodeJson!(string[]); 25 } 26 27 private alias _ = decodeConfig!(string[]); 28 29 struct Config 30 { 31 const(string)[] source; 32 33 // Where component types are turned into structs 34 string componentFolder; 35 36 // Where services are generated as interfaces 37 @(This.Default) 38 string serviceFolder; 39 40 @(This.Default) 41 SchemaConfig[string] schemas; 42 43 @(This.Default) 44 OperationConfig[string] operations; 45 46 mixin(GenerateAll); 47 } 48 49 struct SchemaConfig 50 { 51 @(This.Default!true) 52 bool include = true; 53 54 @(This.Default) 55 const(string)[] properties; 56 57 @(This.Default) 58 const(string)[] invariant_; 59 60 @(This.Default!true) 61 bool isEventType = true; 62 63 @(This.Default) 64 Nullable!string module_; 65 66 mixin(GenerateAll); 67 } 68 69 struct OperationConfig 70 { 71 @(This.Default!true) 72 bool include = true; 73 74 mixin(GenerateAll); 75 }