|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'swagger spec v2.0' do |
| 6 | + include_context "#{MODEL_PARSER} swagger example" |
| 7 | + |
| 8 | + def app |
| 9 | + Class.new(Grape::API) do |
| 10 | + format :json |
| 11 | + |
| 12 | + desc 'This creates Thing after a delay', |
| 13 | + success: { code: 202, message: 'OK', model: Entities::Something } |
| 14 | + params do |
| 15 | + requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' } |
| 16 | + requires :links, type: Array, documentation: { type: 'link', is_array: true } |
| 17 | + end |
| 18 | + post '/delay_thing' do |
| 19 | + status 202 |
| 20 | + end |
| 21 | + |
| 22 | + version 'v3', using: :path |
| 23 | + add_swagger_documentation openapi_version: '3.0', |
| 24 | + api_version: 'v1', |
| 25 | + base_path: '/api', |
| 26 | + info: { |
| 27 | + title: 'The API title to be displayed on the API homepage.', |
| 28 | + description: 'A description of the API.', |
| 29 | + contact_name: 'Contact name', |
| 30 | + contact_email: '[email protected]', |
| 31 | + contact_url: 'www.The-Contact-URL.org', |
| 32 | + license: 'The name of the license.', |
| 33 | + license_url: 'www.The-URL-of-the-license.org', |
| 34 | + terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com' |
| 35 | + } |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + before do |
| 40 | + get '/v3/swagger_doc' |
| 41 | + end |
| 42 | + |
| 43 | + let(:json) { JSON.parse(last_response.body) } |
| 44 | + |
| 45 | + it 'only returns one response if ignore_defaults is specified' do |
| 46 | + expect(json['paths']['/delay_thing']['post']['responses']).to eq('202' => { |
| 47 | + 'content' => { |
| 48 | + 'application/json' => { |
| 49 | + 'schema' => { |
| 50 | + '$ref' => '#/components/schemas/Something' |
| 51 | + } |
| 52 | + } |
| 53 | + }, 'description' => 'OK' |
| 54 | + }) |
| 55 | + expect(json['paths']['/delay_thing']['post']['responses'].keys).not_to include '201' |
| 56 | + end |
| 57 | +end |
0 commit comments