|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +def details |
| 6 | + <<-DETAILS |
| 7 | + # Burgers in Heaven |
| 8 | +
|
| 9 | + > A burger doesn't come for free |
| 10 | +
|
| 11 | + If you want to reserve a burger in heaven, you have to do |
| 12 | + some crazy stuff on earth. |
| 13 | +
|
| 14 | + ``` |
| 15 | + def do_good |
| 16 | + puts 'help people' |
| 17 | + end |
| 18 | + ``` |
| 19 | +
|
| 20 | + * _Will go to Heaven:_ Probably |
| 21 | + * _Will go to Hell:_ Probably not |
| 22 | + DETAILS |
| 23 | +end |
| 24 | + |
| 25 | +describe 'details' do |
| 26 | + describe 'take details as it is' do |
| 27 | + include_context "#{MODEL_PARSER} swagger example" |
| 28 | + |
| 29 | + before :all do |
| 30 | + module TheApi |
| 31 | + class DetailApi < Grape::API |
| 32 | + format :json |
| 33 | + |
| 34 | + desc 'This returns something', |
| 35 | + detail: 'detailed description of the route', |
| 36 | + entity: Entities::UseResponse, |
| 37 | + failure: [{ code: 400, model: Entities::ApiError }] |
| 38 | + get '/use_detail' do |
| 39 | + { 'declared_params' => declared(params) } |
| 40 | + end |
| 41 | + |
| 42 | + desc 'This returns something' do |
| 43 | + detail 'detailed description of the route inside the `desc` block' |
| 44 | + entity Entities::UseResponse |
| 45 | + failure [{ code: 400, model: Entities::ApiError }] |
| 46 | + end |
| 47 | + get '/use_detail_block' do |
| 48 | + { 'declared_params' => declared(params) } |
| 49 | + end |
| 50 | + |
| 51 | + add_swagger_documentation openapi_version: '3.0' |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + def app |
| 57 | + TheApi::DetailApi |
| 58 | + end |
| 59 | + |
| 60 | + subject do |
| 61 | + get '/swagger_doc' |
| 62 | + JSON.parse(last_response.body) |
| 63 | + end |
| 64 | + |
| 65 | + specify do |
| 66 | + expect(subject['paths']['/use_detail']['get']).to include('summary') |
| 67 | + expect(subject['paths']['/use_detail']['get']['summary']).to eql 'This returns something' |
| 68 | + expect(subject['paths']['/use_detail']['get']).to include('description') |
| 69 | + expect(subject['paths']['/use_detail']['get']['description']).to eql 'detailed description of the route' |
| 70 | + end |
| 71 | + |
| 72 | + specify do |
| 73 | + expect(subject['paths']['/use_detail_block']['get']).to include('summary') |
| 74 | + expect(subject['paths']['/use_detail_block']['get']['summary']).to eql 'This returns something' |
| 75 | + expect(subject['paths']['/use_detail_block']['get']).to include('description') |
| 76 | + expect(subject['paths']['/use_detail_block']['get']['description']).to eql 'detailed description of the route inside the `desc` block' |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments