GithubHelp home page GithubHelp logo

jhipster-net's Introduction

JHipsterNet

Core library for app generated with jhipster-dotnetcore

Pre-requisites

  • dotnet v6.0

    Note: If you use asdf package manager, just run asdf install since the codebase is already configured with the appropriate config file.

Running tests

dotnet test

Running the formatter

dotnet format

jhipster-net's People

Contributors

123445666 avatar danielfran avatar enmanuelreyes avatar jhipster-bot avatar kennethlong avatar nicolas63 avatar venturialberto avatar vraravam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jhipster-net's Issues

Source code structure

Overview of the issue

I was trying to understand and write some unit tests to contribute to this new codebase. Not sure if this base folder under src is where things should go. Any explanation for the thought process would be good.

Motivation for or Use Case

Contributing to the codebase by adding unit tests seems unintuitive.

Reproduce the error
Related issues

Not that I know of - this is issue numero uno for this codebase

Suggest a Fix
JHipster Version(s)

INFO! Using JHipster version installed globally
INFO! Executing jhipster:info
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
/dev/oss/jhipster-net
└── (empty)

cat: no such file or directory: .yo-rc.json

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

git version 2.28.0

node: v13.5.0

npm: 6.13.4

Docker version 19.03.12, build 48a66213fe

docker-compose version 1.26.2, build eefe0d31

INFO! Congratulations, JHipster execution is complete!

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

OS: MacOS Catalina
Browser: FF

  • Checking this box is mandatory (this is just to show you read everything)

Pageable is trying to create the "Previous" property when page is 0

Overview of the issue

Hi,
I would like to share an issue I have faced while using the library.

I was trying to copy the configuration of the backend pagination, used on another project.
I created a new .net 6 web api, imported the JHipsterNet.Core and JHipsterNet.Web 1.0.9, created an endpoint with a IPageable as parameter and a custom object with the annotation [FromQuery], but it seems to not work.

In the working project i was able to call the api without specifing a single parameter.

This was the stack trace:

System.ArgumentNullException: Page Number must not be less than zero! (Parameter 'pageNumber')
   at JHipsterNet.Core.Pagination.Pageable..ctor(Int32 pageNumber, Int32 pageSize, Sort sort) in ...path...JHipsterNet.Core\Pagination\Pageable.cs:line 8
   at JHipsterNet.Core.Pagination.Pageable.get_Previous() in ...path...\JHipsterNet.Core\Pagination\Pageable.cs:line 20
   at Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[TDeclaringType,TValue](Func`2 getter, Object target)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.DefaultComplexObjectValidationStrategy.Enumerator.<>c__DisplayClass13_1.<MoveNext>b__1()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationEntry.get_Model()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitImplementation(ModelMetadata& metadata, String& key, Object model)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Validate(ModelMetadata metadata, String key, Object model, Boolean alwaysValidateAtTopLevel, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator.Validate(ActionContext actionContext, ValidationStateDictionary validationState, String prefix, Object model, ModelMetadata metadata, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.EnforceBindRequiredAndValidate(ObjectModelValidator baseObjectValidator, ActionContext actionContext, ParameterDescriptor parameter, ModelMetadata metadata, ModelBindingContext modelBindingContext, ModelBindingResult modelBindingResult, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS
=======
Accept: */*
Connection: keep-alive
Host: localhost:50001
User-Agent: PostmanRuntime/7.20.1
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Postman-Token: f9748320-c0cb-46a3-8966-05f0e44c6ce7

I found out the problem was on the constructor of the Pageable, precisely on the "Previous" property.

private Pageable(int pageNumber, int pageSize, Sort sort = null)
      {
          if (pageNumber < 0) {
              throw new ArgumentNullException(nameof(pageNumber), "Page Number must not be less than zero!");
          }

          if (pageSize < 1) {
              throw new ArgumentNullException(nameof(pageSize), "Page Size must not be less than one!");
          }

          PageNumber = pageNumber;
          PageSize = pageSize;
          Sort = sort ?? Sort.Unsorted;
      }

      public IPageable Previous => new Pageable(PageNumber - 1, PageSize, Sort);
      public bool IsPaged => true;

      public int PageNumber { get; }
      public int PageSize { get; }

      public int Offset => PageNumber * PageSize;
      public Sort Sort { get; }

      public IPageable Next => new Pageable(PageNumber + 1, PageSize, Sort);

      public IPageable PreviousOrFirst => HasPrevious ? Previous : First;

The only reference was on the "PreviousOrFirst".
The error was due to the Pageable with "page=0", trying to create the Pageable of the previous page, so "-1".

Solution
Later i found out the problem was on a property of the project that i had to remove.
https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts

But i wanted to understand better the reasons of the exception.
So I debugged the JHipsterNet.Core and JHipsterNet.Web libraries and found out that the error was due to the "public" declaration of the variabile It seems that if it is public, at runtime the application is trying to resolve the "Previous" property even if it is not necessary (because the page is equal to 0).
In this way it is possibile to make the IPageable parameter optional and the custom object mandatory, without removing the null check project option (which is enable by default in the newest .net projects)

Reproduce the error

The project for testing is attached

Related issues
Suggest a Fix

Change the declaration of "Previous" from public to private.

JHipster Version(s)

1.0.9
JHipsterApiTest.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.