Sha256: 9aca28d21568a3600aa5f0431289da04cd7568f6187f45097ea011de2d95be6b

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'Param example' do
  def app
    Class.new(Grape::API) do
      format :json

      params do
        requires :id, type: Integer, documentation: { example: 123 }
        optional :name, type: String, documentation: { example: 'Person' }
        optional :obj, type: 'Object', documentation: { example: { 'foo' => 'bar' } }
      end

      post '/endpoint_with_examples' do
        { 'declared_params' => declared(params) }
      end

      add_swagger_documentation
    end
  end

  describe 'documentation with parameter examples' do
    subject do
      get '/swagger_doc/endpoint_with_examples'
      JSON.parse(last_response.body)
    end

    let(:parameters) { subject['definitions']['postEndpointWithExamples']['properties'] }

    specify do
      expect(parameters).to eql(
        { 'id' => { 'type' => 'integer', 'format' => 'int32', 'example' => 123 }, 'name' => { 'type' => 'string', 'example' => 'Person' }, 'obj' => { 'type' => 'Object', 'example' => { 'foo' => 'bar' } } }
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitlab-grape-swagger-1.5.0 spec/swagger_v2/params_example_spec.rb