khrt / Raisin

Raisin - a REST API micro framework for Perl 🐫 🐪
61 stars 29 forks source link

Request for clarification #103

Closed hidden-primary-net closed 4 years ago

hidden-primary-net commented 4 years ago

Hello dear enlightened,

I'm constantly scratching my head regarding the md5_hex usage. When I give the created JSON to e.g. swagger-codegen to create a (perl) code stub I get quite unattractive package names containing these 10 hash characters.

What is this fingerprinting meant for? I have really no idea... thanks for helping me get enlightened, too.

khrt commented 4 years ago

Every object in OpenAPI specification has to have a unique name if you would like to refer to it. For example, you define a User object under definitions section, then you refer to this object in paths section without a need to inline the object definitions all the time. See the picture below.

https://petstore.swagger.io/v2/swagger.json

At the moment of implementing this functionality I chose the simplest way of generating the names by taking its package name and hashing it with MD5 function. It looks wired even for me right now, because why don't I use the exact package name instead which would make more sense?

Hope I answered your question. Feel free to re-open if needed.

hidden-primary-net commented 4 years ago

Hellp @khrt, I understand that any object need its own name. What I am struggeling with is that the object names change when attributes change. That makes the object names longer than necessary and the interface instable regarding the object names. A Perl client would constantly need to use other packages, from e.g.

...
use User::MD5HASHCH1;
...
...
my $user = User::MD5HASHCH1->new( ... );```

to

```perl
...
use User::MD5HASHCH2;
...
my $user = User::MD5HASHCH2->new( ... );

only because I added or renamed an attribute.

Is it really useful to use a mechanims like this or would it be sufficient to just use a valid and reproducible $obj->name as name of the package?

khrt commented 4 years ago

As I mentioned above and it matches with what you're saying here, I also believe this would be sufficient to use a valid and reproducible $obj->name as a name of the package.