Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6d183d

Browse files
committed
Simplify and centralize swagger config
1 parent8a6a42a commitb6d183d

File tree

3 files changed

+35
-58
lines changed

3 files changed

+35
-58
lines changed

‎src/Api/Startup.cs‎

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -299,49 +299,6 @@ public void Configure(
299299
app.UseSwagger(config=>
300300
{
301301
config.RouteTemplate="specs/{documentName}/swagger.json";
302-
303-
// Remove all Bitwarden cloud servers and only register the local server
304-
config.PreSerializeFilters.Add((swaggerDoc,httpReq)=>
305-
{
306-
swaggerDoc.Servers.Clear();
307-
swaggerDoc.Servers.Add(newOpenApiServer
308-
{
309-
Url=globalSettings.BaseServiceUri.Api,
310-
});
311-
312-
swaggerDoc.Components.SecuritySchemes.Clear();
313-
swaggerDoc.Components.SecuritySchemes.Add("oauth2-client-credentials",newOpenApiSecurityScheme
314-
{
315-
Type=SecuritySchemeType.OAuth2,
316-
Flows=newOpenApiOAuthFlows
317-
{
318-
ClientCredentials=newOpenApiOAuthFlow
319-
{
320-
TokenUrl=newUri($"{globalSettings.BaseServiceUri.Identity}/connect/token"),
321-
Scopes=newDictionary<string,string>
322-
{
323-
{ApiScopes.ApiOrganization,"Organization APIs"}
324-
}
325-
}
326-
}
327-
});
328-
329-
swaggerDoc.SecurityRequirements.Clear();
330-
swaggerDoc.SecurityRequirements.Add(newOpenApiSecurityRequirement
331-
{
332-
{
333-
newOpenApiSecurityScheme
334-
{
335-
Reference=newOpenApiReference
336-
{
337-
Type=ReferenceType.SecurityScheme,
338-
Id="oauth2-client-credentials"
339-
}
340-
},
341-
[ApiScopes.ApiOrganization]
342-
}
343-
});
344-
});
345302
});
346303

347304
// adds the middleware to display the web UI

‎src/Api/Utilities/ServiceCollectionExtensions.cs‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,40 @@ [this document](https://bitwarden.com/help/vault-management-api/).
5151

5252
config.SwaggerDoc("internal",newOpenApiInfo{Title="Bitwarden Internal API",Version="latest"});
5353

54-
// Configure Bitwarden cloud US and EU servers. These will appear in the swagger.json build artifact
55-
// used for our help center. These are overwritten with the local server when running in self-hosted
56-
// or dev mode (see Api Startup.cs).
57-
config.AddSwaggerServerWithSecurity(
58-
serverId:"US_server",
59-
serverUrl:"https://api.bitwarden.com",
60-
identityTokenUrl:"https://identity.bitwarden.com/connect/token",
61-
serverDescription:"US server");
62-
63-
config.AddSwaggerServerWithSecurity(
64-
serverId:"EU_server",
65-
serverUrl:"https://api.bitwarden.eu",
66-
identityTokenUrl:"https://identity.bitwarden.eu/connect/token",
67-
serverDescription:"EU server");
54+
if(environment.IsDevelopment())
55+
{
56+
// Generate swagger for development servers
57+
config.AddSwaggerServerWithSecurity(
58+
serverId:"Development_server",
59+
serverUrl:globalSettings.BaseServiceUri.Api,
60+
identityTokenUrl:$"{globalSettings.BaseServiceUri.Identity}/connect/token",
61+
serverDescription:"Development server");
62+
}
63+
elseif(globalSettings.SelfHosted)
64+
{
65+
// Generate swagger for self-hosted servers
66+
config.AddSwaggerServerWithSecurity(
67+
serverId:"Self_hosted_server",
68+
serverUrl:globalSettings.BaseServiceUri.Api,
69+
identityTokenUrl:$"{globalSettings.BaseServiceUri.Identity}/connect/token",
70+
serverDescription:"Self-hosted server");
71+
}
72+
else
73+
{
74+
// Configure swagger for Bitwarden cloud servers. These will appear in the swagger.json build artifact
75+
// used for our help center.
76+
config.AddSwaggerServerWithSecurity(
77+
serverId:"US_server",
78+
serverUrl:"https://api.bitwarden.com",
79+
identityTokenUrl:"https://identity.bitwarden.com/connect/token",
80+
serverDescription:"US server");
81+
82+
config.AddSwaggerServerWithSecurity(
83+
serverId:"EU_server",
84+
serverUrl:"https://api.bitwarden.eu",
85+
identityTokenUrl:"https://identity.bitwarden.eu/connect/token",
86+
serverDescription:"EU server");
87+
}
6888

6989
config.DescribeAllParametersInCamelCase();
7090
// config.UseReferencedDefinitionsForEnums();

‎src/SharedWeb/Utilities/ServiceCollectionExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ private static bool IsRabbitMqEnabled(GlobalSettings settings)
10741074
/// Adds a server with its corresponding OAuth2 client credentials security definition and requirement.
10751075
/// </summary>
10761076
/// <param name="config">The SwaggerGen configuration</param>
1077-
/// <param name="serverId">Unique identifier for this server (e.g., "us-server", "eu-server")</param>
1077+
/// <param name="serverId">Unique identifier for this server, without spaces (e.g., "us-server", "eu-server")</param>
10781078
/// <param name="serverUrl">The API server URL</param>
10791079
/// <param name="identityTokenUrl">The identity server token URL</param>
10801080
/// <param name="serverDescription">Human-readable description for the server</param>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp