public OperationSpec ApiDescriptionToOperationSpec(ApiDescription apiDescription, ModelSpecRegistrar modelSpecRegistrar) { var apiPath = apiDescription.RelativePathSansQueryString(); var paramSpecs = apiDescription.ParameterDescriptions .Select(paramDesc => CreateParameterSpec(paramDesc, apiPath, modelSpecRegistrar)) .ToList(); var operationSpec = new OperationSpec { Method = apiDescription.HttpMethod.Method, Nickname = apiDescription.Nickname(), Summary = apiDescription.Documentation, Parameters = paramSpecs, ResponseMessages = new List<ResponseMessageSpec>() }; var returnType = apiDescription.ActionDescriptor.ReturnType; if (returnType == null) { operationSpec.Type = "void"; } else { IEnumerable<ModelSpec> complexSpecs; var modelSpec = _modelSpecGenerator.TypeToModelSpec(returnType, out complexSpecs); modelSpecRegistrar.RegisterMany(complexSpecs); if (modelSpec.Type == "object") { operationSpec.Type = modelSpec.Id; } else { operationSpec.Type = modelSpec.Type; operationSpec.Format = modelSpec.Format; operationSpec.Items = modelSpec.Items; operationSpec.Enum = modelSpec.Enum; } } foreach (var filter in _operationFilters) { filter.Apply(apiDescription, operationSpec, modelSpecRegistrar, _modelSpecGenerator); } // IOperationSpecFilter is obsolete - below is for back-compat var modelSpecMap = new ModelSpecMap(modelSpecRegistrar, _modelSpecGenerator); foreach (var filter in _operationSpecFilters) { filter.Apply(apiDescription, operationSpec, modelSpecMap); } return operationSpec; }
public Operation ApiDescriptionToOperation(ApiDescription apiDescription, Dictionary<string, DataType> complexModels) { var apiPath = apiDescription.RelativePathSansQueryString(); var parameters = apiDescription.ParameterDescriptions .Select(paramDesc => CreateParameter(paramDesc, apiPath, complexModels)) .ToList(); var operation = new Operation { Method = apiDescription.HttpMethod.Method, Nickname = apiDescription.Nickname(), Summary = apiDescription.Documentation, Parameters = parameters, ResponseMessages = new List<ResponseMessage>() }; var responseType = apiDescription.ActualResponseType(); if (responseType == null) { operation.Type = "void"; } else { IDictionary<string, DataType> complexModelsForResponseType; var dataType = _dataTypeGenerator.TypeToDataType(responseType, out complexModelsForResponseType); complexModels.Merge(complexModelsForResponseType); if (dataType.Type == "object") { operation.Type = dataType.Id; } else { operation.Type = dataType.Type; operation.Format = dataType.Format; operation.Items = dataType.Items; operation.Enum = dataType.Enum; } } foreach (var filter in _operationFilters) { filter.Apply(operation, complexModels, _dataTypeGenerator, apiDescription); } return operation; }
public Operation ApiDescriptionToOperation(ApiDescription apiDescription) { var apiPath = apiDescription.RelativePathSansQueryString(); var parameters = apiDescription.ParameterDescriptions .Select(paramDesc => CreateParameter(paramDesc, apiPath)) .ToList(); var operation = new Operation { Method = apiDescription.HttpMethod.Method, Nickname = apiDescription.Nickname(), Summary = apiDescription.Documentation ?? "", Parameters = parameters, ResponseMessages = new List<ResponseMessage>(), Produces = apiDescription.SupportedResponseFormatters.SelectMany(d => d.SupportedMediaTypes.Select(t => t.MediaType)).ToList(), Consumes = apiDescription.SupportedRequestBodyFormatters.SelectMany(d => d.SupportedMediaTypes.Select(t => t.MediaType)).ToList() }; var responseType = apiDescription.ActualResponseType(); if (responseType == null) { operation.Type = "void"; } else { var dataType = _dataTypeRegistry.GetOrRegister(responseType); if (dataType.Type == "object") { operation.Type = dataType.Id; } else { operation.Type = dataType.Type; operation.Format = dataType.Format; operation.Items = dataType.Items; operation.Enum = dataType.Enum; } } foreach (var filter in _operationFilters) { filter.Apply(operation, _dataTypeRegistry, apiDescription); } return operation; }