/// <summary> /// Initialize the entity container to Swagger model. /// </summary> protected virtual void InitializeContainer() { Contract.Assert(SwaggerDoc != null); Contract.Assert(EdmModel != null); SwaggerPaths = new JObject(); SwaggerDoc.Add("paths", SwaggerPaths); if (EdmModel.EntityContainer == null) { return; } foreach (var entitySet in EdmModel.EntityContainer.EntitySets()) { SwaggerPaths.Add("/" + entitySet.Name, ODataSwaggerUtilities.CreateSwaggerPathForEntitySet(entitySet)); SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForEntity(entitySet), ODataSwaggerUtilities.CreateSwaggerPathForEntity(entitySet)); } foreach (var operationImport in EdmModel.EntityContainer.OperationImports()) { SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForOperationImport(operationImport), ODataSwaggerUtilities.CreateSwaggerPathForOperationImport(operationImport)); } }
public void CreateSwaggerPathForOperationOfEntity_ReturnsSwaggerObject() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntity(_isCustomerUpgradedWithParam, _customers); // Assert Assert.NotNull(obj); Assert.Contains("\"Call operation IsUpgradedWithParam\"", obj.ToString()); }
public void CreateSwaggerPathForOperationImport_ReturnsSwaggerObject() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForOperationImport(_getCustomers); // Assert Assert.NotNull(obj); Assert.Contains("\"Call operation import GetCustomers\"", obj.ToString()); }
public void CreateSwaggerPathForEntity_ReturnsSwaggerObject() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForEntity(_customers); // Assert Assert.NotNull(obj); Assert.Contains("\"Get entity from Customers by key.\"", obj.ToString()); }
public void CreateSwaggerPathForEntitySet_ReturnsEmptyObject_IfNavigationSourceNull() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForEntitySet(navigationSource: null); // Assert Assert.NotNull(obj); Assert.Equal(new JObject(), obj); }
public void CreateSwaggerDefinitionForStructureType_ReturnsSwaggerObject() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerTypeDefinitionForStructuredType(_customer); // Assert Assert.NotNull(obj); Assert.Contains("\"$ref\": \"#/definitions/NS.Address\"", obj.ToString()); }
public void GetPathForOperationOfEntity_Returns() { // Arrange & Act string path = ODataSwaggerUtilities.GetPathForOperationOfEntity(_isCustomerUpgradedWithParam, _customers); // Assert Assert.NotNull(path); Assert.Equal("/Customers({ID})/NS.IsUpgradedWithParam(city='{city}')", path); }
public void GetPathForOperationOfEntitySet_Returns() { // Arrange & Act string path = ODataSwaggerUtilities.GetPathForOperationOfEntitySet(_isAnyUpgraded, _customers); // Assert Assert.NotNull(path); Assert.Equal("/Customers/NS.IsAnyUpgraded()", path); }
public void GetPathForOperationImport_Returns() { // Arrange & Act string path = ODataSwaggerUtilities.GetPathForOperationImport(_getCustomers); // Assert Assert.NotNull(path); Assert.Equal("/GetCustomers()", path); }
public void GetPathForEntity_Returns() { // Arrange & Act string path = ODataSwaggerUtilities.GetPathForEntity(_customers); // Assert Assert.NotNull(path); Assert.Equal("/Customers({ID})", path); }
/// <summary> /// Initialize the operations to Swagger model. /// </summary> protected virtual void InitializeOperations() { Contract.Assert(SwaggerDoc != null); Contract.Assert(EdmModel != null); Contract.Assert(SwaggerPaths != null); if (EdmModel.EntityContainer == null) { return; } foreach (var operation in EdmModel.SchemaElements.OfType <IEdmOperation>()) { // skip unbound operation if (!operation.IsBound) { continue; } var boundParameter = operation.Parameters.First(); var boundType = boundParameter.Type.Definition; // skip operation bound to non entity (or entity collection) if (boundType.TypeKind == EdmTypeKind.Entity) { IEdmEntityType entityType = (IEdmEntityType)boundType; foreach (var entitySet in EdmModel.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType))) { SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForOperationOfEntity(operation, entitySet), ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntity(operation, entitySet)); } } else if (boundType.TypeKind == EdmTypeKind.Collection) { IEdmCollectionType collectionType = boundType as IEdmCollectionType; if (collectionType != null && collectionType.ElementType.Definition.TypeKind == EdmTypeKind.Entity) { IEdmEntityType entityType = (IEdmEntityType)collectionType.ElementType.Definition; foreach (var entitySet in EdmModel.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType))) { SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForOperationOfEntitySet(operation, entitySet), ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntitySet(operation, entitySet)); } } } } }
/// <summary> /// Initialize the type definitions to Swagger model. /// </summary> protected virtual void InitializeTypeDefinitions() { Contract.Assert(SwaggerDoc != null); Contract.Assert(EdmModel != null); SwaggerDefinitions = new JObject(); SwaggerDoc.Add("definitions", SwaggerDefinitions); foreach (var type in EdmModel.SchemaElements.OfType <IEdmStructuredType>()) { SwaggerDefinitions.Add(type.FullTypeName(), ODataSwaggerUtilities.CreateSwaggerDefinitionForStructureType(type)); } }