private OpenApiPaths GeneratePaths(IEnumerable <ServiceEntry> apiDescriptions, SchemaRepository schemaRepository) { var apiDescriptionsByPath = apiDescriptions.OrderBy(p => p.RoutePath) .GroupBy(apiDesc => apiDesc.Descriptor.Id); var paths = new OpenApiPaths(); foreach (var group in apiDescriptionsByPath) { var key = $"/{group.Min(p => p.RoutePath).TrimStart('/')}".Trim(); if (!paths.ContainsKey(key)) { paths.Add(key, new OpenApiPathItem { Operations = GenerateOperations(group, schemaRepository) }); } else { paths.Add($"/{group.Min(p => $" {p.RoutePath}( {string.Join("_", p.Parameters.Select(m => m.ParameterType.Name))})")}", new OpenApiPathItem { Operations = GenerateOperations(group, schemaRepository) }); } } ; return(paths); }
/// <summary> /// Create the <see cref="OpenApiPaths"/> /// </summary> /// <returns>the paths object.</returns> public OpenApiPaths Generate() { if (_paths == null) { _paths = new OpenApiPaths(); if (Model.EntityContainer != null) { foreach (var element in Model.EntityContainer.Elements) { switch (element.ContainerElementKind) { case EdmContainerElementKind.EntitySet: IEdmEntitySet entitySet = element as IEdmEntitySet; if (entitySet != null) { foreach (var item in _nsGenerator.CreatePaths(entitySet)) { _paths.Add(item.Key, item.Value); } } break; case EdmContainerElementKind.Singleton: IEdmSingleton singleton = element as IEdmSingleton; if (singleton != null) { foreach (var item in _nsGenerator.CreatePaths(singleton)) { _paths.Add(item.Key, item.Value); } } break; case EdmContainerElementKind.FunctionImport: IEdmFunctionImport functionImport = element as IEdmFunctionImport; if (functionImport != null) { var functionImportPathItem = functionImport.CreatePathItem(); _paths.Add(functionImport.CreatePathItemName(), functionImportPathItem); } break; case EdmContainerElementKind.ActionImport: IEdmActionImport actionImport = element as IEdmActionImport; if (actionImport != null) { var functionImportPathItem = actionImport.CreatePathItem(); _paths.Add(actionImport.CreatePathItemName(), functionImportPathItem); } break; } } } } return(_paths); }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var updatedPaths = new OpenApiPaths(); swaggerDoc.Paths.ToList().ForEach(p => updatedPaths.Add(p.Key.Replace("v{version}", swaggerDoc.Info.Version), p.Value)); swaggerDoc.Paths = updatedPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var paths = swaggerDoc.Paths .OrderBy(e => e.Key); // alphabetic // Sort on operation level for deprecation var byComplexity = _configuration.SortConfiguration.ThenByComplexity; var deprecatedLast = _configuration.SortConfiguration.DeprecatedLast; if (deprecatedLast) { paths = SortOperationsDeprecatedLastThenByComplexity(swaggerDoc); // alphabetic } // for only complexity else if (byComplexity) { paths = SortOperationsOnlyByComplexity(swaggerDoc); } // sort paths by complexity if (byComplexity) { paths = paths .ThenBy(x => x.Key.Length + x.Value.Parameters.Count); // complexity } var newPaths = new OpenApiPaths(); paths.ToList().ForEach(path => newPaths.Add(path.Key, path.Value)); swaggerDoc.Paths = newPaths; }
public void Apply(OpenApiDocument document, DocumentFilterContext context) { document.Extensions.Add("security", new OpenApiArray { new OpenApiObject { ["default"] = new OpenApiArray { } } }); // Remove /v1 of url path, for swagger wso2 json generator. OpenApiPaths newWsoUrlPaths = new OpenApiPaths(); foreach (var path in document.Paths) { newWsoUrlPaths.Add ( path.Key.Replace("/v1", ""), path.Value ); } document.Paths = newWsoUrlPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var paths = new OpenApiPaths(); foreach (var item in swaggerDoc.Paths.ToDictionary(entry => LowercaseEverythingButParameters(entry.Key), entry => entry.Value)) paths.Add(item.Key, item.Value); swaggerDoc.Paths = paths; }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsProduction()) { app.UseHsts(); } else { app.UseDeveloperExceptionPage(); app.UseSwagger(c => { const string basePath = "/"; if (env.IsDevelopment()) { app.UseHttpsRedirection(); } // set base path for nginx c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new List <OpenApiServer> { new OpenApiServer { Url = $"https://{httpReq.Host.Value}{basePath}" } }); // remove base path from docs in swagger ui c.PreSerializeFilters.Add((swaggerDoc, httpReq) => { var paths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { paths.Add(path.Key.Replace(basePath, "/"), path.Value); } swaggerDoc.Paths = paths; }); }); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "ContentManager Server API V1"); }); } InjectableServicesBaseStaticClass.Services = app.ApplicationServices; app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthentication(); app.UseAuthorization(); app.UseMiddleware <JwtMiddleware>(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var swaggerDocPaths = new OpenApiPaths(); foreach (string key in swaggerDoc.Paths.Keys) { swaggerDocPaths.Add(key.Replace("v{version}", swaggerDoc.Info.Version), swaggerDoc.Paths[key]); } swaggerDoc.Paths = swaggerDocPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var paths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { paths.Add(path.Key.Replace("v{version}", swaggerDoc.Info.Version), path.Value); } swaggerDoc.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var oap = new OpenApiPaths(); foreach (var p in swaggerDoc.Paths) { oap.Add(p.Key.Replace("v{version}", swaggerDoc.Info.Version), p.Value); } swaggerDoc.Paths = oap; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var updatedPaths = new OpenApiPaths(); foreach (var entry in swaggerDoc.Paths) { updatedPaths.Add(entry.Key.Replace("v{version}", swaggerDoc.Info.Version), entry.Value); } swaggerDoc.Paths = updatedPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var newPaths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { var res = HandlePath(path.Value); newPaths.Add(path.Key.ToLowerInvariant(), res); } swaggerDoc.Paths = newPaths; }
public void Apply(OpenApiDocument document, DocumentFilterContext context) { OpenApiPaths paths = new OpenApiPaths(); foreach (var path in document.Paths) { paths.Add(path.Key.Replace("v{version}", document.Info.Version), path.Value); } document.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var paths = new OpenApiPaths(); foreach (var x in swaggerDoc.Paths) { paths.Add(x.Key.Replace("{description.GroupName}", swaggerDoc.Info.Version), x.Value); } swaggerDoc.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var pathLists = new OpenApiPaths(); IDictionary<string, OpenApiPaths> paths = new Dictionary<string, OpenApiPaths>(); var version = swaggerDoc.Info.Version.Replace("v", "").Replace("version", "").Replace("ver", "").Replace(" ", ""); foreach (var path in swaggerDoc.Paths) { pathLists.Add(path.Key.Replace("v{version}", swaggerDoc.Info.Version), path.Value); } swaggerDoc.Paths = pathLists; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var toReplaceWith = new OpenApiPaths(); foreach (var(key, value) in swaggerDoc.Paths) { toReplaceWith.Add(key.Replace("v{version}", swaggerDoc.Info.Version, StringComparison.InvariantCulture), value); } swaggerDoc.Paths = toReplaceWith; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var paths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { paths.Add(LowercaseEverythingButParameters(path.Key), path.Value); } swaggerDoc.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { //var updatedPaths = new Dictionary<string, OpenApiPathItem>(); var updatePaths = new OpenApiPaths(); foreach (var entry in swaggerDoc.Paths.ToList()) { updatePaths.Add(entry.Key.Replace("v{version}", swaggerDoc.Info.Version), entry.Value); } swaggerDoc.Paths = updatePaths; }
/// <summary> /// SwaggerUi /// </summary> /// <param name="app"></param> public static void UseCustomSwaggerUI(this IApplicationBuilder app, Action <SwaggerOptions> options) { SwaggerOptions option = new SwaggerOptions(); options?.Invoke(option); //启用中间件服务生成Swagger作为JSON终结点 app.UseSwagger(c => { //c.SerializeAsV2 = true; //c.RouteTemplate = "api-docs/{documentName}/swagger.json"; c.PreSerializeFilters.Add((swaggerDoc, httpReq) => { swaggerDoc.Servers = new List <OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}" } }; OpenApiPaths paths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { //if ( path.Key.StartsWith("/v1/api") )//做版本控制 paths.Add(path.Key, path.Value); } swaggerDoc.Paths = paths; }); }); //启用中间件服务对swagger-ui,指定Swagger JSON终结点 app.UseSwaggerUI(c => { //c.MaxDisplayedTags(5); //c.DisplayOperationId();//唯一标识操作 c.SwaggerEndpoint("/swagger/v1/swagger.json", option.Title); //c.SwaggerEndpoint("/swagger/v2/swagger.json", "V2 Docs"); c.RoutePrefix = "swagger"; //根路由 c.EnableDeepLinking(); //启用深度链接--不知道干嘛的 c.DisplayRequestDuration(); //调试,显示接口响应时间 c.EnableValidator(); //验证 c.DocExpansion(DocExpansion.List); //默认展开 c.DefaultModelsExpandDepth(-1); //隐藏model c.DefaultModelExpandDepth(3); //model展开层级 c.EnableFilter(); //筛选--如果接口过多可以开启 c.DefaultModelRendering(ModelRendering.Model); //设置显示参数的实体或Example //c.SupportedSubmitMethods(SubmitMethod.Get , SubmitMethod.Head , SubmitMethod.Post);// //c.OAuthClientId("test-id"); //c.OAuthClientSecret("test-secret"); //c.OAuthRealm("test-realm"); //c.OAuthAppName("test-app"); //c.OAuthScopeSeparator(" "); //c.OAuthAdditionalQueryStringParams(new Dictionary<string, string> { { "foo", "bar" } }); //c.OAuthUseBasicAuthenticationWithAccessCodeGrant(); }); }
public void Apply(OpenApiDocument apiDoc, DocumentFilterContext context) { var paths = new OpenApiPaths(); foreach (var path in apiDoc.Paths) { var key = path.Key.Replace("v{version}", apiDoc.Info.Version); paths.Add(key, path.Value); } apiDoc.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var newPaths = new OpenApiPaths(); foreach (var swaggerDocPath in swaggerDoc.Paths) { // swaggerDoc.Info.Version gets set by c.SwaggerDoc in AddSwaggerGen newPaths.Add(swaggerDocPath.Key.Replace("v{version}", swaggerDoc.Info.Version), swaggerDocPath.Value); } swaggerDoc.Paths = newPaths; }
private OpenApiPaths GeneratePaths(IDictionary <string, OpenApiSchema> definitions) { IDictionary <string, OpenApiPathItem> paths = this.CreatePathItems(definitions); OpenApiPaths pathsObject = new OpenApiPaths(); foreach (KeyValuePair <string, OpenApiPathItem> path in paths) { pathsObject.Add(path.Key, path.Value); } return(pathsObject); }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var openAPiPaths = new OpenApiPaths(); foreach (var item in swaggerDoc.Paths) { var key = item.Key.ToLower(); openAPiPaths.Add(key, item.Value); } swaggerDoc.Paths = openAPiPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var updatedApiPaths = new OpenApiPaths(); var routeVersion = GetControllerVersion(context.ApiDescriptions); foreach (var documentedPath in swaggerDoc.Paths) { var correctedPath = documentedPath.Key.Replace("{version}", routeVersion); updatedApiPaths.Add(correctedPath, documentedPath.Value); } swaggerDoc.Paths = updatedApiPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var dictionary = swaggerDoc.Paths.ToDictionary(path => path.Key.Replace("{version}", swaggerDoc.Info.Version), path => path.Value); var openApiPaths = new OpenApiPaths(); foreach (var(key, value) in dictionary) { openApiPaths.Add(key, value); } swaggerDoc.Paths = openApiPaths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { swaggerDoc.Tags ??= new List <OpenApiTag>(); var oap = new OpenApiPaths(); foreach (var(key, value) in swaggerDoc.Paths) { oap.Add(key.Replace("v{version}", swaggerDoc.Info.Version), value); } swaggerDoc.Paths = oap; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { if (swaggerDoc == null) { throw new ArgumentNullException(nameof(swaggerDoc)); } var replacements = new OpenApiPaths(); foreach (var(key, value) in swaggerDoc.Paths) { replacements.Add(key.Replace("{version}", swaggerDoc.Info.Version, StringComparison.InvariantCulture), value); } swaggerDoc.Paths = replacements; }
public static OpenApiPaths Paths(params KeyValuePair <string, OpenApiPathItem>[] pathItems) { var paths = new OpenApiPaths(); foreach (var pathItem in pathItems) { if (!paths.ContainsKey(pathItem.Key)) { paths.Add(pathItem.Key, pathItem.Value); } } return(paths); }
/// <summary> /// Replaces the version parameter in all paths with the specific version the user is browsing. /// </summary> public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { if (swaggerDoc == null) { throw new ArgumentNullException(nameof(swaggerDoc)); } var paths = new OpenApiPaths(); foreach (var path in swaggerDoc.Paths) { paths.Add(path.Key.Replace("{version}", swaggerDoc.Info.Version, StringComparison.Ordinal), path.Value); } swaggerDoc.Paths = paths; }
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { if (swaggerDoc == null) { throw new ArgumentNullException(nameof(swaggerDoc)); } var swaggerDocPaths = new OpenApiPaths(); foreach (string key in swaggerDoc.Paths.Keys) { swaggerDocPaths.Add(key.Replace("v{version}", swaggerDoc.Info.Version, StringComparison.InvariantCultureIgnoreCase), swaggerDoc.Paths[key]); } swaggerDoc.Paths = swaggerDocPaths; }