本文整理汇总了C#中SwaggerModeler类的典型用法代码示例。如果您正苦于以下问题:C# SwaggerModeler类的具体用法?C# SwaggerModeler怎么用?C# SwaggerModeler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwaggerModeler类属于命名空间,在下文中一共展示了SwaggerModeler类的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: 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);
}
示例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: 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);
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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"));
}
示例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]);
}
示例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);
}