Skip to content

Commit 4f8fe87

Browse files
committed
chore: additional NRT fixes
Signed-off-by: Vincent Biret <[email protected]>
1 parent 3737e0b commit 4f8fe87

23 files changed

+83
-83
lines changed

src/Microsoft.OpenApi.OData.Reader/EdmModelOpenApiExtensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
55

6+
using System.Collections.Generic;
67
using Microsoft.OData.Edm;
78
using Microsoft.OData.Edm.Validation;
89
using Microsoft.OpenApi.Any;
10+
using Microsoft.OpenApi.Interfaces;
911
using Microsoft.OpenApi.Models;
1012
using Microsoft.OpenApi.OData.Common;
1113
using Microsoft.OpenApi.OData.Edm;
@@ -39,22 +41,20 @@ public static OpenApiDocument ConvertToOpenApi(this IEdmModel model, OpenApiConv
3941
Utils.CheckArgumentNull(model, nameof(model));
4042
Utils.CheckArgumentNull(settings, nameof(settings));
4143

42-
if (settings.VerifyEdmModel)
43-
{
44-
if (!model.Validate(out var errors))
44+
if (settings.VerifyEdmModel && !model.Validate(out var errors))
45+
{
46+
OpenApiDocument document = new();
47+
int index = 1;
48+
document.Extensions ??= new Dictionary<string, IOpenApiExtension>();
49+
foreach (var error in errors)
4550
{
46-
OpenApiDocument document = new();
47-
int index = 1;
48-
foreach (var error in errors)
49-
{
50-
document.Extensions.Add(Constants.xMsEdmModelError + index++, new OpenApiAny(error.ToString()));
51-
}
52-
53-
return document;
51+
document.Extensions.Add(Constants.xMsEdmModelError + index++, new OpenApiAny(error.ToString()));
5452
}
53+
54+
return document;
5555
}
5656

57-
ODataContext context = new(model, settings);
57+
ODataContext context = new(model, settings);
5858
return context.CreateDocument();
5959
}
6060
}

src/Microsoft.OpenApi.OData.Reader/Extensions/IODataRoutePathPrefixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public interface IODataRoutePathPrefixProvider
1616
/// <summary>
1717
/// The route prefix.
1818
/// </summary>
19-
public string PathPrefix { get; }
19+
public string? PathPrefix { get; }
2020

2121
/// <summary>
2222
/// The route prefix parameters.
2323
/// </summary>
24-
public IEnumerable<OpenApiParameter> Parameters { get; }
24+
public IEnumerable<OpenApiParameter>? Parameters { get; }
2525
}
2626
}

src/Microsoft.OpenApi.OData.Reader/Extensions/ODataRoutePathPrefixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public class ODataRoutePathPrefixProvider : IODataRoutePathPrefixProvider
1616
/// <summary>
1717
/// Gets/sets the path prefix.
1818
/// </summary>
19-
public string PathPrefix { get; set; }
19+
public string? PathPrefix { get; set; }
2020

2121
/// <summary>
2222
/// Gets/sets the associated parameters for the path prefix.
2323
/// </summary>
24-
public IEnumerable<OpenApiParameter> Parameters { get; set; }
24+
public IEnumerable<OpenApiParameter>? Parameters { get; set; }
2525
}
2626
}

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSecuritySchemeGenerator.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// ------------------------------------------------------------
55

