Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
<PackageVersion Include="Scrutor" Version="7.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.10.1" />
<PackageVersion Include="FluentValidation" Version="12.1.1" />
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" Version="10.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.1" />
<PackageVersion Include="Braintree" Version="5.38.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Grand.Domain.Permissions;
using Grand.Domain.Catalog;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Grand.Module.Api.Attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Grand.Domain.Permissions;
using Grand.Domain.Catalog;
using MediatR;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Grand.Module.Api.Attributes;
using Microsoft.AspNetCore.Http;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@
using Grand.Module.Api.Queries.Handlers.Common;
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Grand.Module.Api.Infrastructure.Extensions
{
public static class ServiceCollectionExtensions
{
public static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter(this IServiceCollection services)
{
var builder = new ServiceCollection()
.AddLogging()
.AddMvc()
.AddNewtonsoftJson()
.Services.BuildServiceProvider();

return builder
.GetRequiredService<IOptions<MvcOptions>>()
.Value
.InputFormatters
.OfType<NewtonsoftJsonPatchInputFormatter>()
.First();
}
public static void RegisterRequestHandler(this IServiceCollection services)
{
var handlerTypes = new (Type dto, Type entity)[]
Expand Down
3 changes: 1 addition & 2 deletions src/Modules/Grand.Module.Api/Grand.Module.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Scalar.AspNetCore" />
<PackageReference Include="System.Linq.Dynamic.Core" />
Expand Down
5 changes: 0 additions & 5 deletions src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config
//register RequestHandler
services.RegisterRequestHandler();

//Add JsonPatchInputFormatter
services.AddControllers(options =>
{
options.InputFormatters.Insert(0, services.GetJsonPatchInputFormatter());
});
services.AddScoped<ModelValidationAttribute>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
{

var type = context.JsonTypeInfo.Type;
if (!schema.Properties.Any() || type == null) return Task.CompletedTask;

if (type == null || schema.Properties == null || !schema.Properties.Any()) return Task.CompletedTask;
var excludedPropertyNames = type
.GetProperties()
.Where(
Expand All @@ -26,7 +26,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
ap => excludedPropertyNames.Any(
pn => pn.Equals(ap.Key, StringComparison.InvariantCultureIgnoreCase)
)
).Select(ap => ap.Key);
).Select(ap => ap.Key).ToList();

foreach (var propertyToExclude in excludedSchemaPropertyKey) schema.Properties.Remove(propertyToExclude);

Expand Down
4 changes: 4 additions & 0 deletions src/Web/Grand.Web/App_Data/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
"ClientSecret": ""
},
//access to the api to web controllers
//when enabled (Development environment only), API documentation (Scalar) is available at: https://your-domain/scalar/v2
//locally: https://localhost:44350/scalar/v2
"FrontendAPI": {
"Enabled": true,
"JsonContentType": false,
Expand All @@ -186,6 +188,8 @@
"RefreshTokenExpiryInMinutes": 1440
},
//api for admin
//when enabled (Development environment only), API documentation (Scalar) is available at: https://your-domain/scalar/v1
//locally: https://localhost:44350/scalar/v1
"BackendAPI": {
"Enabled": true,
"SecretKey": "your private secret key to use api",
Expand Down
Loading