本文整理汇总了C#中SwaggerModeler.Build方法的典型用法代码示例。如果您正苦于以下问题:C# SwaggerModeler.Build方法的具体用法?C# SwaggerModeler.Build怎么用?C# SwaggerModeler.Build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SwaggerModeler
的用法示例。
在下文中一共展示了SwaggerModeler.Build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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);
}
示例4: 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);
}
示例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]);
}
示例6: 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());
}
示例7: 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);
}
示例8: 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);
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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());
}
示例14: 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);
}
示例15: TestClientModelWithNoContent
public void TestClientModelWithNoContent()
{
var modeler = new SwaggerModeler(new Settings
{
Namespace = "Test",
Input = @"Swagger\swagger-no-content.json"
});
var clientModel = modeler.Build();
Assert.Equal("DeleteBlob", clientModel.Methods[4].Name);
Assert.Equal(PrimaryType.Object, clientModel.Methods[4].ReturnType.Body);
Assert.Equal(PrimaryType.Object, clientModel.Methods[4].Responses[HttpStatusCode.OK].Body);
Assert.Null(clientModel.Methods[4].Responses[HttpStatusCode.BadRequest].Body);
}