66
using System;
7-
using System.Collections.Generic;
87
using System.Diagnostics;
98
using System.Linq;
109
using Microsoft.OpenApi.Models;
@@ -37,6 +36,10 @@ public static void AddSecuritySchemesToDocument(this ODataContext context, OpenA
3736

3837
foreach (var authorization in authorizations)
3938
{
39+
if (string.IsNullOrEmpty(authorization.Name))
40+
{
41+
continue;
42+
}
4043
OpenApiSecurityScheme scheme = new OpenApiSecurityScheme
4144
{
4245
Type = authorization.SchemeType,
@@ -104,7 +107,8 @@ private static void AppendOpenIdConnect(OpenApiSecurityScheme scheme, OpenIDConn
104107
Debug.Assert(scheme != null);
105108
Debug.Assert(openIdConnect != null);
106109

107-
scheme.OpenIdConnectUrl = new Uri(openIdConnect.IssuerUrl);
110+
if (!string.IsNullOrEmpty(openIdConnect.IssuerUrl))
111+
scheme.OpenIdConnectUrl = new Uri(openIdConnect.IssuerUrl);
108112
}
109113

110114
private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorization oAuth2)
@@ -113,11 +117,11 @@ private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorizatio
113117
Debug.Assert(oAuth2 != null);
114118

115119
scheme.Flows = new OpenApiOAuthFlows();
116-
OpenApiOAuthFlow flow = null;
120+
OpenApiOAuthFlow? flow = null;
117121
switch (oAuth2.OAuth2Type)
118122
{
119-
case OAuth2Type.AuthCode: // AuthCode
120-
OAuth2AuthCode authCode = (OAuth2AuthCode)oAuth2;
123+
case OAuth2Type.AuthCode when oAuth2 is OAuth2AuthCode {AuthorizationUrl: not null, TokenUrl: not null} authCode:
124+
// AuthCode
121125
flow = new OpenApiOAuthFlow
122126
{
123127
AuthorizationUrl = new Uri(authCode.AuthorizationUrl),
@@ -126,7 +130,7 @@ private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorizatio
126130
scheme.Flows.AuthorizationCode = flow;
127131
break;
128132

129-
case OAuth2Type.Pasword: // Password
133+
case OAuth2Type.Password: // Password
130134
OAuth2Password password = (OAuth2Password)oAuth2;
131135
flow = new OpenApiOAuthFlow
132136
{
@@ -135,17 +139,17 @@ private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorizatio
135139
scheme.Flows.Password = flow;
136140
break;
137141

138-
case OAuth2Type.Implicit: // Implicit
139-
OAuth2Implicit @implicit = (OAuth2Implicit)oAuth2;
142+
case OAuth2Type.Implicit when oAuth2 is OAuth2Implicit {AuthorizationUrl: not null} @implicit:
143+
// Implicit
140144
flow = new OpenApiOAuthFlow
141145
{
142146
AuthorizationUrl = new Uri(@implicit.AuthorizationUrl)
143147
};
144148
scheme.Flows.Implicit = flow;
145149
break;
146150

147-
case OAuth2Type.ClientCredentials: // ClientCredentials
148-
OAuth2ClientCredentials credentials = (OAuth2ClientCredentials)oAuth2;
151+
case OAuth2Type.ClientCredentials when oAuth2 is OAuth2ClientCredentials {TokenUrl: not null} credentials:
152+
// ClientCredentials
149153
flow = new OpenApiOAuthFlow
150154
{
151155
TokenUrl = new Uri(credentials.TokenUrl)
@@ -155,11 +159,14 @@ private static void AppendOAuth2(OpenApiSecurityScheme scheme, OAuthAuthorizatio
155159
}
156160

157161
Debug.Assert(flow != null);
158-
flow.RefreshUrl = new Uri(oAuth2.RefreshUrl);
162+
if (!string.IsNullOrEmpty(oAuth2.RefreshUrl))
163+
flow.RefreshUrl = new Uri(oAuth2.RefreshUrl);
159164

160165
if (oAuth2.Scopes != null)
161166
{
162-
flow.Scopes = oAuth2.Scopes.ToDictionary(s => s.Scope, s => s.Description);
167+
flow.Scopes = oAuth2.Scopes
168+
.Where(static x => !string.IsNullOrEmpty(x.Scope) && !string.IsNullOrEmpty(x.Description))
169+
.ToDictionary(s => s.Scope!, s => s.Description!);
163170
}
164171
}
165172
}

src/Microsoft.OpenApi.OData.Reader/OData/ODataResourceValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ internal class ODataResourceValue : ODataValue
1515
/// <summary>
1616
/// Gets or sets the properties.
1717
/// </summary>
18-
public IDictionary<string, ODataValue> Properties { get; set; }
18+
public IDictionary<string, ODataValue>? Properties { get; set; }
1919
}
2020
}

src/Microsoft.OpenApi.OData.Reader/OData/ODataValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ internal abstract class ODataValue
1515
/// <summary>
1616
/// Gets or set the type reference of this value.
1717
/// </summary>
18-
public IEdmTypeReference TypeReference { get; set; }
18+
public IEdmTypeReference? TypeReference { get; set; }
1919
}
2020
}

src/Microsoft.OpenApi.OData.Reader/PathItem/MediaEntityPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public MediaEntityPathItemHandler(OpenApiDocument document) : base(document)
4040
/// <inheritdoc/>
4141
protected override void SetOperations(OpenApiPathItem item)
4242
{
43-
var readRestrictions = Context.Model.GetRecord<ReadRestrictionsType>(TargetPath, CapabilitiesConstants.ReadRestrictions);
43+
var readRestrictions = Context?.Model.GetRecord<ReadRestrictionsType>(TargetPath, CapabilitiesConstants.ReadRestrictions);
4444
var navSourceReadRestrictions = EntitySet != null
4545
? Context.Model.GetRecord<ReadRestrictionsType>(EntitySet)
4646
: (Singleton is null ? null : Context.Model.GetRecord<ReadRestrictionsType>(Singleton));

src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.ODataTypeCastSegment(Microsoft.
103103
Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.StructuredType.get -> Microsoft.OData.Edm.IEdmStructuredType!
104104
Microsoft.OpenApi.OData.EdmModelOpenApiExtensions
105105
Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider
106-
Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OpenApi.Models.OpenApiParameter!>!
107-
Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.PathPrefix.get -> string!
106+
Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OpenApi.Models.OpenApiParameter!>?
107+
Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.PathPrefix.get -> string?
108108
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider
109109
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.ODataRoutePathPrefixProvider() -> void
110-
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OpenApi.Models.OpenApiParameter!>!
110+
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable<Microsoft.OpenApi.Models.OpenApiParameter!>?
111111
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.Parameters.set -> void
112-
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.PathPrefix.get -> string!
112+
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.PathPrefix.get -> string?
113113
Microsoft.OpenApi.OData.Extensions.ODataRoutePathPrefixProvider.PathPrefix.set -> void
114114
Microsoft.OpenApi.OData.OpenApiConvertSettings
115115
Microsoft.OpenApi.OData.OpenApiConvertSettings.AddAlternateKeyPaths.get -> bool

src/Microsoft.OpenApi.OData.Reader/Vocabulary/Authorization/ApiKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal class ApiKey : Authorization
3838
/// <summary>
3939
/// The name of the header or query parameter.
4040
/// </summary>
41-
public string KeyName { get; set; }
41+
public string? KeyName { get; set; }
4242

4343
/// <summary>
4444
/// Whether the API Key is passed in the header or as a query option.

src/Microsoft.OpenApi.OData.Reader/Vocabulary/Authorization/OAuth2Password.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ internal class OAuth2Password : OAuthAuthorization
1616
/// <summary>
1717
/// Token Url.
1818
/// </summary>
19-
public string TokenUrl { get; set; }
19+
public string? TokenUrl { get; set; }
2020

2121
/// <summary>
2222
/// Gets the OAuth2 type.
2323
/// </summary>
24-
public override OAuth2Type OAuth2Type => OAuth2Type.Pasword;
24+
public override OAuth2Type OAuth2Type => OAuth2Type.Password;
2525

2626
/// <summary>
2727
/// Init <see cref="OAuth2Password"/>.

0 commit comments

Comments
 (0)