• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SwaggerModeler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SwaggerModeler的典型用法代码示例。如果您正苦于以下问题:C# SwaggerModeler类的具体用法?C# SwaggerModeler怎么用?C# SwaggerModeler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SwaggerModeler类属于命名空间,在下文中一共展示了SwaggerModeler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ClientModelWithCircularDependencyThrowsError

 public void ClientModelWithCircularDependencyThrowsError()
 {
     var modeler = new SwaggerModeler(new Settings
     {
         Namespace = "Test",
         Input = Path.Combine("Swagger", "swagger-allOf-circular.json")
     });
     Assert.Throws<ArgumentException>(() => modeler.Build());
 }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:9,代码来源:SwaggerModelerTests.cs


示例2: TestClientModelFromSimpleSwagger

        public void TestClientModelFromSimpleSwagger()
        {
            Generator.Modeler modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-simple-spec.json")
            });
            var clientModel = modeler.Build();

            var description = "The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.";
            var summary = "Product Types";

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.Properties.Count);
            Assert.True(clientModel.Properties.Any(p => p.Name.Equals("subscriptionId", StringComparison.OrdinalIgnoreCase)));
            Assert.True(clientModel.Properties.Any(p => p.Name.Equals("apiVersion", StringComparison.OrdinalIgnoreCase)));
            Assert.Equal("2014-04-01-preview", clientModel.ApiVersion);
            Assert.Equal("https://management.azure.com/", clientModel.BaseUrl);
            Assert.Equal("Some cool documentation.", clientModel.Documentation);
            Assert.Equal(0, clientModel.Methods.Count(m => m.Group != null));
            Assert.Equal(2, clientModel.Methods.Count);
            Assert.Equal("list", clientModel.Methods[0].Name);
            Assert.NotEmpty(clientModel.Methods[0].Description);
            Assert.Equal(description, clientModel.Methods[0].Description);
            Assert.NotEmpty(clientModel.Methods[0].Summary);
            Assert.Equal(summary, clientModel.Methods[0].Summary);
            Assert.Equal(HttpMethod.Get, clientModel.Methods[0].HttpMethod);
            Assert.Equal(3, clientModel.Methods[0].Parameters.Count);
            Assert.Equal("subscriptionId", clientModel.Methods[0].Parameters[0].Name);
            Assert.NotNull(clientModel.Methods[0].Parameters[0].ClientProperty);
            Assert.Equal("resourceGroupName", clientModel.Methods[0].Parameters[1].Name);
            Assert.Equal("resourceGroupName", clientModel.Methods[0].Parameters[1].SerializedName);
            Assert.Equal("Resource Group ID.", clientModel.Methods[0].Parameters[1].Documentation);
            Assert.Equal(true, clientModel.Methods[0].Parameters[0].IsRequired);
            Assert.Equal(ParameterLocation.Path, clientModel.Methods[0].Parameters[0].Location);
            Assert.Equal("String", clientModel.Methods[0].Parameters[0].Type.ToString());
            Assert.Equal("reset", clientModel.Methods[1].Name);
            Assert.Equal("Product", clientModel.ModelTypes.First(m=>m.Name == "Product").Name);
            Assert.Equal("Product", clientModel.ModelTypes.First(m => m.Name == "Product").SerializedName);
            Assert.Equal("The product title.", clientModel.ModelTypes.First(m => m.Name == "Product").Summary);
            Assert.Equal("The product documentation.", clientModel.ModelTypes.First(m => m.Name == "Product").Documentation);
            Assert.Equal("A product id.", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[0].Summary);
            Assert.Equal("product_id", clientModel.ModelTypes.First(m=>m.Name == "Product").Properties[0].Name);
            Assert.Equal("product_id", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[0].SerializedName);
            Assert.Null(clientModel.Methods[1].ReturnType.Body);
            Assert.Null(clientModel.Methods[1].Responses[HttpStatusCode.NoContent].Body);
            Assert.Equal(3, clientModel.Methods[1].Parameters.Count);
            Assert.Equal("subscriptionId", clientModel.Methods[1].Parameters[0].Name);
            Assert.Null(clientModel.Methods[1].Parameters[0].ClientProperty);
            Assert.Equal("resourceGroupName", clientModel.Methods[1].Parameters[1].Name);
            Assert.Equal("apiVersion", clientModel.Methods[1].Parameters[2].Name);

            Assert.Equal("capacity", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].Name);
            Assert.Equal("100", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].DefaultValue);
        }
