@@ -15,10 +15,6 @@ public static string GenerateAuthorization(
1515 }
1616 if ( authorization . Type is SecuritySchemeType . OAuth2 )
1717 {
18- var jsonSerializerContext = ! string . IsNullOrWhiteSpace ( authorization . Settings . JsonSerializerContext )
19- ? $ ", global::{ authorization . Settings . JsonSerializerContext } .Default.DictionaryStringString"
20- : string . Empty ;
21-
2218 return $@ "
2319#nullable enable
2420
@@ -56,7 +52,9 @@ public sealed partial class {authorization.Settings.ClassName}
5652 response.EnsureSuccessStatusCode();
5753
5854 var json = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
59- var dictionary = global::System.Text.Json.JsonSerializer.Deserialize<global::System.Collections.Generic.Dictionary<string, string>>(json{ jsonSerializerContext } ) ??
55+ var dictionary = global::System.Text.Json.JsonSerializer.Deserialize<global::System.Collections.Generic.Dictionary<string, string>>(json{ ( ! string . IsNullOrWhiteSpace ( authorization . Settings . JsonSerializerContext )
56+ ? $ ", global::{ authorization . Settings . JsonSerializerContext } .Default.DictionaryStringString"
57+ : string . Empty ) } ) ??
6058 throw new global::System.InvalidOperationException(""Deserialization failed."");
6159
6260 var accessToken = dictionary[""access_token""];
@@ -77,29 +75,6 @@ public sealed partial class {authorization.Settings.ClassName}
7775}}" . RemoveBlankLinesWhereOnlyWhitespaces ( ) ;
7876 }
7977
80- var name = ( authorization . Type , authorization . Scheme , authorization . In ) switch
81- {
82- ( SecuritySchemeType . Http , "bearer" , _ ) => "Bearer" ,
83- ( SecuritySchemeType . Http , "basic" , _ ) => "Basic" ,
84- ( SecuritySchemeType . ApiKey , _ , _ ) => authorization . Name ,
85- _ => string . Empty ,
86- } ;
87- var value = ( authorization . Type , authorization . Scheme , authorization . In ) switch
88- {
89- ( SecuritySchemeType . Http , "bearer" , _ ) => "apiKey" ,
90- ( SecuritySchemeType . Http , "basic" , _ ) => @"global::System.Convert.ToBase64String(
91- global::System.Text.Encoding.UTF8.GetBytes($""{username}:{password}""))" ,
92- ( SecuritySchemeType . ApiKey , _ , _ ) => "apiKey" ,
93- _ => string . Empty ,
94- } ;
95- var xmlDocs = ( authorization . Type , authorization . Scheme , authorization . In ) switch
96- {
97- ( SecuritySchemeType . Http , "bearer" , _ ) => "Authorize using bearer authentication." ,
98- ( SecuritySchemeType . Http , "basic" , _ ) => "Authorize using basic authentication." ,
99- ( SecuritySchemeType . ApiKey , _ , _ ) => "Authorize using ApiKey authentication." ,
100- _ => string . Empty ,
101- } ;
102-
10378 return $@ "
10479#nullable enable
10580
@@ -108,7 +83,13 @@ namespace {authorization.Settings.Namespace}
10883 public sealed partial class { authorization . Settings . ClassName }
10984 {{
11085 /// <summary>
111- /// { xmlDocs }
86+ /// { ( authorization . Type , authorization . Scheme . ToUpperInvariant ( ) , authorization . In ) switch
87+ {
88+ ( SecuritySchemeType . Http , "BEARER" , _ ) => "Authorize using bearer authentication." ,
89+ ( SecuritySchemeType . Http , "BASIC" , _ ) => "Authorize using basic authentication." ,
90+ ( SecuritySchemeType . ApiKey , _ , _ ) => "Authorize using ApiKey authentication." ,
91+ _ => string . Empty ,
92+ } }
11293 /// </summary>
11394{ authorization . Parameters . Select ( x => $@ "
11495 /// <param name=""{ x } ""></param>" ) . Inject ( ) }
@@ -124,8 +105,21 @@ public sealed partial class {authorization.Settings.ClassName}
124105 {{
125106 Type = ""{ authorization . Type : G} "",
126107 Location = ""{ authorization . In : G} "",
127- Name = ""{ name } "",
128- Value = { value } ,
108+ Name = ""{ ( authorization . Type , authorization . Scheme . ToUpperInvariant ( ) , authorization . In ) switch
109+ {
110+ ( SecuritySchemeType . Http , "BEARER" , _ ) => "Bearer" ,
111+ ( SecuritySchemeType . Http , "BASIC" , _ ) => "Basic" ,
112+ ( SecuritySchemeType . ApiKey , _ , _ ) => authorization . Name ,
113+ _ => string . Empty ,
114+ } } "",
115+ Value = { ( authorization . Type , authorization . Scheme . ToUpperInvariant ( ) , authorization . In ) switch
116+ {
117+ ( SecuritySchemeType . Http , "BEARER" , _ ) => "apiKey" ,
118+ ( SecuritySchemeType . Http , "BASIC" , _ ) => @"global::System.Convert.ToBase64String(
119+ global::System.Text.Encoding.UTF8.GetBytes($""{username}:{password}""))" ,
120+ ( SecuritySchemeType . ApiKey , _ , _ ) => "apiKey" ,
121+ _ => "\" \" " ,
122+ } } ,
129123 }});
130124 }}
131125 }}
0 commit comments