public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (!operation.responses.ContainsKey("default") && operation.responses.ContainsKey("200")) { operation.responses.Add("default", operation.responses["200"]); } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation == null) { throw new ArgumentNullException("operation"); } if (apiDescription == null) { throw new ArgumentNullException("apiDescription"); } Collection<IFilter> filters = apiDescription.ActionDescriptor.ControllerDescriptor.GetFilters(); IEnumerable<IFilter> mobileAppFilter = filters.Where(f => typeof(MobileAppControllerAttribute).IsAssignableFrom(f.GetType())); if (mobileAppFilter.Any()) { if (operation.parameters == null) { operation.parameters = new List<Parameter>(); } operation.parameters.Add(new Parameter { name = "ZUMO-API-VERSION", @in = "header", type = "string", required = true, @default = "2.0.0" }); } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation.operationId == "FileDownload_GetFile") { operation.produces = new[] { "application/octet-stream" }; } }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { Contract.Assume(swaggerDoc != null); Contract.Assume(schemaRegistry != null); Contract.Assume(apiExplorer != null); var pathItems = swaggerDoc.paths.Values; var deletes = pathItems.Select(pathItem => pathItem.delete).Where(operation => operation != null); var gets = pathItems.Select(pathItem => pathItem.get).Where(operation => operation != null); var heads = pathItems.Select(pathItem => pathItem.head).Where(operation => operation != null); var patches = pathItems.Select(pathItem => pathItem.patch).Where(operation => operation != null); var puts = pathItems.Select(pathItem => pathItem.put).Where(operation => operation != null); var posts = pathItems.Select(pathItem => pathItem.post).Where(operation => operation != null); var options = pathItems.Select(pathItem => pathItem.options).Where(operation => operation != null); var allOperations = deletes.ConcatEvenIfNull(gets) .ConcatEvenIfNull(heads) .ConcatEvenIfNull(patches) .ConcatEvenIfNull(puts) .ConcatEvenIfNull(posts) .ConcatEvenIfNull(options) .ToList(); AppendParameterNamesToOperationId(allOperations); UniquifyOperationId(allOperations); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { List<SwaggerDefaultValue> listDefine = new List<SwaggerDefaultValue> { new SwaggerDefaultValue("Compare", "<", "<,<=,>,>=,="), //new SwaggerDefaultValue("Model_URI", "@{body(\'besconnector').Results.output2.FullURL}"), //new SwaggerDefaultValue("Evaluate_Output_Path", "@{body(\'besconnector\').Results.output1.FullURL}") }; if (operation.parameters == null) return; foreach (var param in operation.parameters) { var actionParam = apiDescription.ActionDescriptor.GetParameters().First(p => p.ParameterName == param.name); foreach (SwaggerDefaultValue customAttribute in listDefine) { if (customAttribute.ParameterName == param.name) { param.@default = customAttribute.DefaultValue; string[] listValue = customAttribute.Values.Split(','); if (listValue != null && listValue.Length > 1) param.@enum = listValue; } } } }
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; }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation.parameters == null) return; HandleFromUriArrayParams(operation); HandleFromUriObjectParams(operation, schemaRegistry, apiDescription); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { var hasAuthorizeAttr = apiDescription.ActionDescriptor.GetFilterPipeline() .Select(filterInfo => filterInfo.Instance) .Any(filter => filter is IAuthorizationFilter); var hasAllowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any(); if (hasAuthorizeAttr && !hasAllowAnonymous) { if (operation.parameters == null) { operation.parameters = new List<Parameter>(); } operation.parameters.Add(new Parameter() { description = "Authorization token. Used for applying content access restrictions. Use one of the OAuth2 grants to auto-populate this value.", @in = "header", name = "Authorization", required = true, type = "string", @default = "bearer " }); } }
/// <summary> /// Implement the interace of operation filter /// </summary> /// <param name="operation"></param> /// <param name="schemaRegistry"></param> /// <param name="apiDescription"></param> public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { if (operation != null && operation.responses != null && operation.responses.ContainsKey("202")) { operation.responses["202"].schema = null; } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { // Determine if the operation has the Authorize attribute var authorizeAttributes = apiDescription .ActionDescriptor.GetCustomAttributes<AuthorizeAttribute>(); if (!authorizeAttributes.Any()) return; // Correspond each "Authorize" role to an oauth2 scope var scopes = authorizeAttributes .SelectMany(attr => attr.Roles.Split(',')) .Distinct() .ToList(); // Initialize the operation.security property if it hasn't already been if (operation.security == null) operation.security = new List<IDictionary<string, IEnumerable<string>>>(); var oAuthRequirements = new Dictionary<string, IEnumerable<string>> { { "oauth2", scopes } }; operation.security.Add(oAuthRequirements); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { // stripping the name string operationName = operation.operationId; if (!string.IsNullOrEmpty(operationName)) { // swashbuckle adds controller name, stripping that int index = operationName.IndexOf("_", 0); if (index >= 0 && (index + 1) < operationName.Length) { operation.operationId = operationName.Substring(index + 1); } } // operation response change IDictionary<string, Response> responses = operation.responses; if (responses != null && !responses.ContainsKey(defaultResponseCode)) { try { string successResponseCode = JsonSwaggerGenerator.GetReturnCodeForSuccess(responses.Keys); Response successResponse = responses[successResponseCode]; Response defaultResponse = new Response(); defaultResponse.description = Resources.DefaultResponseDescription; defaultResponse.schema = null; responses.Add(defaultResponseCode, defaultResponse); } catch(InvalidOperationException) { throw new Exception("No success code found, not adding default response code"); } } }
/// <summary> /// /// </summary> /// <param name="swaggerDoc"></param> /// <param name="schemaRegistry"></param> /// <param name="apiExplorer"></param> public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { IList<string> apilist = new List<string>(); if (swaggerDoc != null && swaggerDoc.paths != null) { foreach (System.Collections.Generic.KeyValuePair<string, PathItem> pathitem in swaggerDoc.paths) { if (pathitem.Key.Contains("OAuth")) { apilist.Add(pathitem.Key); } } } foreach (string pathitem in apilist) { swaggerDoc.paths.Remove(pathitem); } if (swaggerDoc != null && swaggerDoc.definitions != null) { swaggerDoc.definitions.Remove("TokenResult"); swaggerDoc.definitions.Remove("Object"); } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation == null) { throw new ArgumentNullException("operation"); } if (apiDescription == null) { throw new ArgumentNullException("apiDescription"); } // Correspond each "Authorize" action to an oauth2 scope var authorized = apiDescription.ActionDescriptor.GetFilterPipeline() .Select(filterInfo => filterInfo.Instance) .OfType<AuthorizeAttribute>() .Distinct(); if (authorized.Any()) { if (operation.security == null) { operation.security = new List<IDictionary<string, IEnumerable<string>>>(); } var requirements = new Dictionary<string, IEnumerable<string>> { { this.provider, new string[] { } } }; operation.security.Add(requirements); } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation.operationId != "Products_GetAllByType") return; var response = operation.responses["200"]; response.vendorExtensions = new Dictionary<string, object>(); response.vendorExtensions.Add("x-foo", "bar"); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { var descriptor = apiDescription.ActionDescriptor as ControllerlessActionDescriptor; operation.summary = descriptor != null ? this.provider.GetDescription(descriptor.MessageType) : operation.summary; }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { var successResponse = operation.responses["200"]; successResponse.examples = new Dictionary<string, object> { {"application/json", new {title = "A message", content = "Some content"}} }; }
private static Schema HandleGenericODataTypeThatShouldBeUnwrapped(SchemaRegistry registry, IEdmModel edmModel, Type type) { var genericArguments = type.GetGenericArguments(); Contract.Assume(genericArguments != null); var schema = registry.GetOrRegister(genericArguments[0]); ApplyEdmModelPropertyNamesToSchema(registry, edmModel, genericArguments[0]); return schema; }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { swaggerDoc.basePath = "/" + swaggerDoc.info.version; swaggerDoc.paths = swaggerDoc.paths.ToDictionary( entry => entry.Key.Replace("/{apiVersion}", ""), entry => RemoveVersionParamsFrom(entry.Value)); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { // Add a default response code if(operation != null && operation.responses != null && operation.responses.ContainsKey("200")) { operation.responses.Add("default", operation.responses["200"]); } }
private static void FixSchemaReference(SchemaRegistry registry, Schema schema, Type referencedType) { Contract.Requires(schema.@ref != null); var schemaIdSelector = registry.GetInstanceField<Func<Type, string>>("_schemaIdSelector", true); schema.@ref = "#/definitions/" + schemaIdSelector(referencedType); }
public ModelFilterContext( Type systemType, JsonObjectContract jsonObjectContract, SchemaRegistry schemaRegistry) { SystemType = systemType; JsonObjectContract = jsonObjectContract; SchemaRegistry = schemaRegistry; }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, System.Web.Http.Description.IApiExplorer apiExplorer) { IList<IDictionary<string, IEnumerable<string>>> security = new List<IDictionary<string, IEnumerable<string>>>(); security.Add(new Dictionary<string, IEnumerable<string>> { {Key, new string[0]} }); swaggerDoc.security = security; }
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) { if (schema == null || schema.properties == null || type == null) return; bool isPushTrigger = type.AssemblyQualifiedNameNoTypeParams() == typeof(TriggerInput<string, string>).AssemblyQualifiedNameNoTypeParams(); foreach (var propertyName in schema.properties.Keys) { var property = schema.properties[propertyName]; if (isPushTrigger && propertyName == Constants.CALLBACK_URL_PROPERTY_NAME) { #region Apply callback magic defaults // Apply trigger magic defaults: // "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri schema.SetChildPropertyRequired(Constants.CALLBACK_URL_PROPERTY_NAME); property.SetVisibility(VisibilityType.Internal); property.SetSchedulerRecommendation(Constants.CALLBACK_URL_MAGIC_DEFAULT); // This is what this will look like (pulled from HTTP Listener API Definition) // // "TriggerInput[TriggerPushParameters,TriggerOutputParameters]": { // "required": [ <-- SetChildPropertyRequired (on the parent model containing the callbackUrl property) // "callbackUrl" // ], // "type": "object", // "properties": { // "callbackUrl": { <-- SetSchedulerRecommendation (on the actual property) // "type": "string", // "x-ms-visibility": "internal", // "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri" // }, #endregion } // Apply friendly names and descriptions wherever possible // "x-ms-summary" - friendly name (applies to properties) // schema.properties["prop"].description - description (applies to parameters) var propertyInfo = type.GetRuntimeProperties().Where(p => p.Name == propertyName).FirstOrDefault(); if (propertyInfo == null) return; var propertyMetadata = propertyInfo.GetCustomAttribute<MetadataAttribute>(); if (propertyMetadata != null) { property.SetVisibility(propertyMetadata.Visibility); property.SetFriendlyNameAndDescription(propertyMetadata.FriendlyName, propertyMetadata.Description); } } }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { //添加Tag swaggerDoc.tags = new List<Tag>(); var controllers = apiExplorer.ApiDescriptions.Select(p => p.ActionDescriptor.ControllerDescriptor).Distinct(); foreach (var item in controllers) { var desc = item.GetCustomAttributes<DisplayNameAttribute>(); if (desc != null && desc.Count > 0) { //hack swaggerDoc.tags.Add(new Tag() { name = hackcontrollername(item.ControllerName), description = desc[0].DisplayName }); } else { var desc2 = item.GetCustomAttributes<DescriptionAttribute>(); if (desc2 != null && desc2.Count > 0) { swaggerDoc.tags.Add(new Tag() { name = hackcontrollername(item.ControllerName), description = desc2[0].Description }); } } } //优化枚举显示 foreach (var schemaDictionaryItem in swaggerDoc.definitions) { var schema = schemaDictionaryItem.Value; foreach (var propertyDictionaryItem in schema.properties) { var property = propertyDictionaryItem.Value; var propertyEnums = property.@enum; if (propertyEnums != null && propertyEnums.Count > 0) { var enumDescriptions = new List<string>(); for (int i = 0; i < propertyEnums.Count; i++) { var enumOption = propertyEnums[i]; var desc =(DisplayAttribute) enumOption.GetType().GetField(enumOption.ToString()).GetCustomAttributes(true).Where(p => p is DisplayAttribute).FirstOrDefault(); if (desc==null) { enumDescriptions.Add(string.Format("{0} = {1} ", Convert.ToInt32(enumOption), Enum.GetName(enumOption.GetType(), enumOption))); } else { enumDescriptions.Add(string.Format("{0} = {1} ", Convert.ToInt32(enumOption), desc.Name)); } } property.description += string.Format(" ({0})", string.Join(", ", enumDescriptions.ToArray())); } } } }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { var errorSchema = schemaRegistry.GetOrRegister(typeof(HttpError)); operation.responses.Add("200", new Response { description = "Ok", schema = errorSchema }); }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { Contract.Assume(operation != null); Contract.Assume(schemaRegistry != null); Contract.Assume(apiDescription != null); if (HasEnableQueryAttribute(apiDescription) && !HasAnyQueryOptionParameters(operation)) { operation.parameters = ODataSwaggerUtilities.AddQueryOptionParameters(operation.parameters ?? new List<Parameter>()); } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="dataTypeRegistry"></param> /// <param name="type"></param> public void Apply(Schema model, SchemaRegistry dataTypeRegistry, Type type) { if (model != null && dataTypeRegistry != null && type != null) { var ignoredProperties = type.GetProperties().Where(p => p.GetCustomAttributes(typeof(JsonIgnoreAttribute), false).FirstOrDefault() != null); foreach (var property in ignoredProperties) { model.properties.Remove(property.Name); } } }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { swaggerDoc.tags = new List<Tag> { new Tag { name = "Clients", description = "an ApiController resource" }, new Tag { name = "Customers", description = "an ODataController resource" }, new Tag { name = "Orders", description = "an ODataController resource" }, new Tag { name = "CustomersV1", description = "a versioned ODataController resource" }, new Tag { name = "Users", description = "a RESTier resource" }, new Tag { name = "Products", description = "demonstrates OData functions and actions" } }; }
public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { operation.parameters = operation.parameters ?? new List<Parameter>(); operation.parameters.Add(new Parameter { name = Name, description = Description, @in = In, required = true, type = "string" }); }
public SwaggerDocument GetSwagger(string rootUrl, string apiVersion) { var schemaRegistry = new SchemaRegistry( _jsonSerializerSettings, _options.CustomSchemaMappings, _options.SchemaFilters, _options.ModelFilters, _options.IgnoreObsoleteProperties, _options.SchemaIdSelector, _options.DescribeAllEnumsAsStrings, _options.DescribeStringEnumsInCamelCase, _options.ApplyFiltersToAllSchemas); Info info; _apiVersions.TryGetValue(apiVersion, out info); if (info == null) { throw new UnknownApiVersion(apiVersion); } /*var paths0 = GetApiDescriptionsFor(apiVersion).ToList();*/ var paths = GetApiDescriptionsFor(apiVersion) .Where(apiDesc => !(_options.IgnoreObsoleteActions && apiDesc.IsObsolete())) .OrderBy(_options.GroupingKeySelector, _options.GroupingKeyComparer) .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString()) .ToDictionary(group => "/" + group.Key, group => CreatePathItem(group, schemaRegistry)); var rootUri = new Uri(rootUrl); var port = (!rootUri.IsDefaultPort) ? ":" + rootUri.Port : string.Empty; var swaggerDoc = new SwaggerDocument { info = info, host = rootUri.Host + port, basePath = (rootUri.AbsolutePath != "/") ? rootUri.AbsolutePath : null, schemes = (_options.Schemes != null) ? _options.Schemes.ToList() : new[] { rootUri.Scheme }.ToList(), paths = paths, definitions = schemaRegistry.Definitions, securityDefinitions = _options.SecurityDefinitions }; swaggerDoc.muiltVersion = new List <Info>(); foreach (var version in _apiVersions) { swaggerDoc.muiltVersion.Add(version.Value); } if (SwaggerEnabledConfiguration.DiscoveryPaths != null && SwaggerEnabledConfiguration.DiscoveryPaths.Any()) { foreach (var version in swaggerDoc.muiltVersion) { var path = SwaggerEnabledConfiguration.DiscoveryPaths.FirstOrDefault(x => x.Contains(version.version)); if (!string.IsNullOrEmpty(path)) { version.docPath = path; if (version.version == swaggerDoc.info.version) { //mt 这傻逼在循环里只修改第一条数据 //这里是给路径加上虚拟地址 version.docPath = string.IsNullOrWhiteSpace(swaggerDoc.basePath) ? path : (swaggerDoc.basePath + "/" + path); // swaggerDoc.info.docPath = string.IsNullOrWhiteSpace(swaggerDoc.basePath) ? path : (swaggerDoc.basePath + "/" + path); } else//mt 这里是给没有版本号的区域加上虚拟目录 { version.docPath = string.IsNullOrWhiteSpace(swaggerDoc.basePath) ? path : (swaggerDoc.basePath + "/" + path); } } } } var keys = paths.Keys.ToList(); SetTags(swaggerDoc, _options.ModelFilters, keys); foreach (var filter in _options.DocumentFilters.OrderBy(p => p)) { filter.Apply(swaggerDoc, schemaRegistry, _apiExplorer); } //todo 这里是排序的代码 //mt 2019-01-04 swaggerDoc.paths = swaggerDoc.paths.OrderBy(p => p.Key).ToDictionary(pair => pair.Key, pair => pair.Value); return(swaggerDoc); }
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); var reflectedDescriptor = (ReflectedHttpParameterDescriptor)paramDesc.ParameterDescriptor; foreach (var attribute in reflectedDescriptor.ParameterInfo.GetCustomAttributes(true)) { SchemaExtensions.SetSchemaDetails(schema, attribute); } //if (paramDesc.ParameterDescriptor.ActionDescriptor != null) //{ // var actionIgnore = paramDesc.ParameterDescriptor.ActionDescriptor.GetCustomAttributes<SwaggerIgnore>(); // if (actionIgnore != null) // { // parameter.ignore = true; // } //} if (parameter.@in == "body") { parameter.schema = schema; } else { parameter.PopulateFrom(schema); } return(parameter); }
private PathItem CreatePathItem(IEnumerable <ApiDescription> apiDescriptions, SchemaRegistry schemaRegistry) { var pathItem = new PathItem(); // Group further by http method var perMethodGrouping = apiDescriptions .GroupBy(apiDesc => apiDesc.HttpMethod.Method.ToLower()); foreach (var group in perMethodGrouping) { var httpMethod = group.Key; var apiDescription = (group.Count() == 1) ? group.First() : _options.ConflictingActionsResolver(group); switch (httpMethod) { case "get": pathItem.get = CreateOperation(apiDescription, schemaRegistry); break; case "put": pathItem.put = CreateOperation(apiDescription, schemaRegistry); break; case "post": pathItem.post = CreateOperation(apiDescription, schemaRegistry); break; case "delete": pathItem.delete = CreateOperation(apiDescription, schemaRegistry); break; case "options": pathItem.options = CreateOperation(apiDescription, schemaRegistry); break; case "head": pathItem.head = CreateOperation(apiDescription, schemaRegistry); break; case "patch": pathItem.patch = CreateOperation(apiDescription, schemaRegistry); break; } } return(pathItem); }
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 = !paramDesc.ParameterDescriptor.IsOptional; var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType); if (parameter.@in == "body") { parameter.schema = schema; } else { parameter.PopulateFrom(schema); } return(parameter); }
private Parameter CreateParameter(string location, ApiParameterDescription paramDesc, SchemaRegistry schemaRegistry) { var parameter = new Parameter { @in = location, name = paramDesc.Name }; if (paramDesc.ParameterDescriptor == null) { parameter.type = "string"; parameter.required = true; return(parameter); } parameter.required = location == "path" || !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); }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { // Change host to be UI swaggerDoc.host = UrlHelper.TrimProtocol(ApplicationConfiguration.UrlUI); // Remove private API calls from live docs if (ApplicationConfiguration.IsEnvironmentLive) { var omitedControllers = new List<string> { "Home", "Log", "StaticReports", "PdfReporting", "NonPublicServices" }; foreach (var apiDescription in apiExplorer.ApiDescriptions) { if (omitedControllers.Contains(apiDescription.ActionDescriptor.ControllerDescriptor.ControllerName)) { var route = "/" + apiDescription.Route.RouteTemplate.TrimEnd('/'); swaggerDoc.paths.Remove(route); } } } }