开发者ID:xingwu1,项目名称:autorest,代码行数:55,代码来源:SwaggerModelerTests.cs


示例3: ClientModelWithCircularDependencyThrowsError

 public void ClientModelWithCircularDependencyThrowsError()
 {
     var modeler = new SwaggerModeler(new Settings
     {
         Namespace = "Test",
         Input = Path.Combine("Swagger", "swagger-allOf-circular.json")
     });
     var ex = Assert.Throws<InvalidOperationException>(() => modeler.Build());
     Assert.Contains("circular", ex.Message, StringComparison.OrdinalIgnoreCase);
     Assert.Contains("siamese", ex.Message, StringComparison.OrdinalIgnoreCase);
 }
开发者ID:jhancock93,项目名称:autorest,代码行数:11,代码来源:SwaggerModelerTests.cs


示例4: GetBuilder

 public ObjectBuilder GetBuilder(SwaggerModeler swaggerSpecBuilder)
 {
     if (this is SwaggerParameter)
     {
         return new ParameterBuilder(this as SwaggerParameter, swaggerSpecBuilder);
     }
     if (this is Schema)
     {
         return new SchemaBuilder(this as Schema, swaggerSpecBuilder);
     }
     return new ObjectBuilder(this, swaggerSpecBuilder);
 }
开发者ID:Ranjana1996,项目名称:autorest,代码行数:12,代码来源:SwaggerObject.cs


示例5: GlobalResponsesReference

        public void GlobalResponsesReference()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-global-responses.json")
            });
            var clientModel = modeler.Build();

            Assert.Equal(1, clientModel.Methods[0].Responses.Count);
            Assert.NotNull(clientModel.Methods[0].Responses[HttpStatusCode.OK]);
        }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:12,代码来源:SwaggerModelerTests.cs


示例6: TestExternalReferences

        public void TestExternalReferences()
        {
            Generator.Modeler modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-external-ref-no-definitions.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.ModelTypes.Count);
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:12,代码来源:SwaggerModelerTests.cs


示例7: DefaultReturnsCorrectType

        public void DefaultReturnsCorrectType()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-multiple-response-schemas.json")
            });
            var clientModel = modeler.Build();

            var retType = clientModel.Methods.First(m => m.Name == "patchDefaultResponse");

            Assert.Equal("pet", retType.ReturnType.ToString());
        }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:13,代码来源:SwaggerModelerTests.cs


示例8: TestExternalReferencesWithAllOf

        public void TestExternalReferencesWithAllOf()
        {
            Generator.Modeler modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = @"Swagger\swagger-external-ref.json"
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(3, clientModel.ModelTypes.Count);
            Assert.Equal("ChildProduct", clientModel.ModelTypes[0].Name);
            Assert.Equal("Product", clientModel.ModelTypes[0].BaseModelType.Name);
        }
开发者ID:juvchan,项目名称:autorest,代码行数:14,代码来源:SwaggerModelerTests.cs


示例9: AllowVendorExtensionInPath

        public void AllowVendorExtensionInPath()
        {
            SwaggerModeler modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "vendor-extension-in-path.json")
            });
            var clientModel = modeler.Build();

            // should return a valid model.
            Assert.NotNull(clientModel);

            // there should be one method in this generated api.
            Assert.Equal(1, modeler.ServiceClient.Methods.Count);
        }
开发者ID:jhancock93,项目名称:autorest,代码行数:15,代码来源:VendorExtensionInPath.cs


示例10: ValidateSwagger

        private IEnumerable<ValidationMessage> ValidateSwagger(string input)
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = input
            });
            IEnumerable<ValidationMessage> messages;
            modeler.Build(out messages);

            // remove debug-level messages
            messages = messages.Where(each => each.Severity > LogEntrySeverity.Debug);

            return messages;
        }
开发者ID:haocs,项目名称:autorest,代码行数:15,代码来源:SwaggerModelerValidationTests.cs


示例11: TestClientModelFromSimpleSwagger

        public void TestClientModelFromSimpleSwagger()
        {
            Generator.Modeler modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-simple-spec.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.Properties.Count);
            Assert.True(clientModel.Properties.Any(p => p.Name.Equals("subscriptionId", StringComparison.OrdinalIgnoreCase)));
            Assert.True(clientModel.Properties.Any(p => p.Name.Equals("apiVersion", StringComparison.OrdinalIgnoreCase)));
            Assert.Equal("2014-04-01-preview", clientModel.ApiVersion);
            Assert.Equal("https://management.azure.com/", clientModel.BaseUrl);
            Assert.Equal("Some cool documentation.", clientModel.Documentation);
            Assert.Equal(0, clientModel.Methods.Count(m => m.Group != null));
            Assert.Equal(2, clientModel.Methods.Count);
            Assert.Equal("list", clientModel.Methods[0].Name);
            Assert.NotEmpty(clientModel.Methods[0].Documentation);
            Assert.Equal(HttpMethod.Get, clientModel.Methods[0].HttpMethod);
            Assert.Equal(3, clientModel.Methods[0].Parameters.Count);
            Assert.Equal("subscriptionId", clientModel.Methods[0].Parameters[0].Name);
            Assert.NotNull(clientModel.Methods[0].Parameters[0].ClientProperty);
            Assert.Equal("resourceGroupName", clientModel.Methods[0].Parameters[1].Name);
            Assert.Equal("resourceGroupName", clientModel.Methods[0].Parameters[1].SerializedName);
            Assert.Equal("Resource Group ID.", clientModel.Methods[0].Parameters[1].Documentation);
            Assert.Equal(true, clientModel.Methods[0].Parameters[0].IsRequired);
            Assert.Equal(ParameterLocation.Path, clientModel.Methods[0].Parameters[0].Location);
            Assert.Equal("String", clientModel.Methods[0].Parameters[0].Type.ToString());
            Assert.Equal("reset", clientModel.Methods[1].Name);
            Assert.Equal("Product", clientModel.ModelTypes[0].Name);
            Assert.Equal("Product", clientModel.ModelTypes[0].SerializedName);
            Assert.Equal("The product documentation.", clientModel.ModelTypes[0].Documentation);
            Assert.Equal("product_id", clientModel.ModelTypes[0].Properties[0].Name);
            Assert.Equal("product_id", clientModel.ModelTypes[0].Properties[0].SerializedName);
            Assert.Null(clientModel.Methods[1].ReturnType);
            Assert.Null(clientModel.Methods[1].Responses[HttpStatusCode.NoContent]);
            Assert.Equal(3, clientModel.Methods[1].Parameters.Count);
            Assert.Equal("subscriptionId", clientModel.Methods[1].Parameters[0].Name);
            Assert.Null(clientModel.Methods[1].Parameters[0].ClientProperty);
            Assert.Equal("resourceGroupName", clientModel.Methods[1].Parameters[1].Name);
            Assert.Equal("apiVersion", clientModel.Methods[1].Parameters[2].Name);
        }
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:44,代码来源:SwaggerModelerTests.cs


示例12: CompareSwagger

        /// <summary>
        /// Helper method -- load two Swagger documents and invoke the comparison logic.
        /// </summary>
        /// <param name="input">The name of the swagger document file. The file name must be the same in both the 'modified' and 'original' folder.</param>
        /// <returns>A list of messages from the comparison logic.</returns>
        private IEnumerable<ComparisonMessage> CompareSwagger(string input)
        {
            using (NewContext)
            {
                var settings = new Settings
                {
                    Namespace = "Test",
                    Input = Path.Combine("Swagger", "Comparison", "Modified", input),
                    Previous = Path.Combine("Swagger", "Comparison", "Original", input)
                };

                var modeler = new SwaggerModeler();
                IEnumerable<ComparisonMessage> messages = modeler.Compare();

                // remove debug-level messages
                messages = messages.Where(each => each.Severity > LogEntrySeverity.Debug);

                return messages;
            }
        }
开发者ID:devigned,项目名称:autorest,代码行数:25,代码来源:SwaggerModelerCompareTests.cs


示例13: TestClientModelWithResponseHeaders

        public void TestClientModelWithResponseHeaders()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-response-headers.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.Methods.Count);
            Assert.Equal(2, clientModel.Methods[0].Responses.Count);
            Assert.Equal("list-Headers", clientModel.Methods[0].Responses[HttpStatusCode.OK].Headers.Name);
            Assert.Equal(3, ((CompositeType)clientModel.Methods[0].Responses[HttpStatusCode.OK].Headers).Properties.Count);
            Assert.Equal("list-Headers", clientModel.Methods[0].Responses[HttpStatusCode.Created].Headers.Name);
            Assert.Equal(3, ((CompositeType)clientModel.Methods[0].Responses[HttpStatusCode.Created].Headers).Properties.Count);
            Assert.Equal("list-Headers", clientModel.Methods[0].ReturnType.Headers.Name);
            Assert.Equal(3, ((CompositeType)clientModel.Methods[0].ReturnType.Headers).Properties.Count);

            Assert.Equal(1, clientModel.Methods[1].Responses.Count);
            Assert.Equal("create-Headers", clientModel.Methods[1].Responses[HttpStatusCode.OK].Headers.Name);
            Assert.Equal(3, ((CompositeType)clientModel.Methods[1].Responses[HttpStatusCode.OK].Headers).Properties.Count);
            Assert.Equal("create-Headers", clientModel.Methods[1].ReturnType.Headers.Name);
            Assert.Equal(3, ((CompositeType)clientModel.Methods[1].ReturnType.Headers).Properties.Count);
            Assert.True(clientModel.HeaderTypes.Any(c => c.Name == "list-Headers"));
            Assert.True(clientModel.HeaderTypes.Any(c => c.Name == "create-Headers"));
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:27,代码来源:SwaggerModelerTests.cs


示例14: TestClientWithValidation

        public void TestClientWithValidation()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = @"Swagger\swagger-validation.json"
            });
            var clientModel = modeler.Build();

            Assert.Equal("resourceGroupName", clientModel.Methods[0].Parameters[1].Name);
            Assert.Equal(true, clientModel.Methods[0].Parameters[1].IsRequired);
            Assert.Equal(3, clientModel.Methods[0].Parameters[1].Constraints.Count);
            Assert.Equal("10", clientModel.Methods[0].Parameters[1].Constraints[Constraint.MaxLength]);
            Assert.Equal("3", clientModel.Methods[0].Parameters[1].Constraints[Constraint.MinLength]);
            Assert.Equal("[a-zA-Z0-9]+", clientModel.Methods[0].Parameters[1].Constraints[Constraint.Pattern]);

            Assert.Equal("id", clientModel.Methods[0].Parameters[2].Name);
            Assert.Equal(3, clientModel.Methods[0].Parameters[2].Constraints.Count);
            Assert.Equal("10", clientModel.Methods[0].Parameters[2].Constraints[Constraint.MultipleOf]);
            Assert.Equal("100", clientModel.Methods[0].Parameters[2].Constraints[Constraint.InclusiveMinimum]);
            Assert.Equal("1000", clientModel.Methods[0].Parameters[2].Constraints[Constraint.InclusiveMaximum]);

            Assert.Equal("apiVersion", clientModel.Methods[0].Parameters[3].Name);
            Assert.NotNull(clientModel.Methods[0].Parameters[3].ClientProperty);
            Assert.Equal(1, clientModel.Methods[0].Parameters[3].Constraints.Count);
            Assert.Equal("\\d{2}-\\d{2}-\\d{4}", clientModel.Methods[0].Parameters[3].Constraints[Constraint.Pattern]);

            Assert.Equal("Product", clientModel.ModelTypes.First(m => m.Name == "Product").Name);
            Assert.Equal("display_names", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[2].Name);
            Assert.Equal(3, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[2].Constraints.Count);
            Assert.Equal("6", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[2].Constraints[Constraint.MaxItems]);
            Assert.Equal("0", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[2].Constraints[Constraint.MinItems]);
            Assert.Equal("true", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[2].Constraints[Constraint.UniqueItems]);

            Assert.Equal("capacity", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].Name);
            Assert.Equal(2, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].Constraints.Count);
            Assert.Equal("100", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].Constraints[Constraint.ExclusiveMaximum]);
            Assert.Equal("0", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[3].Constraints[Constraint.ExclusiveMinimum]);
	    }
开发者ID:CamSoper,项目名称:autorest,代码行数:39,代码来源:SwaggerModelerTests.cs


示例15: TestConstants

        public void TestConstants()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = @"Swagger\swagger-validation.json"
            });
            var clientModel = modeler.Build();

            Assert.Equal("myintconst", clientModel.Methods[0].Parameters[4].Name);
            Assert.Equal(PrimaryType.Int, clientModel.Methods[0].Parameters[4].Type);
            Assert.Equal(true, clientModel.Methods[0].Parameters[4].IsConstant);
            Assert.Equal("0", clientModel.Methods[0].Parameters[4].DefaultValue);

            Assert.Equal("mystrconst", clientModel.Methods[0].Parameters[5].Name);
            Assert.Equal(PrimaryType.String, clientModel.Methods[0].Parameters[5].Type);
            Assert.Equal(true, clientModel.Methods[0].Parameters[5].IsConstant);
            Assert.Equal("constant", clientModel.Methods[0].Parameters[5].DefaultValue);

            Assert.Equal("myintconst", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[5].Name);
            Assert.Equal(PrimaryType.Int, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[5].Type);
            Assert.Equal(true, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[5].IsConstant);
            Assert.Equal("0", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[5].DefaultValue);

            Assert.Equal("mystrconst", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[6].Name);
            Assert.Equal(PrimaryType.String, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[6].Type);
            Assert.Equal(true, clientModel.ModelTypes.First(m => m.Name == "Product").Properties[6].IsConstant);
            Assert.Equal("constant", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[6].DefaultValue);
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:29,代码来源:SwaggerModelerTests.cs


示例16: TestClientModelWithMethodGroups

        public void TestClientModelWithMethodGroups()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = @"Swagger\swagger-optional-params.json"
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(0, clientModel.Methods.Count(m => m.Group == null));
            Assert.Equal(2, clientModel.Methods.Count(m => m.Group == "Widgets"));
            Assert.Equal("List", clientModel.Methods[0].Name);
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:14,代码来源:SwaggerModelerTests.cs


