public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var client = new TsFile(Settings.ClientFileName);


            foreach (var(_, type) in types)
            {
                client.Write(type.Code);
                client.Write("");
            }

            client.Write("");

            var mainFileTemplate = Context.GetTemplateFactory()
                                   .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), new List <string>());

            client.Write(mainFileTemplate.TransformText());

            client.Write("");

            var exports = types.Select(x => x.Key).StrJoin(", ");

            client.Write("export { " + exports + " };");

            return(new List <string>
            {
                client.ToSystemFile()
            });
        }
Exemple #2
0
        public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var typeFile = new TsFile(Settings.TypesFileName);

            var relatedSchemas = types.Select(x => x.Value.RelatedSchemas)
                                 .SelectMany(x => x)
                                 .Distinct();

            var imports = GetImportsString(typeFile, relatedSchemas).ToList();

            if (imports.Any())
            {
                typeFile.Write(imports);
                typeFile.Write("");
            }

            foreach (var(_, type) in types)
            {
                typeFile.Write(type.Code);
                typeFile.Write("");
            }

            var exports = types.Select(x => x.Key).StrJoin(", ");

            typeFile.Write("export { " + exports + " };");

            var mainFile = new TsFile(Settings.ClientFileName);

            relatedSchemas = functions.Select(x => x.Value.RelatedSchemas)
                             .SelectMany(x => x)
                             .Distinct();

            imports = GetImportsString(mainFile, relatedSchemas).ToList();

            var template = Context.GetTemplateFactory()
                           .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), imports);

            mainFile.Write(template.TransformText());

            if (FileFilter != null)
            {
                FileFilter.Invoke(typeFile);
                FileFilter.Invoke(mainFile);
            }

            return(new List <string>
            {
                typeFile.ToSystemFile(),
                mainFile.ToSystemFile()
            });
        }
        public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var createdFile = new List <string>();

            foreach (var(name, type) in types)
            {
                var file = new TsFile(name);

                var imports = type
                              .RelatedSchemas
                              .Distinct()
                              .Select(x => GetImportsFormRelatedTypes(new List <ISchema> {
                    x
                }))
                              .SelectMany(x => x)
                              .Select(x =>
                                      "import { " + x + $" }} from \"./{x}\";")
                              .ToList();

                if (imports.Any())
                {
                    file.Write(imports);
                    file.Write("");
                }

                file.Write(type.Code);

                file.Write("");

                file.Write("export { " + name + " };");

                createdFile.Add(file.ToSystemFile());
            }

            var clientFile    = new TsFile(Settings.ClientFileName);
            var clientImports = functions.Select(x => x.Value.RelatedSchemas)
                                .SelectMany(x => x)
                                .Distinct().Select(x => "import { " + x.GetName() + " } from \"./" + x.GetName() + "\";");


            var template = Context.GetTemplateFactory()
                           .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), clientImports);

            clientFile.Write(template.TransformText());

            createdFile.Add(clientFile.ToSystemFile());

            return(createdFile);
        }