Пример #1
0
        /// <summary>
        /// Convert <see cref="IEdmModel"/> to <see cref="OpenApiDocument"/> using a convert settings.
        /// </summary>
        /// <param name="model">The Edm model.</param>
        /// <param name="settings">The convert settings.</param>
        /// <returns>The converted Open API document object, <see cref="OpenApiDocument"/>.</returns>
        public static OpenApiDocument ConvertToOpenApi(this IEdmModel model, OpenApiConvertSettings settings)
        {
            Utils.CheckArgumentNull(model, nameof(model));
            Utils.CheckArgumentNull(settings, nameof(settings));

            if (settings.VerifyEdmModel)
            {
                IEnumerable <EdmError> errors;
                if (!model.Validate(out errors))
                {
                    OpenApiDocument document = new OpenApiDocument();
                    int             index    = 1;
                    foreach (var error in errors)
                    {
                        document.Extensions.Add(Constants.xMsEdmModelError + index++, new OpenApiString(error.ToString()));
                    }

                    return(document);
                }
            }

            ODataContext context = new ODataContext(model, settings);

            return(context.CreateDocument());
        }
        public void CreateDocumentThrowArgumentNullContext()
        {
            // Arrange
            ODataContext context = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>("context", () => context.CreateDocument());
        }
        public void CreateDocumentReturnsForEmptyModel()
        {
            // Arrange
            IEdmModel    model   = EdmModelHelper.EmptyModel;
            ODataContext context = new ODataContext(model);

            // Act
            var document = context.CreateDocument();

            // Assert
            Assert.NotNull(document);
            Assert.NotNull(document.Info);
            Assert.NotNull(document.Tags);
            Assert.NotNull(document.Servers);
            Assert.NotNull(document.Paths);
            Assert.NotNull(document.Components);

            Assert.Null(document.ExternalDocs);
            Assert.Null(document.SecurityRequirements);
        }