Ejemplo n.º 1
0
        public void Output(TypeScriptWriter writer, ApiDesc api)
        {
            writer.WriteLine("// AUTOGENERATED FILE - any manual changes will be lost");
            writer.WriteLine();
            if (api.Imports.Count > 0)
            {
                foreach (var import in api.Imports.Order())
                {
                    writer.WriteLine(import);
                }
                writer.WriteLine();
            }
            writer.WriteLine("declare global {");
            writer.WriteLine();
            using (writer.Indent())
            {
                var namespaces = api.Interfaces.Values.Select(i => getNamespace(i.TsName)).Concat(api.Enums.Values.Select(e => getNamespace(e.TsName))).Distinct().Order();
                foreach (var ns in new string[] { null }.Concat(namespaces))
                {
                    var enums      = api.Enums.Values.Where(e => getNamespace(e.TsName) == ns).OrderBy(e => e.TsName).ToList();
                    var interfaces = api.Interfaces.Values.Where(i => getNamespace(i.TsName) == ns).OrderBy(e => e.TsName).ToList();
                    if (enums.Count == 0 && interfaces.Count == 0)
                    {
                        continue;
                    }
                    if (ns != null)
                    {
                        writer.WriteLine($"namespace {ns} {{");
                        writer.WriteLine();
                    }
                    using (writer.Indent(ns != null))
                    {
                        foreach (var e in enums)
                        {
                            OutputEnum(writer, e);
                            writer.WriteLine();
                        }
                        foreach (var i in interfaces)
                        {
                            OutputInterface(writer, i);
                            writer.WriteLine();
                        }
                    }
                    if (ns != null)
                    {
                        writer.WriteLine("}");
                        writer.WriteLine();
                    }
                }
            }
            writer.WriteLine("}");
            writer.WriteLine();

            writer.WriteLine("export class Services {");
            using (writer.Indent())
            {
                foreach (var svc in api.Services.OrderBy(s => s.Name))
                {
                    writer.WriteLine($"public readonly {svc.Name}: {svc.Name}Service;");
                }
                writer.WriteLine();
                writer.WriteLine("public constructor(hostname: string) {");
                using (writer.Indent())
                {
                    foreach (var svc in api.Services.OrderBy(s => s.Name))
                    {
                        writer.WriteLine($"this.{svc.Name} = new {svc.Name}Service(hostname);");
                    }
                }
                writer.WriteLine("}");
            }
            writer.WriteLine("}");
            writer.WriteLine();
            foreach (var svc in api.Services.OrderBy(s => s.Name))
            {
                OutputService(writer, svc);
                writer.WriteLine();
            }
        }
Ejemplo n.º 2
0
 public GenericControllerServiceBuilder(ApiDesc api) : base(api)
 {
 }
Ejemplo n.º 3
0
 public WebApiMvc5ServiceBuilder(ApiDesc api) : base(api)
 {
 }
Ejemplo n.º 4
0
 public ApiServiceBuilder(ApiDesc api)
 {
     Api = api;
 }