Skip to content

Add response examples #675

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
merged 13 commits into from
May 22, 2018
Merged

Add response examples #675

merged 13 commits into from
May 22, 2018

Conversation

gamartin
Copy link
Contributor

@gamartin gamartin commented May 14, 2018

Added support to expose response examples

  • Available only with desc DSL block syntax.
  • Consumer is responsible for generating the example

@gamartin gamartin changed the title Response examples Add response examples May 14, 2018
@coveralls
Copy link

coveralls commented May 14, 2018

Coverage Status

Coverage increased (+1.4%) to 98.613% when pulling b930431 on gamartin:response-examples into 36d3beb on ruby-grape:master.

gamartin added 7 commits May 14, 2018 12:03
lib/grape-swagger/endpoint.rb:7:3: C: Metrics/ClassLength: Class has too many lines. [289/287]
  class Endpoint ...
  ^^^^^^^^^^^^^^
lib/grape-swagger/endpoint.rb:196:5: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for response_object is too high. [14/13]
    def response_object(route) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/grape-swagger/endpoint.rb:196:5: C: Metrics/PerceivedComplexity: Perceived complexity for response_object is too high. [15/14]
    def response_object(route) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -264,6 +261,12 @@ def tag_object(route, path)

private

def build_reference(route, value, response_model)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted this to a method to avoid lint:

lib/grape-swagger/endpoint.rb:196:5: C: Metrics/PerceivedComplexity: Perceived complexity for response_object is too high. [15/14]

@@ -294,9 +297,8 @@ def merge_params(route)
end

def default_type(params)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to inline block to avoid lint:
Class has too many lines

@gamartin
Copy link
Contributor Author

@LeFnord @dblock would you consider this PR?

@LeFnord
Copy link
Member

LeFnord commented May 16, 2018

This PR is very welcome, but can review it, if I can access my machine again … was damaged 😞 – it isn’t so nice via phone 😉 … hope tomorrow

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.

very nice and welcome work …


desc 'This returns examples' do
success model: Entities::UseResponse, examples: { 'application/json' => { description: 'Names list', items: [{ id: '123', name: 'John' }] } }
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }]]
Copy link
Member

Choose a reason for hiding this comment

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

question: is it also possible to use the explicit notation as hash, mean …

failure: [
  {
    code: 400,
    message: 'NotFound',
    model: Entities::ApiError,
    examples:  { 'application/json' => { code: 404, message: 'Not found' }
  }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, added examples and docs for that notation

b930431#diff-e92729f9b6df796f94002a66a1e5b640R21

@LeFnord
Copy link
Member

LeFnord commented May 22, 2018

many thanks @gamartin :)

@LeFnord LeFnord merged commit 9b41652 into ruby-grape:master May 22, 2018
LeFnord pushed a commit to LeFnord/grape-swagger that referenced this pull request Feb 9, 2019
* first try

* tests

* n test

* Update README.md

* Update README.md

* add response examples

* tests

* n test

* Update README.md

* Update README.md

* Addressed lint issues:

lib/grape-swagger/endpoint.rb:7:3: C: Metrics/ClassLength: Class has too many lines. [289/287]
  class Endpoint ...
  ^^^^^^^^^^^^^^
lib/grape-swagger/endpoint.rb:196:5: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for response_object is too high. [14/13]
    def response_object(route) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/grape-swagger/endpoint.rb:196:5: C: Metrics/PerceivedComplexity: Perceived complexity for response_object is too high. [15/14]
    def response_object(route) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^

* added examples for explicit hash notation in failure
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.

3 participants