示例17: TestDataTypes

        public void TestDataTypes()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-data-types.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal("Int integer", clientModel.Methods[0].Parameters[0].ToString());
            Assert.Equal("Int int", clientModel.Methods[0].Parameters[1].ToString());
            Assert.Equal("Long long", clientModel.Methods[0].Parameters[2].ToString());
            Assert.Equal("Double number", clientModel.Methods[0].Parameters[3].ToString());
            Assert.Equal("Double float", clientModel.Methods[0].Parameters[4].ToString());
            Assert.Equal("Double double", clientModel.Methods[0].Parameters[5].ToString());
            Assert.Equal("Decimal decimal", clientModel.Methods[0].Parameters[6].ToString());
            Assert.Equal("String string", clientModel.Methods[0].Parameters[7].ToString());
            Assert.Equal("enum color", clientModel.Methods[0].Parameters[8].ToString());
            Assert.Equal("ByteArray byte", clientModel.Methods[0].Parameters[9].ToString());
            Assert.Equal("Boolean boolean", clientModel.Methods[0].Parameters[10].ToString());
            Assert.Equal("Date date", clientModel.Methods[0].Parameters[11].ToString());
            Assert.Equal("DateTime dateTime", clientModel.Methods[0].Parameters[12].ToString());
            Assert.Equal("IList<String> array", clientModel.Methods[0].Parameters[13].ToString());

            var variableEnumInPath =
                clientModel.Methods.First(m => m.Name == "list" && m.Group == null).Parameters.First(p => p.Name == "color" && p.Location == ParameterLocation.Path).Type as EnumType;
            Assert.NotNull(variableEnumInPath);
            Assert.Equal(variableEnumInPath.Values,
                new[] { new EnumValue { Name = "red" }, new EnumValue { Name = "blue" }, new EnumValue { Name = "green" } }.ToList());
            Assert.True(variableEnumInPath.ModelAsString);
            Assert.Empty(variableEnumInPath.Name);

            var variableEnumInQuery =
                clientModel.Methods.First(m => m.Name == "list" && m.Group == null).Parameters.First(p => p.Name == "color" && p.Location == ParameterLocation.Query).Type as EnumType;
            Assert.NotNull(variableEnumInQuery);
            Assert.Equal(variableEnumInQuery.Values,
                new[] { new EnumValue { Name = "red" }, new EnumValue { Name = "blue" }, new EnumValue { Name = "green" }, new EnumValue { Name = "purple" } }.ToList());
            Assert.True(variableEnumInQuery.ModelAsString);
            Assert.Empty(variableEnumInQuery.Name);

            var differentEnum =
                clientModel.Methods.First(m => m.Name == "list" && m.Group == "DiffEnums").Parameters.First(p => p.Name == "color" && p.Location == ParameterLocation.Query).Type as EnumType;
            Assert.NotNull(differentEnum);
            Assert.Equal(differentEnum.Values,
                new[] { new EnumValue { Name = "cyan" }, new EnumValue { Name = "yellow" } }.ToList());
            Assert.True(differentEnum.ModelAsString);
            Assert.Empty(differentEnum.Name);

            var sameEnum =
                clientModel.Methods.First(m => m.Name == "get" && m.Group == "SameEnums").Parameters.First(p => p.Name == "color2" && p.Location == ParameterLocation.Query).Type as EnumType;
            Assert.NotNull(sameEnum);
            Assert.Equal(sameEnum.Values,
                new[] { new EnumValue { Name = "blue" }, new EnumValue { Name = "green" }, new EnumValue { Name = "red" } }.ToList());
            Assert.True(sameEnum.ModelAsString);
            Assert.Empty(sameEnum.Name);

            var modelEnum =
                clientModel.ModelTypes.First(m => m.Name == "Product").Properties.First(p => p.Name == "color2").Type as EnumType;
            Assert.NotNull(modelEnum);
            Assert.Equal(modelEnum.Values,
                new[] { new EnumValue { Name = "red" }, new EnumValue { Name = "blue" }, new EnumValue { Name = "green" } }.ToList());
            Assert.True(modelEnum.ModelAsString);
            Assert.Empty(modelEnum.Name);

            var fixedEnum =
                clientModel.ModelTypes.First(m => m.Name == "Product").Properties.First(p => p.Name == "color").Type as EnumType;
            Assert.NotNull(fixedEnum);
            Assert.Equal(fixedEnum.Values,
                new[] { new EnumValue { Name = "red" }, new EnumValue { Name = "blue" }, new EnumValue { Name = "green" } }.ToList());
            Assert.False(fixedEnum.ModelAsString);
            Assert.Equal("Colors", fixedEnum.Name);

            var fixedEnum2 =
                clientModel.ModelTypes.First(m => m.Name == "Product").Properties.First(p => p.Name == "color3").Type as EnumType;
            Assert.Equal(fixedEnum2, fixedEnum);

            Assert.Equal(1, clientModel.EnumTypes.Count);
            Assert.Equal("Colors", clientModel.EnumTypes.First().Name);
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:80,代码来源:SwaggerModelerTests.cs


