Exemplo n.º 1
0
        private static void ApplyCommonSwaggerConfiguration(SwaggerDocsConfig c, IUnityContainer container, string cacheKey, string[] xmlCommentsFilePaths)
        {
            var cacheManager = container.Resolve <ICacheManager <object> >();

            c.CustomProvider(defaultProvider => new CachingSwaggerProvider(defaultProvider, cacheManager, cacheKey));
            c.MapType <object>(() => new Schema {
                type = "object"
            });
            c.IgnoreObsoleteProperties();
            c.DescribeAllEnumsAsStrings();
            c.OperationFilter(() => new OptionalParametersFilter());
            c.OperationFilter(() => new FileResponseTypeFilter());
            c.OperationFilter(() => new FileUploadOperationFilter());
            c.OperationFilter(() => new AssignOAuth2SecurityOperationFilter());
            c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
            c.RootUrl(message => new Uri(ComputeHostAsSeenByOriginalClient(message), message.GetRequestContext().VirtualPathRoot).ToString());
            c.PrettyPrint();
            c.OAuth2("OAuth2")
            .Description("OAuth2 Resource Owner Password Grant flow")
            .Flow("password")
            .TokenUrl(HttpRuntime.AppDomainAppVirtualPath?.TrimEnd('/') + "/token");

            foreach (var path in xmlCommentsFilePaths)
            {
                c.IncludeXmlComments(path);
            }
        }
 public static void EnableAzureAdB2cOAuth2(this SwaggerDocsConfig c, string tenantId, bool useV2Endpoint, string description, params ScopeDescription[] scopes)
 {
     ValidateScopes(scopes.Select(s => s.ScopeName));
     c.OAuth2("oauth2")
     .Description(description)
     .Flow("implicit")
     .AuthorizationUrl(AuthorizationUrl(tenantId, useV2Endpoint))
     //.TokenUrl(TokenUrl(tenantId, useV2Endpoint))
     .Scopes(s =>
     {
         for (int i = 0; i < DefaultScopes.Length; i++)
         {
             s.Add(DefaultScopes[i], DefaultScopesNames[i]);
         }
         foreach (var scopeDescription in scopes)
         {
             s.Add(scopeDescription.ScopeName, scopeDescription.Description);
         }
     });
     c.OperationFilter(() => new AssignOAuth2SecurityRequirements(scopes));
 }