Exemplo n.º 1
0
        public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host)
        {
            var clientGenerator = new SwaggerToTypeScriptGenerator(InputSwaggerService);

            clientGenerator.Class     = Class;
            clientGenerator.AsyncType = AsyncType;
            clientGenerator.OperationGenerationMode = OperationGenerationMode;

            var output = clientGenerator.GenerateFile();

            WriteOutput(host, output);
        }
Exemplo n.º 2
0
        public void When_generating_TypeScript_code_then_output_contains_expected_classes()
        {
            // Arrange
            var service = CreateService();

            //// Act
            var generator = new SwaggerToTypeScriptGenerator(service);

            generator.Class = "MyClass";
            var code = generator.GenerateFile();

            // Assert
            Assert.IsTrue(code.Contains("export class MyClass"));
            Assert.IsTrue(code.Contains("export interface Person"));
            Assert.IsTrue(code.Contains("export interface Address"));
        }
        public Task GenerateClientAsync(string swaggerData)
        {
            return(RunTaskAsync(async() =>
            {
                var code = string.Empty;
                await Task.Run(() =>
                {
                    if (!string.IsNullOrEmpty(swaggerData))
                    {
                        var service = SwaggerService.FromJson(swaggerData);

                        var codeGenerator = new SwaggerToTypeScriptGenerator(service);
                        codeGenerator.Class = ClassName;
                        codeGenerator.AsyncType = AsyncType;
                        codeGenerator.OperationGenerationMode = OperationGenerationMode;

                        code = codeGenerator.GenerateFile();
                    }
                });

                ClientCode = code;
            }));
        }
Exemplo n.º 4
0
        public async Task <string> RunAsync()
        {
            var clientGenerator = new SwaggerToTypeScriptGenerator(InputSwaggerService, Settings);

            return(clientGenerator.GenerateFile());
        }
Exemplo n.º 5
0
        public void When_parameter_is_array_then_TypeScript_is_correct()
        {
            //// Arrange
            var swagger = @"{
  ""swagger"" : ""2.0"",
  ""info"" : {
    ""version"" : ""1.0.2"",
    ""title"" : ""Test API""
  },
  ""host"" : ""localhost:8080"",
  ""basePath"" : ""/"",
  ""tags"" : [ {
    ""name"" : ""api""
  } ],
  ""schemes"" : [ ""http"" ],
  ""paths"" : {
     ""/removeElement"" : {
      ""delete"" : {
        ""tags"" : [ ""api"" ],
        ""summary"" : ""Removes elements"",
        ""description"" : ""Removes elements"",
        ""operationId"" : ""removeElement"",
        ""consumes"" : [ ""application/json"" ],
        ""produces"" : [ ""application/json"" ],
        ""parameters"" : [ {
          ""name"" : ""X-User"",
          ""in"" : ""header"",
          ""description"" : ""User identifier"",
          ""required"" : true,
          ""type"" : ""string""
        }, {
          ""name"" : ""elementId"",
          ""in"" : ""query"",
          ""description"" : ""The ids of existing elements that should be removed"",
          ""required"" : false,
          ""type"" : ""array"",
          ""items"" : {
            ""type"" : ""integer"",
            ""format"" : ""int64""
          },
        } ],
        ""responses"" : {
          ""default"" : {
            ""description"" : ""successful operation""
          }
        }
      }
    }
  },
    ""definitions"" : { }
}
";
            var service = SwaggerService.FromJson(swagger);

            //// Act
            var settings = new SwaggerToTypeScriptGeneratorSettings {
                ClassName = "MyClass"
            };
            var generator = new SwaggerToTypeScriptGenerator(service, settings);
            var code      = generator.GenerateFile();

            //// Assert
            Assert.IsTrue(code.Contains(@"elementId.forEach(item => { url += ""elementId="" + encodeURIComponent("""" + item) + ""&""; });"));
        }