Exemplo n.º 1
0
        private void Run()
        {
            TypeMapper.Language = _targetLanguage;

            var jsonText = LoadStringFromUrl(_url);

            var parser = new Parser
            {
                EnumOverrides = _enums
                                .Split(ItemSeparators, StringSplitOptions.RemoveEmptyEntries)
                                .Select(s => EnumRegex.Match(s))
                                .Where(m => m.Success)
                                .ToDictionary(
                    m => $"{m.Groups["fieldName"].Value.Trim()}.{string.Join(",", m.Groups["valueList"].Value.Split(ListSeparators, StringSplitOptions.RemoveEmptyEntries))}",
                    m => new Enum(
                        new Property {
                    Name = m.Groups["enumName"].Value.Trim()
                },
                        new Property {
                    Name = m.Groups["enumName"].Value.Trim()
                },
                        m.Groups["valueList"].Value.Split(ListSeparators, StringSplitOptions.RemoveEmptyEntries)))
            };

            var api = parser.Parse(jsonText, _url);

            var generator = CreateCodeGenerator(api);

            _log.Info($"{api.Title} ({api.Version}) has {api.Paths.SelectMany(p => p.Operations).Count()} operations, {api.Definitions.Count} definitions and {api.Enums.Count} enumerations");

            var code     = generator.GenerateServiceModel();
            var filename = _filename[_targetLanguage];

            _log.Info($"Writing code to {filename} ...");

            File.WriteAllText(filename, code);
        }
Exemplo n.º 2
0
 public static bool IsRegex(string pStr, EnumRegex pEnum)
 {
     return(ArrCheckRegex[(int)pEnum].IsMatch(pStr));
 }