-
Notifications
You must be signed in to change notification settings - Fork 472
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
removes limit on model names, updates README #515
Conversation
LeFnord
commented
Oct 10, 2016
- updates README
a78a844
to
b493f45
Compare
length += x.length | ||
length < 42 | ||
end.reverse.join | ||
def model_name(entity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still make assumptions about the grape / entity / class structure, can we just leave it as entity.name
or entity.entity_name
if defined?
There is no reference in the spec that definitions should have a specific naming convention.
I argue for this point that this will be the most transparent to the developer. For internal documentation it helps to correctly show the entity name (fully).
For example take: AnimalFarm::Internal::CowEntity
and AnimalFarm::Internal:GoatEntity
both would be rendered as AnimalFarm::Internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah I see …
it should now be correct … the assumentions based in both documentations, one is in grape-swagger self, and very often used in the wild and the other one is this, you mentioned from grape-entity for the first one it would be assumed, that only the class name is the relevant part |
For consistency sake all cases should be handled the same. People can easily overwrite it using the entry name method |
Looks good to me |
else | ||
name.name.demodulize.camelize | ||
entity.name.demodulize.camelize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take the example again of animals:
AnimalFarm::Internal::CowEntity
and an AnimalFarm::Public::CowEntity
, the internal is only used by internal apps and exposes all attributes, the public one only the important attributes. Using this they both end up being CowEntity
and depending on the load order the swagger output will show the public or internal
if entity.respond_to?(:entity_name) | ||
entity.entity_name | ||
elsif entity.to_s.end_with?('::Entity', '::Entities') | ||
entity.to_s.split('::')[-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this elsif
just be removed and default to entity.name
? less assumptions == happier developer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw @LeFnord why do we check for end_with?
here, but removing all 'Entity' string parts here https://github.com/ruby-grape/grape-swagger/blob/master/lib/grape-swagger/doc_methods/data_type.rb#L49
Which algo is correct?
Sorry to be a bitch about this but can it just be like this? :D def model_name(entity)
if entity.respond_to?(:entity_name)
entity.entity_name
else
entity.name
end
end Benefits:
class ApplicationEntity < Grape::Entity
def self.entity_name
name.to_s.split('::')[-2]
# OR
name.demodulize.camelize
end
end
class AnimalFarmEntity < ApplicationEntity
...
end |
- updates README - adds changelog entry
@JanStevens … benefits of this solution are:
your proposed solution would intruduce one |
Fair enough, considerable for next major release? Or should I drop it 😀 On Wednesday, 12 October 2016, peter scholz notifications@github.com
~Jan Stevens |
@@ -7,6 +7,7 @@ | |||
|
|||
#### Fixes | |||
|
|||
* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names, updates README - [@LeFnord](https://github.com/LeFnord). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove "updates README", it's not relevant, but nice.
I'm going to vote no breaking changes and merge this, but @JanStevens you have a good point, so maybe you want to open a PR on top of this that introduces your proposal and we can talk about that again? |
@JanStevens … don't drop it … such things should be forgotten, maybe we can use the project feature? |
I thought this was a good step forward @LeFnord. I'll slow down :) |
Hi,
If you could jsut change By the way, I think showing the full name is a better behaviour than just the name. Having an internal and external entity seem a little strange, (for what I understand) entities are used for expose data through an API so they are not supposed to be private / internal and it's seems to be a lot more improbable than having two classes with the same name in different namespace. |
@jonathantribouharet please can you commit your thoughts on this discussion #519 |