Skip to content

Commit

Permalink
Add IDE support for route syntax highlighting and fix some nullabilit…
Browse files Browse the repository at this point in the history
…y warnings.
  • Loading branch information
Hawxy authored and jeremydmiller committed Mar 21, 2024
1 parent 66750b4 commit 582983d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/Http/Wolverine.Http/HttpChain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -328,7 +329,7 @@ private void applyMetadata()
return variable;
}

public bool FindRouteVariable(ParameterInfo parameter, out Variable variable)
public bool FindRouteVariable(ParameterInfo parameter, [NotNullWhen(true)]out Variable? variable)
{
var existing = _routeVariables.FirstOrDefault(x =>
x.VariableType == parameter.ParameterType && x.Usage.EqualsIgnoreCase(parameter.Name));
Expand Down Expand Up @@ -357,11 +358,11 @@ public bool FindRouteVariable(ParameterInfo parameter, out Variable variable)
}
}

variable = default!;
variable = default;
return false;
}

public bool FindRouteVariable(Type variableType, string routeOrParameterName, out Variable variable)
public bool FindRouteVariable(Type variableType, string routeOrParameterName, [NotNullWhen(true)]out Variable? variable)
{
var matched =
_routeVariables.FirstOrDefault(x => x.VariableType == variableType && x.Usage == routeOrParameterName);
Expand Down Expand Up @@ -389,7 +390,7 @@ public bool FindRouteVariable(Type variableType, string routeOrParameterName, ou
}
}

variable = default!;
variable = default;
return false;

}
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Wolverine.Http/HttpGraph.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using JasperFx.CodeGeneration;
using JasperFx.CodeGeneration.Frames;
using JasperFx.Core;
Expand Down Expand Up @@ -123,7 +124,7 @@ public override IChangeToken GetChangeToken()
return this;
}

public HttpChain? ChainFor(string httpMethod, string urlPattern)
public HttpChain? ChainFor(string httpMethod, [StringSyntax("Route")]string urlPattern)
{
return _chains.FirstOrDefault(x => x.HttpMethods.Contains(httpMethod) && x.RoutePattern!.RawText == urlPattern);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Wolverine.Http/IHttpAware.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using JasperFx.CodeGeneration;
using JasperFx.CodeGeneration.Frames;
using JasperFx.CodeGeneration.Model;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static EndpointBuilder RemoveStatusCodeResponse(this EndpointBuilder buil
/// Base class for resource types that denote some kind of resource being created
/// in the system. Wolverine specific, and more efficient, version of Created<T> from ASP.Net Core
/// </summary>
public record CreationResponse(string Url) : IHttpAware
public record CreationResponse([StringSyntax("Route")]string Url) : IHttpAware
{
public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
{
Expand Down
15 changes: 8 additions & 7 deletions src/Http/Wolverine.Http/ModifyHttpChainAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using JasperFx.CodeGeneration;
using JasperFx.CodeGeneration.Model;
Expand Down Expand Up @@ -112,7 +113,7 @@ public override void Modify(HttpChain chain, GenerationRules rules)
/// </summary>
public class WolverineGetAttribute : WolverineHttpMethodAttribute
{
public WolverineGetAttribute(string template) : base("GET", template)
public WolverineGetAttribute([StringSyntax("Route")]string template) : base("GET", template)
{
}

Expand All @@ -124,7 +125,7 @@ public WolverineGetAttribute(string template) : base("GET", template)
/// </summary>
public class WolverinePostAttribute : WolverineHttpMethodAttribute
{
public WolverinePostAttribute(string template) : base("POST", template)
public WolverinePostAttribute([StringSyntax("Route")]string template) : base("POST", template)
{
}
}
Expand All @@ -134,7 +135,7 @@ public WolverinePostAttribute(string template) : base("POST", template)
/// </summary>
public class WolverinePutAttribute : WolverineHttpMethodAttribute
{
public WolverinePutAttribute(string template) : base("PUT", template)
public WolverinePutAttribute([StringSyntax("Route")]string template) : base("PUT", template)
{
}
}
Expand All @@ -144,7 +145,7 @@ public WolverinePutAttribute(string template) : base("PUT", template)
/// </summary>
public class WolverineHeadAttribute : WolverineHttpMethodAttribute
{
public WolverineHeadAttribute(string template) : base("HEAD", template)
public WolverineHeadAttribute([StringSyntax("Route")]string template) : base("HEAD", template)
{
}
}
Expand All @@ -154,7 +155,7 @@ public WolverineHeadAttribute(string template) : base("HEAD", template)
/// </summary>
public class WolverineDeleteAttribute : WolverineHttpMethodAttribute
{
public WolverineDeleteAttribute(string template) : base("DELETE", template)
public WolverineDeleteAttribute([StringSyntax("Route")]string template) : base("DELETE", template)
{
}
}
Expand All @@ -164,7 +165,7 @@ public WolverineDeleteAttribute(string template) : base("DELETE", template)
/// </summary>
public class WolverinePatchAttribute : WolverineHttpMethodAttribute
{
public WolverinePatchAttribute(string template) : base("PATCH", template)
public WolverinePatchAttribute([StringSyntax("Route")]string template) : base("PATCH", template)
{
}
}
Expand All @@ -174,7 +175,7 @@ public WolverinePatchAttribute(string template) : base("PATCH", template)
/// </summary>
public class WolverineOptionsAttribute : WolverineHttpMethodAttribute
{
public WolverineOptionsAttribute(string template) : base("OPTIONS", template)
public WolverineOptionsAttribute([StringSyntax("Route")]string template) : base("OPTIONS", template)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.Json;
using Lamar;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static void ConfigureSystemTextJsonForWolverineOrMinimalApi(this IService
/// <param name="url"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapPostToWolverine<T>(this IEndpointRouteBuilder endpoints, string url)
public static RouteHandlerBuilder MapPostToWolverine<T>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")]string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(T)));
Expand All @@ -62,7 +63,7 @@ public static RouteHandlerBuilder MapPostToWolverine<T>(this IEndpointRouteBuild
/// <param name="url"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapPutToWolverine<T>(this IEndpointRouteBuilder endpoints, string url)
public static RouteHandlerBuilder MapPutToWolverine<T>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")]string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(T)));
Expand All @@ -78,7 +79,7 @@ public static RouteHandlerBuilder MapPutToWolverine<T>(this IEndpointRouteBuilde
/// <param name="url"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapDeleteToWolverine<T>(this IEndpointRouteBuilder endpoints, string url)
public static RouteHandlerBuilder MapDeleteToWolverine<T>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")]string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(T)));
Expand All @@ -97,7 +98,7 @@ public static RouteHandlerBuilder MapDeleteToWolverine<T>(this IEndpointRouteBui
/// <typeparam name="TResponse"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapPostToWolverine<TRequest, TResponse>(this IEndpointRouteBuilder endpoints,
string url)
[StringSyntax("Route")] string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(TRequest)));
Expand All @@ -116,7 +117,7 @@ public static RouteHandlerBuilder MapPostToWolverine<TRequest, TResponse>(this I
/// <typeparam name="TResponse"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapPutToWolverine<TRequest, TResponse>(this IEndpointRouteBuilder endpoints,
string url)
[StringSyntax("Route")] string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(TRequest)));
Expand All @@ -135,7 +136,7 @@ public static RouteHandlerBuilder MapPutToWolverine<TRequest, TResponse>(this IE
/// <typeparam name="TResponse"></typeparam>
/// <returns></returns>
public static RouteHandlerBuilder MapDeleteToWolverine<TRequest, TResponse>(this IEndpointRouteBuilder endpoints,
string url)
[StringSyntax("Route")] string url)
{
var runtime = GetWolverineRuntime(endpoints);
var invoker = new Lazy<IMessageInvoker>(() => runtime.FindInvoker(typeof(TRequest)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public Task DeadLetterAsync(CancellationToken token, string? deadLetterReason =
private ServiceBusReceivedMessage AzureMessage { get; }
private ServiceBusSessionReceiver? SessionReceiver { get; }
private ServiceBusReceiver? ServiceBusReceiver { get; }
public Exception Exception { get; set; }

public Exception? Exception { get; set; }
public bool IsCompleted { get; set; }
public ServiceBusReceiver? Receiver { get; set; }
}
2 changes: 1 addition & 1 deletion src/Transports/Pulsar/Wolverine.Pulsar/PulsarListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async ValueTask DeferAsync(Envelope envelope)

public async ValueTask DisposeAsync()
{
_localCancellation.Cancel();
await _localCancellation.CancelAsync();

if (_consumer != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public bool IsEnabled(LogLevel logLevel)
return true;
}

public IDisposable BeginScope<TState>(TState state)
public IDisposable BeginScope<TState>(TState state) where TState: notnull
{
return new Disposable();
}
Expand Down

0 comments on commit 582983d

Please sign in to comment.