Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Nullable support #1149

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a4590a3
First batch of fixes
maxkoshevoi Nov 29, 2021
ed33ac0
Initialize collections
maxkoshevoi Nov 29, 2021
015808a
Style fixes
maxkoshevoi Nov 29, 2021
a0a2749
Nullable batch 2
maxkoshevoi Nov 29, 2021
5154402
Merge branch 'main' into mk/nullable
shwetha-manvinkurke Dec 2, 2021
b5ce648
Added missed annotations
maxkoshevoi Dec 2, 2021
43f28e7
Update .Net SDK in pipeline
maxkoshevoi Dec 2, 2021
dde6798
Remove duplicated word
maxkoshevoi Dec 3, 2021
db89c1c
Merge branch 'main' into mk/nullable
JenniferMah Jan 5, 2022
422be17
Revert pipeline changes
maxkoshevoi Mar 23, 2022
255b68d
Revert C#9 changes
maxkoshevoi Mar 23, 2022
77cea17
Merge branch 'main' into mk/nullable
maxkoshevoi Mar 23, 2022
ccee470
Merge
maxkoshevoi Mar 23, 2022
8f4e1ed
Update SendGrid.Extensions.DependencyInjection.csproj
maxkoshevoi Mar 23, 2022
5e379a2
Revert innitializing collections in `SendGridMessage`
maxkoshevoi Mar 23, 2022
79ccc06
Revert innitializing collections in `Personalization`
maxkoshevoi Mar 23, 2022
de3e049
Update SendGridMessage.cs
maxkoshevoi Mar 23, 2022
fa6d9dc
Merge branch 'main' into mk/nullable
Mar 25, 2022
8d48348
Update annotations after merge
maxkoshevoi Mar 25, 2022
2fccfdc
Revert some changes
maxkoshevoi Mar 28, 2022
1733e77
Revert `httpErrorAsException` changes
maxkoshevoi Mar 28, 2022
2f34479
Tos are non-nullable
maxkoshevoi Apr 2, 2022
fd2b40d
Fix tests
maxkoshevoi Apr 2, 2022
7956860
Fix tests
maxkoshevoi Apr 2, 2022
63875bc
Fix tests
maxkoshevoi Apr 2, 2022
a2a84db
Fix tests
maxkoshevoi Apr 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SendGrid.Extensions.DependencyInjection
/// </summary>
internal class InjectableSendGridClient : BaseClient
{
public InjectableSendGridClient(HttpClient httpClient, IOptions<SendGridClientOptions> options)
public InjectableSendGridClient(HttpClient? httpClient, IOptions<SendGridClientOptions> options)
: base(httpClient, options.Value)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<SignAssembly>true</SignAssembly>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleset>..\SendGrid\SendGrid.ruleset</CodeAnalysisRuleset>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<LangVersion>8</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
33 changes: 16 additions & 17 deletions src/SendGrid/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class BaseClient : ISendGridClient
/// <summary>
/// The client assembly version to send in request User-Agent header.
/// </summary>
private static readonly string ClientVersion = typeof(BaseClient).GetTypeInfo().Assembly.GetName().Version.ToString();
private static readonly string ClientVersion = typeof(BaseClient).GetTypeInfo().Assembly.GetName().Version!.ToString();

/// <summary>
/// The configuration to use with current client instance.
Expand All @@ -47,7 +47,7 @@ public abstract class BaseClient : ISendGridClient
/// </summary>
/// <param name="options">A <see cref="BaseClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
protected BaseClient(BaseClientOptions options)
protected BaseClient(BaseClientOptions? options)
: this(httpClient: null, options)
{
}
Expand All @@ -58,7 +58,7 @@ protected BaseClient(BaseClientOptions options)
/// <param name="webProxy">Web proxy.</param>
/// <param name="options">A <see cref="BaseClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
protected BaseClient(IWebProxy webProxy, BaseClientOptions options)
protected BaseClient(IWebProxy? webProxy, BaseClientOptions options)
: this(CreateHttpClientWithWebProxy(webProxy, options), options)
{
}
Expand All @@ -69,7 +69,7 @@ protected BaseClient(IWebProxy webProxy, BaseClientOptions options)
/// <param name="httpClient">An optional HTTP client which may me injected in order to facilitate testing.</param>
/// <param name="options">A <see cref="BaseClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
protected BaseClient(HttpClient httpClient, BaseClientOptions options)
protected BaseClient(HttpClient? httpClient, BaseClientOptions? options)
{
this.options = options ?? throw new ArgumentNullException(nameof(options));

Expand Down Expand Up @@ -123,7 +123,7 @@ public string UrlPath
/// <summary>
/// The API version.
/// </summary>
public string Version
public string? Version
{
get => this.options.Version;
set => this.options.Version = value;
Expand Down Expand Up @@ -151,7 +151,7 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair<string, s
/// <param name="request">The parameters for the API call.</param>
/// <param name="cancellationToken">Cancel the asynchronous call.</param>
/// <returns>Response object.</returns>
public virtual async Task<Response> MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<Response> MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default)
{
HttpResponseMessage response = await this.client.SendAsync(request, cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -182,10 +182,10 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair<string, s
/// In particular, this means that you may expect a TimeoutException if you are not connected to the Internet.</exception>
public async Task<Response> RequestAsync(
SendGridClient.Method method,
string requestBody = null,
string queryParams = null,
string urlPath = null,
CancellationToken cancellationToken = default(CancellationToken))
string? requestBody = null,
string? queryParams = null,
string? urlPath = null,
CancellationToken cancellationToken = default)
{
var baseAddress = new Uri(this.options.Host);
if (!baseAddress.OriginalString.EndsWith("/"))
Expand All @@ -204,7 +204,7 @@ public async Task<Response> RequestAsync(
// Drop the default UTF-8 content type charset for JSON payloads since some APIs may not accept it.
if (request.Content != null && this.MediaType == DefaultMediaType)
{
request.Content.Headers.ContentType.CharSet = null;
request.Content.Headers.ContentType!.CharSet = null;
}

// set header overrides
Expand All @@ -229,7 +229,7 @@ public async Task<Response> RequestAsync(
/// <param name="msg">A SendGridMessage object with the details for the request.</param>
/// <param name="cancellationToken">Cancel the asynchronous call.</param>
/// <returns>A Response object.</returns>
public async Task<Response> SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default(CancellationToken))
public async Task<Response> SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default)
{
return await this.RequestAsync(
Method.POST,
Expand All @@ -249,7 +249,7 @@ private static HttpClient CreateHttpClientWithRetryHandler(BaseClientOptions opt
/// <param name="webProxy">the WebProxy.</param>
/// <param name="options">A <see cref="BaseClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>HttpClient with RetryDelegatingHandler and WebProxy if set.</returns>
private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy, BaseClientOptions options)
private static HttpClient CreateHttpClientWithWebProxy(IWebProxy? webProxy, BaseClientOptions options)
{
if (webProxy != null)
{
Expand All @@ -276,13 +276,12 @@ private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy, BaseC
/// <param name="urlPath">The URL path.</param>
/// <param name="queryParams">A string of JSON formatted query parameters (e.g. {'param': 'param_value'}).</param>
/// <returns>Final URL.</returns>
private string BuildUrl(string urlPath, string queryParams = null)
private string BuildUrl(string? urlPath, string? queryParams = null)
{
string url = null;

// create urlPAth - from parameter if overridden on call or from constructor parameter
var urlpath = urlPath ?? this.options.UrlPath;

string url;
if (this.options.Version != null)
{
url = this.options.Version + "/" + urlpath;
Expand Down Expand Up @@ -338,7 +337,7 @@ private Dictionary<string, List<object>> ParseJson(string json)
{
case JsonToken.PropertyName:
{
propertyName = reader.Value.ToString();
propertyName = reader.Value.ToString()!;
if (!dict.ContainsKey(propertyName))
{
dict.Add(propertyName, new List<object>());
Expand Down
8 changes: 4 additions & 4 deletions src/SendGrid/BaseClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public ReliabilitySettings ReliabilitySettings
/// <summary>
/// The base URL.
/// </summary>
public string Host { get; set; }
public string Host { get; set; } = string.Empty;

/// <summary>
/// The API version (defaults to "v3").
/// </summary>
public string Version { get; set; } = "v3";
public string? Version { get; set; } = "v3";

/// <summary>
/// The path to the API endpoint.
/// </summary>
public string UrlPath { get; set; }
public string UrlPath { get; set; } = string.Empty;

/// <summary>
/// The Auth header value.
/// </summary>
public AuthenticationHeaderValue Auth { get; set; }
public AuthenticationHeaderValue? Auth { get; set; }

/// <summary>
/// Gets or sets a value indicating whether HTTP error responses should be raised as exceptions. Default is false.
Expand Down
6 changes: 3 additions & 3 deletions src/SendGrid/Helpers/Errors/ErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private static async Task<string> GetErrorMessage(HttpResponseMessage message)
var errorStatusCode = (int)message.StatusCode;
var errorReasonPhrase = message.ReasonPhrase;

string errorValue = null;
string fieldValue = null;
string helpValue = null;
string? errorValue = null;
string? fieldValue = null;
string? helpValue = null;

if (message.Content != null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public class SendGridErrorResponse
/// <summary>
/// Gets or sets the error Reason Phrase
/// </summary>
public string ErrorReasonPhrase { get; set; }
public string? ErrorReasonPhrase { get; set; }

/// <summary>
/// Gets or sets the SendGrid error message
/// </summary>
public string SendGridErrorMessage { get; set; }
public string? SendGridErrorMessage { get; set; }

/// <summary>
/// Gets or sets the field that has the error
/// </summary>
public string FieldWithError { get; set; }
public string? FieldWithError { get; set; }

/// <summary>
/// Gets or sets the error default help
/// </summary>
public string HelpLink { get; set; }
public string? HelpLink { get; set; }
}
}
Loading