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

Can not handle model binding validation errors for dynamic web API actions #1918

Closed
ShiningRush opened this issue Mar 7, 2017 · 3 comments
Closed
Labels
Milestone

Comments

@ShiningRush
Copy link

ShiningRush commented Mar 7, 2017

I'm find a problem that when dynamic webapi validating parameter, It can't find out the serialization errors.
Such as the client posted contents contain incorrect string "abcd" which will be serialized to a property with a int type.
Now, Application Layer that be called by dynamic webapi will get a defaut int value instead of throwing a AbpValidationException.

I finded out the code causing the problem as follow:

        public async Task<HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
        {
            if (!_configuration.IsValidationEnabledForControllers)
            {
                return await continuation();
            }

            var methodInfo = actionContext.ActionDescriptor.GetMethodInfoOrNull();
            if (methodInfo == null)
            {
                return await continuation();
            }

// here, jump the webapi's validation caused the problem
            if (actionContext.ActionDescriptor.IsDynamicAbpAction())
            {
                return await continuation();
            }

            using (var validator = _iocResolver.ResolveAsDisposable<WebApiActionInvocationValidator>())
            {
                validator.Object.Initialize(actionContext, methodInfo);
                validator.Object.Validate();
            }

            return await continuation();
        }

Now what i can do is annotated the code,
But i worry about it could reduce performance(double validate).

And Even used webapi's validation can catch serialization errors but the returned errorMessage is empty, It also confused me.

There is any solution more better?

@hikalkan hikalkan added this to the v1.6.0 milestone Mar 7, 2017
@hikalkan
Copy link
Member

hikalkan commented Mar 7, 2017

Let us check this.

@ShiningRush
Copy link
Author

Thanks reply.
I wonder whether i should close the issue after it be asigned to problem or bug?

@hikalkan
Copy link
Member

hikalkan commented Mar 9, 2017

We will close this when it's resolved.
Thanks a lot.

@hikalkan hikalkan changed the title DynamicWebapi Validation Problem Can not handle model binding validation errors for dynamic web API actions Mar 13, 2017
@hikalkan hikalkan added bug and removed problem labels Mar 13, 2017
ShiningRush added a commit to ShiningRush/aspnetboilerplate that referenced this issue Mar 17, 2017
* Nolocking extensions implemented for aspnetboilerplate#1637

* Add EfCoreTransactionStrategy

* Implement EfCoreTransactionStrategy

* Abp.Dapper package implemented for aspnetboilerplate#1661

* Dapper packoptions added on project.json

* Abp.Dapper tests added

* refactor for aspnetboilerplate#1661

* resolved aspnetboilerplate#1907

* Resolved aspnetboilerplate#1847: Trigger AbpHandledExceptionData for hangfire jobs too.

* Fixed aspnetboilerplate#1875: Tenant Resolve Contributer renamed to Contributor (typo fix)

* Resolved aspnetboilerplate#1886: Make TestAbpSession methods and properties virtual to allow overriding.

* Use existing connection in the demo if available for EF Core.

* aspnetboilerplate#1909: Refactor EF Core transaction strategy. Pass conn string to options builder.

* aspnetboilerplate#1909 refactored DbContextEfCoreTransactionStrategy

* aspnetboilerplate#1854 Correct version in project.json for dapper package.

* Add Abp.Dapper to pack.ps1.

* Resolved aspnetboilerplate#1827: Depend on JetBrains.Annotations instead of including annotations in Abp package.

* Resolved aspnetboilerplate#1864: Set Http Status to 400 for validation exceptions.

* Add WithNoLockInterceptor in AbpEntityFrameworkModule aspnetboilerplate#1823.

* Resolved aspnetboilerplate#1892: Load plugin dependencies from plugin folder.

* Incremented version to 1.5.0.0.

* Resolved aspnetboilerplate#1915: Upgrade to AspNet Core v1.1.1.

* Open solution on VS 2017, make it building (but not passing all unit tests yet).

* Upgraded xunt and other nuget packages.

* Create nuget packages after build.

* Create Abp-fa.xml

* Added bindings based on microsoft/vstest#428 to be able to run unit tests for aspnet core.

* Passed all unit tests by applying microsoft/vstest#428

* Remove solution folder.

* Change pack.ps1 for msbuild

* Revised nuget packaging.

* Fix appveyor.xml.

* Move common project properties to a single file. Revise pack.ps1.

* Change sln format.

* update appveyor file

* added RuntimeIdentifier.

* Fix test dll paths in appveyor.xml

* Temporarily remove NH tests for appveyor.

* Check matched count on DomainTenantResolveContributor

* Fixed aspnetboilerplate#1928: Fix Dapper namespaces.

* Fix default namespaces for projects.

* Resolved aspnetboilerplate#1934: Upgrade nuget package dependencies.

* Fixed aspnetboilerplate#1923: Web API [DontWrapResult] Not Working with [AbpApiAuthorize]

* Fixed aspnetboilerplate#1918: Can not handle model binding validation errors for dynamic web API actions.

* aspnetboilerplate#1936 Remove Abp dependency from Abp.Web.Resources package.

* Fixed aspnetboilerplate#1936: Abp.Web.Resources contents become flat with 1.5.1 release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants