|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'hide documentation path' do |
| 6 | + include_context "#{MODEL_PARSER} swagger example" |
| 7 | + |
| 8 | + before :all do |
| 9 | + module TheApi |
| 10 | + class HideDocumentationApi < Grape::API |
| 11 | + format :json |
| 12 | + |
| 13 | + desc 'This returns something', |
| 14 | + params: Entities::UseResponse.documentation, |
| 15 | + failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }] |
| 16 | + params do |
| 17 | + requires :foo, type: Integer |
| 18 | + end |
| 19 | + get '/params_response' do |
| 20 | + { 'declared_params' => declared(params) } |
| 21 | + end |
| 22 | + |
| 23 | + desc 'This returns something', |
| 24 | + entity: Entities::UseResponse, |
| 25 | + failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }] |
| 26 | + get '/entity_response' do |
| 27 | + { 'declared_params' => declared(params) } |
| 28 | + end |
| 29 | + |
| 30 | + desc 'This returns something', |
| 31 | + failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }] |
| 32 | + get '/present_response' do |
| 33 | + foo = OpenStruct.new id: 1, name: 'bar' |
| 34 | + something = OpenStruct.new description: 'something', item: foo |
| 35 | + present :somethings, something, with: Entities::UseResponse |
| 36 | + end |
| 37 | + |
| 38 | + add_swagger_documentation openapi_version: '3.0', hide_documentation_path: false |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + def app |
| 44 | + TheApi::HideDocumentationApi |
| 45 | + end |
| 46 | + |
| 47 | + describe 'shows documentation paths' do |
| 48 | + subject do |
| 49 | + get '/swagger_doc' |
| 50 | + JSON.parse(last_response.body) |
| 51 | + end |
| 52 | + |
| 53 | + specify do |
| 54 | + expect(subject['paths'].keys).to include '/swagger_doc', '/swagger_doc/{name}' |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments