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; }
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; }
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; }