Skip to content

Use full entity name as a default (fixes #779) #786

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

Merged

Conversation

mrexox
Copy link
Contributor

@mrexox mrexox commented Apr 18, 2020

In this PR I just wanted to end with this:

- model.to_s.split('::').last
+ model.to_s

But I met a problem that it receives Class type in here

def model_name(name)

But String type in the another place. So, splitting by :: and taking the last word actually returns the same as name method of the class. This is fine, but...

For example, if we use such constructions, we end up with just V1 and V2 from the A::B module as it is parsed first:

module A
  module B
    class V1 < Grape::Entity
     ...

    class V2 < Grape::Entity
     ...

module A
  module C
    class V1 < Grape::Entity
      ...

    class V2 < Grape::Entity
      ...

This PR fixes this issue.

I just wanted to resolve this:

```
- model.to_s.split('::').last
+ model.to_s
```

But I met a problem that it receives Class type in here
https://github.com/ruby-grape/grape-swagger/blob/8abddd5f2ce5fe29238990b136625f34371b0be0/lib/grape-swagger/endpoint.rb#L354
But String type in the another place, where the type is generated. So,
splitting and taking the last actually returns the same as `name`
method of the class. That is very strange I think.

Also, if we, for example, use such constructions, we end up with just
`V1` and `V2` fron the `A::B` module as they are parsed first:

```ruby
module A
  module B
    class V1 < Grape::Entity
     ...

    class V2 < Grape::Entity
     ...

module A
  module C
    class V1 < Grape::Entity
      ...

    class V2 < Grape::Entity
      ...
```

This PR fixes this issue.
@grape-bot
Copy link

grape-bot commented Apr 18, 2020

1 Error
🚫 One of the lines below found in CHANGELOG.md doesn’t match the expected format. Please make it look like the other lines, pay attention to periods and spaces.
* [#786](https://github.com/ruby-grape/grape-swagger/pull/786): Use full entity name as a default - [@mrexox](https://github.com/mrexox)

Generated by 🚫 danger

@coveralls
Copy link

coveralls commented Apr 18, 2020

Coverage Status

Coverage remained the same at 99.454% when pulling 80276f0 on mrexox:use-full-entity-names-as-a-default-#779 into 077a274 on ruby-grape:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 99.429% when pulling d4299c9 on mrexox:use-full-entity-names-as-a-default-#779 into 077a274 on ruby-grape:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 99.429% when pulling d4299c9 on mrexox:use-full-entity-names-as-a-default-#779 into 077a274 on ruby-grape:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 99.429% when pulling d4299c9 on mrexox:use-full-entity-names-as-a-default-#779 into 077a274 on ruby-grape:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 99.429% when pulling d4299c9 on mrexox:use-full-entity-names-as-a-default-#779 into 077a274 on ruby-grape:master.

Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add an upgrade entry, so the users know about the changes, thanks

will release it as 1.1.0

@mrexox
Copy link
Contributor Author

mrexox commented Apr 19, 2020

@LeFnord , added an upgrade entry. Does it look fine?

@mrexox mrexox requested a review from LeFnord April 20, 2020 08:02
Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @mrexox

@LeFnord LeFnord merged commit 8f978dc into ruby-grape:master Apr 20, 2020
@LeFnord
Copy link
Member

LeFnord commented Apr 20, 2020

will release it tonight

aka-momo pushed a commit to aka-momo/grape-swagger that referenced this pull request Feb 8, 2023
)

* Use full entity name as a default (fixes ruby-grape#779)

I just wanted to resolve this:

```
- model.to_s.split('::').last
+ model.to_s
```

But I met a problem that it receives Class type in here
https://github.com/ruby-grape/grape-swagger/blob/8abddd5f2ce5fe29238990b136625f34371b0be0/lib/grape-swagger/endpoint.rb#L354
But String type in the another place, where the type is generated. So,
splitting and taking the last actually returns the same as `name`
method of the class. That is very strange I think.

Also, if we, for example, use such constructions, we end up with just
`V1` and `V2` fron the `A::B` module as they are parsed first:

```ruby
module A
  module B
    class V1 < Grape::Entity
     ...

    class V2 < Grape::Entity
     ...

module A
  module C
    class V1 < Grape::Entity
      ...

    class V2 < Grape::Entity
      ...
```

This PR fixes this issue.

* Update CHANGELOG

* Fix for old Ruby versions

* Skip Representable:: prefix just like Entity::

* Add upgrade entry and move changelog entry from fixes to features scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants