Giter Site home page Giter Site logo

aspnetcore.hashids's People

Contributors

geothachankary avatar lurumad avatar martincostello avatar unaizorrilla avatar villagra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aspnetcore.hashids's Issues

Signed integers not working

Could be possible to hash signed integers? When we try hash negative integers it returns empty string, ie, for example we're trying hash -1. Thanks

Error when pass a fake id hashed

When get all datas from a query, I have ids hashed, and if I take a id and make a request to get a element, it works fine. However, if I make a request with a fake id hashed, the request fails in OnException.

Request: PUT

bug_ID_Malo

Encode/decode Id in DTO

Hi.
Your assembly works well, when it comes to routes. But when I post DTO with string Id, it remains original string. Can you please think of decoding them to int too? I'm not sure right now how it should be working in this case but that would be just great. Now I have to decode id manually each time.
Thanks.

HashidsModelBinder doesn't take in consideration whether the hash ID can be decoded when route constraint is not applied

When :hashids route constraint is not applied, the HashidsModelBinder returns

Task.CompletedTask

when the Decode method returns empty array which leads to having a default value in the route parameter - default for int is 0. Also, the model binder nor the route constraint is respecting the AcceptNonHashedIds option

https://github.com/Xabaril/AspNetCore.Hashids/blob/2b5a623d10c5a5571fa99a282305977a9ecd2a15/src/AspNetCore.Hashids/Mvc/HashidsModelBinder.cs#LL44C13-L47C14

Expected Behavior

I expect to have validation whether the Hash ID is valid and can be decoded - similar to when using Guid as parameter, if the :guid route constraint is not applied a 400 Bad request with validation body is returned.

Current Behavior

Currently. the model binder assumes that the route constraint would make sure that the hash can be decoded and if it cannot be, it will return a

Task.CompletedTask

thus leading to a default value for the route parameter - 0 for ints

Possible Solution

I suggest to have the same behavior as when using Guid id as route parameter - return 400 Bad request. When the :hashids route constraint is applied, the current behavior is expected.

Steps to Reproduce

[HttpGet("{id}")]
public async Task<IActionResult> GetWeatherForecast1([ModelBinder(typeof(HashidsModelBinder))] int id)
{
    .
    . // "id" would be 0 here when the Hash ID string cannot be decoded
    .
}

Context (Environment)

.NET version: ASP.NET Core 6.0 - basic API controller
AspNetCore.Hashids version: 2.0.0
Hashids.net version: 1.6.1

Possible Implementation

/

Support for Int64/long Ids

Hashids.Decode() only supports int32, the current implementation doesn't work with int64 ids. Currently we have to use Hashids.DecodeLong().

HashIds not working after adding custom Output formatter

I am using Hashids library in my .NET 6 API to encode int values into string values in my model before sending it off to the API caller. The library is currently working fine.

Recently I have a requirement to provide pascal cased json from the API (default it was returning camel case). In order to achieve this I have gone in the path of sending an Accept header with a custom value and added an output formatter to handle the pascal case conversion.

public class PascalCaseFormatter : SystemTextJsonOutputFormatter { public PascalCaseFormatter(JsonSerializerOptions jsonSerializerOptions) : base(jsonSerializerOptions) { SupportedMediaTypes.Clear(); SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=pascal")); } }

then registered it in Startup.cs

`services.AddHashids(setup =>
{
setup.Salt = Configuration["HashConfiguration:Salt"];
setup.MinHashLength = Convert.ToInt32(Configuration["HashConfiguration:MinHashLength"]);
setup.Alphabet = Configuration["HashConfiguration:Alphabet"];
});

services.AddControllers(options =>
{
options.OutputFormatters.Add(
new PascalCaseFormatter(new JsonSerializerOptions { PropertyNamingPolicy = null }));
});`

In the accept header if I send as application/json;profile=pascal I get pascal cased json result for any model which does not have a hashid converter in it. When I have a model as below, then an error is thrown from the hashids library mentioning that the service provider is not found.

public class ApplicantAccountVm { [JsonConverter(typeof(HashidsJsonConverter))] public int ApplicantAccountId { get; set; } }

Result for this model,

image

What should I do to register hashid in this situation?

Not compatible with netstandard2.0

Tried to add package to a .Net Standard 2.0 project and generated an Error code NU1202 "Package AspNetCore.Hashids 1.1.1 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package AspNetCore.Hashids 1.1.1 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1)"

Integración con MediatR y Swagger.

Hola a todos, muy útil esta librería y la estoy integrando en un proyecto que ya esta funcionando.

Con los métodos simples como los siguientes, no tengo problemas y ya hice la migración:
/products
/product/{id:hashids}
/categories
/category/{id:hashids}

El problema lo tengo con los métodos que reciben un objeto desde el [FromQuery], por ejemplo un IRequest de MediatR para una consulta. Necesita el ProductId, CategoryId y otros campos más. Mis preguntas:

  1. Cómo hago para recibir el objeto en el método y que se decodifiquen las propiedades?

  2. Cómo recibo decodifico los campos cuando los manden en un método Post?

Otra cosa que note es que no funciona con Swagger, para recibir el Id es un Int y no permite que ingrese un valor codificado como 3gY14rPO.

Saludos y gracias de antemano!

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.