示例18: TestClientModelWithDifferentReturnsTypesBasedOnStatusCode

        public void TestClientModelWithDifferentReturnsTypesBasedOnStatusCode()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-multiple-response-schemas.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal("getSameResponse", clientModel.Methods[0].Name);
            Assert.Equal("IList<pet>", clientModel.Methods[0].ReturnType.ToString());
            Assert.Equal("IList<pet>", clientModel.Methods[0].Responses[HttpStatusCode.OK].ToString());
            Assert.Equal("IList<pet>", clientModel.Methods[0].Responses[HttpStatusCode.Accepted].ToString());

            Assert.Equal("postInheretedTypes", clientModel.Methods[1].Name);
            Assert.Equal("pet", clientModel.Methods[1].ReturnType.ToString());
            Assert.Equal("dog", clientModel.Methods[1].Responses[HttpStatusCode.OK].ToString());
            Assert.Equal("cat", clientModel.Methods[1].Responses[HttpStatusCode.Accepted].ToString());

            Assert.Equal("patchDifferentStreamTypesNoContent", clientModel.Methods[6].Name);
            Assert.Equal("VirtualMachineGetRemoteDesktopFileResponse", clientModel.Methods[6].ReturnType.ToString());
            Assert.Equal("VirtualMachineGetRemoteDesktopFileResponse",
                clientModel.Methods[6].Responses[HttpStatusCode.OK].ToString());
            Assert.Null(clientModel.Methods[6].Responses[HttpStatusCode.NoContent].Body);
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:26,代码来源:SwaggerModelerTests.cs


示例19: TestClientModelWithStreamAndByteArray

        public void TestClientModelWithStreamAndByteArray()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-streaming.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal("GetWithStreamFormData", clientModel.Methods[0].Name);
            Assert.Equal("Stream", clientModel.Methods[0].Parameters[0].Type.Name);
            Assert.Equal("Stream", clientModel.Methods[0].ReturnType.ToString());
            Assert.Equal("Stream", clientModel.Methods[0].Responses[HttpStatusCode.OK].ToString());

            Assert.Equal("PostWithByteArrayFormData", clientModel.Methods[1].Name);
            Assert.Equal("ByteArray", clientModel.Methods[1].Parameters[0].Type.Name);
            Assert.Equal("ByteArray", clientModel.Methods[1].ReturnType.ToString());
            Assert.Equal("ByteArray", clientModel.Methods[1].Responses[HttpStatusCode.OK].ToString());

            Assert.Equal("GetWithStream", clientModel.Methods[2].Name);
            Assert.Equal("Stream", clientModel.Methods[2].ReturnType.ToString());
            Assert.Equal("Stream", clientModel.Methods[2].Responses[HttpStatusCode.OK].ToString());

            Assert.Equal("PostWithByteArray", clientModel.Methods[3].Name);
            Assert.Equal("ByteArray", clientModel.Methods[3].ReturnType.ToString());
            Assert.Equal("ByteArray", clientModel.Methods[3].Responses[HttpStatusCode.OK].ToString());
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:28,代码来源:SwaggerModelerTests.cs


示例20: TestCustomPaths

        public void TestCustomPaths()
        {
            var modeler = new SwaggerModeler(new Settings
            {
                Namespace = "Test",
                Input = Path.Combine("Swagger", "swagger-x-ms-paths.json")
            });
            var clientModel = modeler.Build();

            Assert.NotNull(clientModel);
            Assert.Equal(3, clientModel.Methods.Count);
            Assert.True(clientModel.Methods.All(m => m.Url == "/values/foo"));

        }
开发者ID:CamSoper,项目名称:autorest,代码行数:14,代码来源:SwaggerModelerTests.cs



注:本文中的SwaggerModeler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SwapChain类代码示例发布时间:2022-05-24
下一篇:
C# SvnRevision类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap