You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest adding the [it self gateway first definition] property to ensure that Gateway is the first definition in the list. Full code implementation in the comments, thanks!
usingMicrosoft.OpenApi.Models;usingMMLib.SwaggerForOcelot.Aggregates;usingSystem;usingSystem.Collections.Generic;namespaceMMLib.SwaggerForOcelot.Configuration{/// <summary>/// Options for generating docs of ApiGateway./// </summary>publicclassOcelotSwaggerGenOptions{/// <summary>/// Gets or sets a value indicating whether [generate docs for aggregates]./// </summary>/// <value>/// <c>true</c> if [generate docs for aggregates]; otherwise, <c>false</c>./// </value>publicboolGenerateDocsForAggregates{get;set;}=false;/// <summary>/// Gets or sets a value indicating whether [generate docs for gateway it self]./// </summary>/// <value>/// <c>true</c> if [generate docs for gateway it self]; otherwise, <c>false</c>./// </value>publicboolGenerateDocsForGatewayItSelf{get;set;}=false;/// <summary>/// Gets or sets a value indicating whether [it self gateway first definition]./// </summary>/// <value>/// <c>true</c> if [it self gateway first definition]; otherwise, <c>false</c>./// </value>publicboolIsItSelfGatewayFirstDefinition{get;set;}=false;/// <summary>/// Gets or sets a value indicating downstream docs cache expire duration in seconds./// </summary>/// <value>/// <c>0</c> if it won't be cached; otherwise, cache expire duration in seconds./// </value>publicTimeSpanDownstreamDocsCacheExpire{get;set;}=TimeSpan.Zero;/// <summary>/// Generates docs for gateway it self with options./// </summary>/// <param name="options">Gateway itself docs generation options.</param>publicvoidGenerateDocsDocsForGatewayItSelf(Action<OcelotGatewayItSelfSwaggerGenOptions>options=null){GenerateDocsForGatewayItSelf=true;OcelotGatewayItSelfSwaggerGenOptions=newOcelotGatewayItSelfSwaggerGenOptions();options?.Invoke(OcelotGatewayItSelfSwaggerGenOptions);GatewayDocsTitle=OcelotGatewayItSelfSwaggerGenOptions.GatewayDocsTitle??GatewayDocsTitle;GatewayDocsOpenApiInfo=OcelotGatewayItSelfSwaggerGenOptions.GatewayDocsOpenApiInfo??GatewayDocsOpenApiInfo;}/// <summary>/// Adds a mapping between Ocelot's AuthenticationProviderKey and Swagger's securityScheme/// If a route has a match, security definition will be added to the endpoint with the provided AllowedScopes from the config./// </summary>/// <param name="authenticationProviderKey"></param>/// <param name="securityScheme"></param>publicvoidAddAuthenticationProviderKeyMapping(stringauthenticationProviderKey,stringsecurityScheme){AuthenticationProviderKeyMap.Add(authenticationProviderKey,securityScheme);}/// <summary>/// Register aggregate docs generator post process./// </summary>publicAction<SwaggerAggregateRoute,IEnumerable<RouteDocs>,OpenApiPathItem,OpenApiDocument>AggregateDocsGeneratorPostProcess{get;set;}=AggregateRouteDocumentationGenerator.DefaultPostProcess;internalstaticOcelotSwaggerGenOptionsDefault{get;}=newOcelotSwaggerGenOptions();internalconststringAggregatesKey="aggregates";internalconststringGatewayKey="gateway";internalstringGatewayDocsTitle{get;set;}="Gateway";internalOpenApiInfoGatewayDocsOpenApiInfo{get;set;}=new(){Title="Gateway",Version=GatewayKey,};internalOcelotGatewayItSelfSwaggerGenOptionsOcelotGatewayItSelfSwaggerGenOptions{get;privateset;}internalDictionary<string,string>AuthenticationProviderKeyMap{get;}=new();}}
usingKros.Utils;usingMicrosoft.Extensions.Options;usingMMLib.SwaggerForOcelot.Configuration;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespaceMMLib.SwaggerForOcelot.Repositories{/// <summary>/// Provider for obtaining <see cref="SwaggerEndPointOptions"/>./// </summary>publicclassSwaggerEndPointProvider:ISwaggerEndPointProvider{privatereadonlyLazy<Dictionary<string,SwaggerEndPointOptions>>_swaggerEndPoints;privatereadonlyIOptionsMonitor<List<SwaggerEndPointOptions>>_swaggerEndPointsOptions;privatereadonlyOcelotSwaggerGenOptions_options;/// <summary>/// Initializes a new instance of the <see cref="SwaggerEndPointProvider"/> class./// </summary>/// <param name="swaggerEndPoints">The swagger end points.</param>publicSwaggerEndPointProvider(IOptionsMonitor<List<SwaggerEndPointOptions>>swaggerEndPoints,OcelotSwaggerGenOptionsoptions){_swaggerEndPointsOptions=Check.NotNull(swaggerEndPoints,nameof(swaggerEndPoints));_swaggerEndPoints=newLazy<Dictionary<string,SwaggerEndPointOptions>>(Init);_options=options;}/// <inheritdoc/>publicIReadOnlyList<SwaggerEndPointOptions>GetAll()=>_swaggerEndPoints.Value.Values.ToList();/// <inheritdoc/>publicSwaggerEndPointOptionsGetByKey(stringkey)=>_swaggerEndPoints.Value[$"/{key}"];privateDictionary<string,SwaggerEndPointOptions>Init(){varret=_swaggerEndPointsOptions.CurrentValue.Select(p =>KeyValuePair.Create($"/{p.KeyToPath}",p));if(_options.GenerateDocsForAggregates){ret=ret.Append(AddEndpoint(OcelotSwaggerGenOptions.AggregatesKey,"Aggregates"));}if(_options.GenerateDocsForGatewayItSelf){vargateway=AddEndpoint(OcelotSwaggerGenOptions.GatewayKey,_options.GatewayDocsTitle);ret=_options.IsItSelfGatewayFirstDefinition?ret.Prepend(gateway):ret.Append(gateway);}returnret.ToDictionary(x =>x.Key, x =>x.Value);}privatestaticKeyValuePair<string,SwaggerEndPointOptions>AddEndpoint(stringkey,stringdescription)=>KeyValuePair.Create($"/{key}",newSwaggerEndPointOptions(){Key=key,TransformByOcelotConfig=false,Config=newList<SwaggerEndPointConfig>(){newSwaggerEndPointConfig(){Name=description,Version=key,Url=""}}});}}
The text was updated successfully, but these errors were encountered:
Hello there,
I suggest adding the [it self gateway first definition] property to ensure that Gateway is the first definition in the list. Full code implementation in the comments, thanks!
The text was updated successfully, but these errors were encountered: