Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rast1234 committed Jul 26, 2024
1 parent b6ba163 commit 616902a
Show file tree
Hide file tree
Showing 50 changed files with 6,144 additions and 5,802 deletions.
16 changes: 8 additions & 8 deletions src/Tochka.JsonRpc.All/Tochka.JsonRpc.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Tochka.JsonRpc.ApiExplorer\Tochka.JsonRpc.ApiExplorer.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Client\Tochka.JsonRpc.Client.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Common\Tochka.JsonRpc.Common.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.OpenRpc\Tochka.JsonRpc.OpenRpc.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Server\Tochka.JsonRpc.Server.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Swagger\Tochka.JsonRpc.Swagger.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tochka.JsonRpc.ApiExplorer\Tochka.JsonRpc.ApiExplorer.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Client\Tochka.JsonRpc.Client.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Common\Tochka.JsonRpc.Common.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.OpenRpc\Tochka.JsonRpc.OpenRpc.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Server\Tochka.JsonRpc.Server.csproj" />
<ProjectReference Include="..\Tochka.JsonRpc.Swagger\Tochka.JsonRpc.Swagger.csproj" />
</ItemGroup>

</Project>
32 changes: 16 additions & 16 deletions src/Tochka.JsonRpc.Client/JsonRpcClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,6 @@ internal virtual async Task<ISingleJsonRpcResult<TResponse>> SendRequestInternal
}
}

private async Task<(IJsonRpcCallContext, string)> PrepareInternalRequestContext<TParams>(string? requestUrl, Request<TParams> request,
CancellationToken cancellationToken) where TParams : class
{
var context = CreateContext();
context.WithRequestUrl(requestUrl);
var data = request.WithSerializedParams(DataJsonSerializerOptions);
context.WithSingle(data);
using var content = CreateHttpContent(data);
using var requestMessage = CreateRequestMessage(requestUrl, content, new[] { request.Method });
var httpResponseMessage = await Client.SendAsync(requestMessage, cancellationToken);
context.WithHttpResponse(httpResponseMessage);
var contentString = await GetContent(httpResponseMessage.Content, cancellationToken);
context.WithHttpContent(httpResponseMessage.Content, contentString);
return (context, contentString);
}

// internal virtual for mocking in tests
internal virtual async Task<IBatchJsonRpcResult?> SendBatchInternal(string? requestUrl, IEnumerable<ICall> calls, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -437,6 +421,22 @@ protected internal virtual HttpContent CreateHttpContent(object data)
protected internal virtual async Task<string> GetContent(HttpContent content, CancellationToken cancellationToken) =>
await content.ReadAsStringAsync(cancellationToken);

private async Task<(IJsonRpcCallContext, string)> PrepareInternalRequestContext<TParams>(string? requestUrl, Request<TParams> request, CancellationToken cancellationToken)
where TParams : class
{
var context = CreateContext();
context.WithRequestUrl(requestUrl);
var data = request.WithSerializedParams(DataJsonSerializerOptions);
context.WithSingle(data);
using var content = CreateHttpContent(data);
using var requestMessage = CreateRequestMessage(requestUrl, content, new[] { request.Method });
var httpResponseMessage = await Client.SendAsync(requestMessage, cancellationToken);
context.WithHttpResponse(httpResponseMessage);
var contentString = await GetContent(httpResponseMessage.Content, cancellationToken);
context.WithHttpContent(httpResponseMessage.Content, contentString);
return (context, contentString);
}

/// <summary>
/// Set User-Agent header
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public static class BatchExtensions
/// <returns>true if the object contains an element that has the specified key; otherwise, false.</returns>
/// <exception cref="ArgumentNullException">key is null</exception>
[ExcludeFromCodeCoverage]
public static bool TryGetResponse(this IReadOnlyDictionary<IRpcId, IResponse> responses,
IRpcId id,
[NotNullWhen(true)] out IResponse? response) =>
public static bool TryGetResponse(this IReadOnlyDictionary<IRpcId, IResponse> responses, IRpcId id, [NotNullWhen(true)] out IResponse? response) =>
responses.TryGetValue(id, out response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public BatchJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions hea
[PublicAPI]
public class BatchJsonRpcResult<TResponse> : IBatchJsonRpcResult<TResponse>
{
/// <inheritdoc />
public IBatchJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Context with all information about request and response
/// </summary>
Expand All @@ -48,9 +51,6 @@ public class BatchJsonRpcResult<TResponse> : IBatchJsonRpcResult<TResponse>
/// </summary>
protected readonly Dictionary<IRpcId, IResponse> Responses;

/// <inheritdoc />
public IBatchJsonRpcResultAdvanced Advanced { get; init; }

/// <inheritdoc cref="IBatchJsonRpcResult{TResponse}" />
public BatchJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions headersJsonSerializerOptions, JsonSerializerOptions dataJsonSerializerOptions)
{
Expand Down
24 changes: 12 additions & 12 deletions src/Tochka.JsonRpc.Client/Models/BatchResult/IBatchJsonRpcResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace Tochka.JsonRpc.Client.Models.BatchResult;
[PublicAPI]
public interface IBatchJsonRpcResult
{
/// <summary>
/// Advanced data for complex work with batch Result of JSON-RPC request
/// </summary>
/// <returns></returns>
IBatchJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Try to deserialize response result or throw if unable
/// </summary>
Expand All @@ -31,12 +37,6 @@ public interface IBatchJsonRpcResult
/// <param name="id">Response id</param>
/// <exception cref="JsonRpcException">if no response with given id or response has error</exception>
bool HasError(IRpcId id);

/// <summary>
/// Advanced data for complex work with batch Result of JSON-RPC request
/// </summary>
/// <returns></returns>
IBatchJsonRpcResultAdvanced Advanced { get; init; }
}

/// <summary>
Expand All @@ -46,6 +46,12 @@ public interface IBatchJsonRpcResult
[PublicAPI]
public interface IBatchJsonRpcResult<out TResponse>
{
/// <summary>
/// Advanced data for complex work with batch Result of JSON-RPC request
/// </summary>
/// <returns></returns>
IBatchJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Try to deserialize response result to typed response or throw if unable
/// </summary>
Expand All @@ -66,10 +72,4 @@ public interface IBatchJsonRpcResult<out TResponse>
/// <param name="id">Response id</param>
/// <exception cref="JsonRpcException">if no response with given id or response has error</exception>
bool HasError(IRpcId id);

/// <summary>
/// Advanced data for complex work with batch Result of JSON-RPC request
/// </summary>
/// <returns></returns>
IBatchJsonRpcResultAdvanced Advanced { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace Tochka.JsonRpc.Client.Models.SingleResult;
[PublicAPI]
public interface ISingleJsonRpcResult
{
/// <summary>
/// Advanced data for complex work with single Result of JSON-RPC request
/// </summary>
/// <returns></returns>
ISingleJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Try to deserialize response result or throw if unable
/// </summary>
Expand All @@ -26,22 +32,21 @@ public interface ISingleJsonRpcResult
/// Check if response has error
/// </summary>
bool HasError();

/// <summary>
/// Advanced data for complex work with single Result of JSON-RPC request
/// </summary>
/// <returns></returns>
ISingleJsonRpcResultAdvanced Advanced { get; init; }
}


/// <summary>
/// Result of single JSON-RPC request with typed response
/// <typeparam name="TResponse">Type of response</typeparam>
/// </summary>
[PublicAPI]
public interface ISingleJsonRpcResult<out TResponse>
{
/// <summary>
/// Advanced data for complex work with single Result of JSON-RPC request
/// </summary>
/// <returns></returns>
ISingleJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Try to deserialize response result to typed response or throw if unable
/// </summary>
Expand All @@ -58,10 +63,4 @@ public interface ISingleJsonRpcResult<out TResponse>
/// Check if response has error
/// </summary>
bool HasError();

/// <summary>
/// Advanced data for complex work with single Result of JSON-RPC request
/// </summary>
/// <returns></returns>
ISingleJsonRpcResultAdvanced Advanced { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public SingleJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions he
public TResponse? AsResponse<TResponse>() => Advanced.AsResponse<TResponse>();
}


/// <inheritdoc />
[PublicAPI]
public class SingleJsonRpcResult<TResponse> : ISingleJsonRpcResult<TResponse>
{
/// <inheritdoc />
public ISingleJsonRpcResultAdvanced Advanced { get; init; }

/// <summary>
/// Context with all information about request and response
/// </summary>
Expand All @@ -47,9 +49,6 @@ public class SingleJsonRpcResult<TResponse> : ISingleJsonRpcResult<TResponse>
/// </summary>
protected readonly IResponse? Response;

/// <inheritdoc />
public ISingleJsonRpcResultAdvanced Advanced { get; init; }

/// <summary></summary>
public SingleJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions headersJsonSerializerOptions, JsonSerializerOptions dataJsonSerializerOptions)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tochka.JsonRpc.Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class Extensions
/// </summary>
/// <param name="collection">Collection of objects</param>
/// <typeparam name="T">Type of item to get</typeparam>
/// <returns>First item of type <typeparamref name="T"/> if found, null otherwise</returns>
/// <returns>First item of type <typeparamref name="T" /> if found, null otherwise</returns>
public static T? Get<T>(this IEnumerable<object> collection)
where T : class => collection.FirstOrDefault(static x => x is T) as T;

Expand Down
14 changes: 7 additions & 7 deletions src/Tochka.JsonRpc.OpenRpc/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ public static IEndpointConventionBuilder MapOpenRpc(this IEndpointRouteBuilder e
return endpoints.MapGet(options.DocumentPath, requestDelegate);
}

public static JsonSchema BuildWithoutUri(this JsonSchemaBuilder builder)

Check warning on line 116 in src/Tochka.JsonRpc.OpenRpc/Extensions.cs

View workflow job for this annotation

GitHub Actions / test

Missing XML comment for publicly visible type or member 'Extensions.BuildWithoutUri(JsonSchemaBuilder)'

Check warning on line 116 in src/Tochka.JsonRpc.OpenRpc/Extensions.cs

View workflow job for this annotation

GitHub Actions / test

Missing XML comment for publicly visible type or member 'Extensions.BuildWithoutUri(JsonSchemaBuilder)'
{
var result = builder.Build();
result.BaseUri = null!;
return result;
}

private static void EnsureRequiredServicesRegistered(IServiceProvider services)
{
if (services.GetService<OpenRpcMarkerService>() == null)
{
throw new InvalidOperationException($"Unable to find the required services. Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(AddOpenRpc)}' in the application startup code.");
}
}

public static JsonSchema BuildWithoutUri(this JsonSchemaBuilder builder)
{
var result = builder.Build();
result.BaseUri = null!;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public static JsonSchemaBuilder TryAppendTitle(this JsonSchemaBuilder builder, s

return builder;
}
}
}
Loading

0 comments on commit 616902a

Please sign in to comment.