当前位置: 首页>>代码示例>>C#>>正文


C# ApiDescription.Produces方法代码示例

本文整理汇总了C#中System.Web.Http.Description.ApiDescription.Produces方法的典型用法代码示例。如果您正苦于以下问题:C# ApiDescription.Produces方法的具体用法?C# ApiDescription.Produces怎么用?C# ApiDescription.Produces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Http.Description.ApiDescription的用法示例。


在下文中一共展示了ApiDescription.Produces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateOperation

        private Operation CreateOperation(ApiDescription apiDescription, SchemaRegistry schemaRegistry)
        {
            Contract.Requires(apiDescription != null);
            Contract.Requires(schemaRegistry != null);
            Contract.Requires(apiDescription.ParameterDescriptions != null);


            var edmModel = ((ODataRoute)apiDescription.Route).GetEdmModel();

            var parameters = apiDescription.ParameterDescriptions
                .Select(paramDesc =>
                {
                    var inPath = apiDescription.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}");
                    var swaggerApiParameterDescription = paramDesc as SwaggerApiParameterDescription;
                    return swaggerApiParameterDescription != null 
                    ? CreateParameter(swaggerApiParameterDescription, inPath, schemaRegistry, edmModel) 
                    : CreateParameter(paramDesc, inPath, schemaRegistry, edmModel);
                })
                 .ToList();
            var responses = new Dictionary<string, Response>();
            var responseType = apiDescription.ResponseType();
            if (responseType == null || responseType == typeof(void))
                responses.Add("204", new Response { description = "No Content" });
            else
                responses.Add("200", new Response { description = "OK", schema = schemaRegistry.GetOrRegisterResponseType(edmModel, responseType) });

            var operation = new Operation
            {
                summary = apiDescription.Documentation,
                tags = new[] { _options.GroupingKeySelector(apiDescription) },
                operationId = apiDescription.OperationId(),
                produces = apiDescription.Produces()?.ToList(),
                consumes = apiDescription.Consumes()?.ToList(),
                parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
                responses = responses,
                deprecated = apiDescription.IsObsolete()
            };

            foreach (var filter in _options.OperationFilters)
            {
                Contract.Assume(filter != null);
                filter.Apply(operation, schemaRegistry, apiDescription);
            }

            return operation;
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:46,代码来源:ODataSwaggerProvider.cs

示例2: CreateOperation

        private Operation CreateOperation(ApiDescription apiDescription, SchemaRegistry schemaRegistry)
        {
            var parameters = apiDescription.ParameterDescriptions
                .Select(paramDesc =>
                    {
                        var inPath = apiDescription.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}");
                        return CreateParameter(paramDesc, inPath, schemaRegistry);
                    })
                 .ToList();

            var responses = new Dictionary<string, Response>();
            var responseType = apiDescription.ResponseType();
            if (responseType == null)
                responses.Add("204", new Response { description = "No Content" });
            else
                responses.Add("200", new Response { description = "OK", schema = schemaRegistry.GetOrRegister(responseType) });

            var operation = new Operation
            { 
                tags = new [] { _options.GroupingKeySelector(apiDescription) },
                operationId = apiDescription.FriendlyId(),
                produces = apiDescription.Produces().ToList(),
                consumes = apiDescription.Consumes().ToList(),
                parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
                responses = responses,
                deprecated = apiDescription.IsObsolete()
            };

            foreach (var filter in _options.OperationFilters)
            {
                filter.Apply(operation, schemaRegistry, apiDescription);
            }

            return operation;
        }
开发者ID:shaunparsloe,项目名称:Swashbuckle,代码行数:35,代码来源:SwaggerGenerator.cs

示例3: CreateOperation

        private Operation CreateOperation(ApiDescription apiDesc, SchemaRegistry schemaRegistry)
        {
            var parameters = apiDesc.ParameterDescriptions
                .Select(paramDesc =>
                    {
                        string location = GetParameterLocation(apiDesc, paramDesc);
                        return CreateParameter(location, paramDesc, schemaRegistry);
                    })
                 .ToList();

            var responses = new Dictionary<string, Response>();
            var responseType = apiDesc.ResponseType();
            if (responseType == null || responseType == typeof(void))
                responses.Add("204", new Response { description = "No Content" });
            else
                responses.Add("200", new Response { description = "OK", schema = schemaRegistry.GetOrRegister(responseType) });

            var operation = new Operation
            {
                tags = new [] { _options.GroupingKeySelector(apiDesc) },
                operationId = apiDesc.FriendlyId(),
                produces = apiDesc.Produces().ToList(),
                consumes = apiDesc.Consumes().ToList(),
                parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
                responses = responses,
                deprecated = apiDesc.IsObsolete()
            };

            foreach (var filter in _options.OperationFilters)
            {
                filter.Apply(operation, schemaRegistry, apiDesc);
            }

            return operation;
        }
开发者ID:sk8tz,项目名称:Swashbuckle,代码行数:35,代码来源:SwaggerGenerator.cs


注:本文中的System.Web.Http.Description.ApiDescription.Produces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。