예제 #1
0
        /// <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));
            }
        }
예제 #2
0
        public void CreateSwaggerPathForOperationOfEntity_ReturnsSwaggerObject()
        {
            // Arrange & Act
            JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntity(_isCustomerUpgradedWithParam, _customers);

            // Assert
            Assert.NotNull(obj);
            Assert.Contains("\"Call operation  IsUpgradedWithParam\"", obj.ToString());
        }
예제 #3
0
        public void CreateSwaggerPathForOperationImport_ReturnsSwaggerObject()
        {
            // Arrange & Act
            JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForOperationImport(_getCustomers);

            // Assert
            Assert.NotNull(obj);
            Assert.Contains("\"Call operation import  GetCustomers\"", obj.ToString());
        }
예제 #4
0
        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());
        }
예제 #5
0
        public void CreateSwaggerPathForEntitySet_ReturnsEmptyObject_IfNavigationSourceNull()
        {
            // Arrange & Act
            JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForEntitySet(navigationSource: null);

            // Assert
            Assert.NotNull(obj);
            Assert.Equal(new JObject(), obj);
        }
예제 #6
0
        public void CreateSwaggerDefinitionForStructureType_ReturnsSwaggerObject()
        {
            // Arrange & Act
            JObject obj = ODataSwaggerUtilities.CreateSwaggerTypeDefinitionForStructuredType(_customer);

            // Assert
            Assert.NotNull(obj);
            Assert.Contains("\"$ref\": \"#/definitions/NS.Address\"", obj.ToString());
        }
예제 #7
0
        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);
        }
예제 #8
0
        public void GetPathForOperationOfEntitySet_Returns()
        {
            // Arrange & Act
            string path = ODataSwaggerUtilities.GetPathForOperationOfEntitySet(_isAnyUpgraded, _customers);

            // Assert
            Assert.NotNull(path);
            Assert.Equal("/Customers/NS.IsAnyUpgraded()", path);
        }
예제 #9
0
        public void GetPathForOperationImport_Returns()
        {
            // Arrange & Act
            string path = ODataSwaggerUtilities.GetPathForOperationImport(_getCustomers);

            // Assert
            Assert.NotNull(path);
            Assert.Equal("/GetCustomers()", path);
        }
예제 #10
0
        public void GetPathForEntity_Returns()
        {
            // Arrange & Act
            string path = ODataSwaggerUtilities.GetPathForEntity(_customers);

            // Assert
            Assert.NotNull(path);
            Assert.Equal("/Customers({ID})", path);
        }
예제 #11
0
        /// <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));
                        }
                    }
                }
            }
        }
예제 #12
0
        /// <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));
            }
        }