private Parameter CreateParameter(ApiParameterDescription paramDesc, bool inPath, SchemaRegistry schemaRegistry) { var @in = (inPath) ? "path" : (paramDesc.Source == ApiParameterSource.FromUri) ? "query" : "body"; var parameter = new Parameter { name = paramDesc.Name, @in = @in }; if (paramDesc.ParameterDescriptor == null) { parameter.type = "string"; parameter.required = true; return parameter; } parameter.required = inPath || !paramDesc.ParameterDescriptor.IsOptional; parameter.@default = paramDesc.ParameterDescriptor.DefaultValue; var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType); if (parameter.@in == "body") parameter.schema = schema; else parameter.PopulateFrom(schema); return parameter; }
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 || 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(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; }