Skip to content
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

Entity name setter method #10

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

olivier-thatch
Copy link
Contributor

By default, the entity names generated by grape-swagger in the OpenAPI schema are based on the fully qualified Ruby class names, e.g. MyAPI::Entities::Foo becomes MyAPI_Entities_Foo in the schema.

It is possible to customize entity names by adding an entity_name class method to the entity class (cf. docs).

However, doing this with Sorbet is very verbose:

class Link < Grape::Entity
  extend T::Sig

  sig { returns(String) }
  def self.entity_name
    "LinkedStatus"
  end
end

or even worse, if you're using the Style/ClassMethodsDefinitions Rubocop rule with EnforcedStyle: self_class:

class Link < Grape::Entity
  class << self
    extend T::Sig

    sig { returns(String) }
    def entity_name
      "LinkedStatus"
    end
  end
end

This PR adds an .entity_name= setter method to Grape::Entity to make it possible to define custom entity names in a much terser manner:

class Link < Grape::Entity
  self.entity_name = "LinkedStatus"
end

@olivier-thatch olivier-thatch merged commit d1b73dc into main Jul 15, 2024
6 checks passed
@olivier-thatch olivier-thatch deleted the olivier-grape-entity-name branch July 15, 2024 17:13
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.

1 participant