/// <summary> /// Parses API dependencies within a JSON tree. /// </summary> /// <param name="root">The root of the API JSON tree.</param> /// <param name="searchPaths">The set of directories to search when resolving relative file references.</param> /// <returns>A list of API models representing dependencies.</returns> static List <ApiModel> ParseDependencies(JObject root, IEnumerable <string> searchPaths) { var results = new List <ApiModel>(); var processed = new HashSet <string>(); JToken dependencies; if (root.TryGetValue("dependencies", out dependencies)) { foreach (var dependency in dependencies) { var file = (string)dependency; if (processed.Contains(file)) { continue; } foreach (var searchPath in searchPaths) { var path = Path.Combine(searchPath, file); if (File.Exists(path)) { var json = JObject.Parse(File.ReadAllText(path)); results.Add(ModelJson.Parse(json, searchPaths)); break; } } } } return(results); }
/// <summary> /// The application's entry point. /// </summary> /// <param name="arguments">The command line arguments.</param> static void Main(string[] arguments) { if (arguments.Length == 0) { throw new InvalidOperationException("Missing configuration file path."); } var configuration = new Configuration(arguments[0]); var searchPaths = new HashSet <string>(); var json = RunParser(configuration); foreach (var layer in configuration.Layers) { JObject current = null; current = JObject.Parse(File.ReadAllText(layer)); searchPaths.Add(Path.GetDirectoryName(Path.GetFullPath(layer))); // combine the current layer with the base if (json == null) { json = current; } else { CompositingEngine.Compose(json, current); } } var generatedModelFile = Path.Combine(configuration.GeneratorOutputPath, configuration.ApiName + ".json"); File.WriteAllText(generatedModelFile, json.ToString()); // run the generator on the composed Json model var api = ModelJson.Parse(json, searchPaths); RunGenerator(api, configuration); }