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

Addes support for enum values in entity documentation and form parameters #132

Merged
merged 2 commits into from
Jul 30, 2014

Conversation

antek-drzewiecki
Copy link
Contributor

Grape supports has a value restrictions trough arrays or Proc. Swagger UI supports form parameter restrictions trough the enum field. You can also document an entity enum values with the enum field in Swagger UI. This push request adds parameter value integration between Grape (Entity) and Swagger UI.

Usage:

class Status < Grape::Entity
  expose :text, documentation: { type: 'string', desc: 'Status update text.' }
  expose :links, using: Link, documentation: { type: 'link', is_array: true }
  expose :numbers, documentation: { type: 'integer', desc: 'favourite number', values: [1,2,3,4] } 
end

desc 'Creates a new status', entity: API::Entities::Status, params: API::Entities::Status.documentation
post '/statuses' do
        ...
end

desc 'Creates a new status', entity: API::Entities::Status 
params do
   required :numbers , type: Integer, values:[1,2,3]
   ...
end
post '/statuses' do
  ...
end 

@antek-drzewiecki
Copy link
Contributor Author

This has effect on Swagger UI that the parameter number now gets an select drop down box with values 1 , 2 , 3 in it and the entity documentation shows all enum values before the parameter description.

@@ -13,6 +13,7 @@
* [#126](https://github.com/tim-vandecasteele/grape-swagger/pull/126): Rewritten demo in the `test` folder with CORS enabled - [@dblock](https://github.com/dblock).
* [#127](https://github.com/tim-vandecasteele/grape-swagger/pull/127): Fixed `undefined method 'reject' for nil:NilClass` error for an invalid route, now returning 404 Not Found - [@dblock](https://github.com/dblock).
* [#128](https://github.com/tim-vandecasteele/grape-swagger/pull/128): Combine global models and endpoint entities - [@dspaeth-faber](https://github.com/dspaeth-faber).
* [#132](https://github.com/tim-vandecasteele/grape-swagger/pull/132): Addes support for enum values in entity documentation and form parameters - [@Antek-drzewiecki](https://github.com/Antek-drzewiecki)
Copy link
Member

Choose a reason for hiding this comment

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

Missing a period at the end ;)

@dblock
Copy link
Member

dblock commented Jul 30, 2014

This is good. Can you please amend the few small things noted above.

@antek-drzewiecki
Copy link
Contributor Author

@dblock , done thanks for the feedback.

@@ -10,6 +10,13 @@ class Something < Grape::Entity
end

module Entities
class EnumValues < Grape::Entity
expose :gender, documentation: { type: 'string', desc: 'Content of something.', values: %w(Male Female) }
Copy link
Member

Choose a reason for hiding this comment

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

Btw, if you're going to use this in a production API, please do allow other genders than 'male' and 'female', for once facebook did it right :)

@dblock
Copy link
Member

dblock commented Jul 30, 2014

Great, merging.

dblock added a commit that referenced this pull request Jul 30, 2014
Addes support for enum values in entity documentation and form parameters
@dblock dblock merged commit b6d10f3 into ruby-grape:master Jul 30, 2014
@antek-drzewiecki antek-drzewiecki mentioned this pull request Jul 31, 2014
antek-drzewiecki pushed a commit to antek-drzewiecki/grape-swagger that referenced this pull request Aug 14, 2014
…anged throw of StandardError to ArgumentError.
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