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

Added documentation to entities #183

Merged
merged 5 commits into from
Jun 26, 2012
Merged

Added documentation to entities #183

merged 5 commits into from
Jun 26, 2012

Conversation

flah00
Copy link
Contributor

@flah00 flah00 commented Jun 11, 2012

Entities and documentation seem like a logical unit. Combining inheritable exposures with inheritable docs would be magical! I am currently forced to define a hash (object_fields) in a call to desc and maintain an entity and documentation separately.

My current work flow

  1. Create an entity
  2. Create an endpoint
  3. Write a desc for the endpoint
    class Api::Entities::Widget < Grape::Entity
        expose :slug, :name
    end
...
    desc "blah blah", { 
        :params => { 
            :slug => { :type => "string", :desc => "unique id" }
        },
        :object_fields => {
            :slug => { :type => "string", :desc => "unique id" },
            :name => { :type => "string", :desc => "the name of the object" }
        }
    }

Inevitably, our very immature API requires field fiddling and I have to revisit the entity. Suddenly I'm faced with the very frustrating prospect of changing the desc and the entity ... and I don't always remember. When I add something to the entity, I need to remember to add it to the object_fields hash as well.

If entities become aware of one more key, maybe called documentation, I could gain immediate visibility into which fields are and aren't documented... and I'd be happier.

Consequently, I'd now be able to easily include my documentation in my desc block

    class Api::Entities::Widget < Grape::Entity
        expose :slug, :documentation => { :type => "string", :desc => "unique id" }
        expose :name, :documentation => { :type => "string", :desc => "the name of the object" }
    end
...
    desc "blah blah", { 
        :params => { 
            :slug => { :type => "string", :desc => "unique id" }
        },
        :object_fields => Api::Entities::Widget.documentation
    } 

@dblock
Copy link
Member

dblock commented Jun 12, 2012

I like this very much. I'm going to let it hang a bit to see if other people would like to comment, in the meantime, could you spend a moment updating changelog and readme around the documentation area? Maybe a section inside "Describing and Inspecting the API" on entities?

@flah00
Copy link
Contributor Author

flah00 commented Jun 12, 2012

Cool! I'll update the readme shortly.

@dblock
Copy link
Member

dblock commented Jun 26, 2012

Very nice, merging. Thx.

dblock added a commit that referenced this pull request Jun 26, 2012
@dblock dblock merged commit 9013459 into ruby-grape:master Jun 26, 2012
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.

2 participants