Skip to content

Commit 2d35869

Browse files
committed
Refactor security scheme naming in AuthDocumentTransformer
Updated the naming convention for security schemes in the `AuthenticationDocumentTransformer` class. The new format appends a suffix to the scheme name (e.g., "-Header" and "-QueryString") instead of using descriptive phrases. This change enhances consistency and clarity in the generated documentation for both header and query string security schemes. Refactor security scheme naming in OpenAPI document This update changes the naming convention for security schemes added to the OpenAPI document. Instead of descriptive strings that include the scheme name and location, the new implementation appends a suffix to the scheme name (e.g., `"{settings.SchemeName}-Header"` for headers and `"{settings.SchemeName}-QueryString"` for query strings). This improves consistency, clarity, and maintainability of the security scheme definitions.
1 parent 51e6709 commit 2d35869

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ static void CheckAddApiKey(OpenApiDocument document, IConfigurationSection secti
5353

5454
if (!string.IsNullOrWhiteSpace(settings.HeaderName))
5555
{
56-
AddSecurityScheme(document, $"{settings.SchemeName} in Header", SecuritySchemeType.ApiKey, null, ParameterLocation.Header, settings.HeaderName, "Insert the API Key");
57-
AddSecurityRequirement(document, $"{settings.SchemeName} in Header");
56+
var schemeName = $"{settings.SchemeName}-Header";
57+
58+
AddSecurityScheme(document, schemeName, SecuritySchemeType.ApiKey, null, ParameterLocation.Header, settings.HeaderName, "Insert the API Key");
59+
AddSecurityRequirement(document, schemeName);
5860
}
5961

6062
if (!string.IsNullOrWhiteSpace(settings.QueryStringKey))
6163
{
62-
AddSecurityScheme(document, $"{settings.SchemeName} in Query String", SecuritySchemeType.ApiKey, null, ParameterLocation.Query, settings.QueryStringKey, "Insert the API Key");
63-
AddSecurityRequirement(document, $"{settings.SchemeName} in Query String");
64+
var schemeName = $"{settings.SchemeName}-QueryString";
65+
66+
AddSecurityScheme(document, schemeName, SecuritySchemeType.ApiKey, null, ParameterLocation.Query, settings.QueryStringKey, "Insert the API Key");
67+
AddSecurityRequirement(document, schemeName);
6468
}
6569
}
6670

0 commit comments

Comments
 (0)