From f0ef6589537f6f58d0da32150747c1ec02fbed7d Mon Sep 17 00:00:00 2001 From: Tim Vandecasteele Date: Tue, 8 Oct 2013 12:04:19 +0200 Subject: [PATCH] Add spec for multiple documentations. --- CHANGELOG.markdown | 1 + spec/non_default_api_spec.rb | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 9e97a9f..aecd2b4 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -4,6 +4,7 @@ * Adding support for generating swagger responseClass and models from Grape Entities - [@calebwoods](https://github.com/calebwoods). * Adding hidden endpoints - [@arturoherrero](https://github.com/arturoherrero). * Fix: allow urls with `-` - [@dadario](https://github.com/dadario). +* Fix: mounting multiple documentations - [@Drakula2k](https://github.com/Drakula2k). * Your Contribution Here ### 0.6.0 (June 19, 2013) diff --git a/spec/non_default_api_spec.rb b/spec/non_default_api_spec.rb index 43afe73..2328947 100644 --- a/spec/non_default_api_spec.rb +++ b/spec/non_default_api_spec.rb @@ -337,4 +337,59 @@ describe "options: " do end end end + + context "multiple documentations" do + before :all do + class FirstApi < Grape::API + desc 'This is the first API' + get '/first' do + { first: 'hip' } + end + + add_swagger_documentation mount_path: '/first/swagger_doc' + end + + class SecondApi < Grape::API + desc 'This is the second API' + get '/second' do + { second: 'hop' } + end + + add_swagger_documentation mount_path: '/second/swagger_doc' + end + + class SimpleApiWithMultipleMountedDocumentations < Grape::API + mount FirstApi + mount SecondApi + end + end + + def app; SimpleApiWithMultipleMountedDocumentations; end + + it "retrieves the first swagger-documentation on /first/swagger_doc" do + get '/first/swagger_doc.json' + JSON.parse(last_response.body).should == { + "apiVersion" => "0.1", + "swaggerVersion" => "1.1", + "basePath" => "http://example.org", + "operations" => [], + "apis" => [ + { "path" => "/first/swagger_doc/first.{format}" } + ] + } + end + + it "retrieves the first swagger-documentation on /second/swagger_doc" do + get '/second/swagger_doc.json' + JSON.parse(last_response.body).should == { + "apiVersion" => "0.1", + "swaggerVersion" => "1.1", + "basePath" => "http://example.org", + "operations" => [], + "apis" => [ + { "path" => "/second/swagger_doc/second.{format}" } + ] + } + end + end end