Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to 1.2 w/ passing tests #75

Merged
merged 34 commits into from
Dec 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
754e820
Removing patch level from .rvmrc
Sep 19, 2013
350e1ab
Include in regex to capture URL with '-' in name
Sep 19, 2013
5a2fbaa
Merge current tim-vandecasteele/master
Oct 16, 2013
14677cf
Removing unexpect END
Oct 16, 2013
9db450d
Fix local test to make equal master forked
Oct 16, 2013
778e160
Including markdown format for params and headers descriptions
Oct 16, 2013
2747bb2
Specific call to get root Entity name.
Oct 17, 2013
a9eee91
Merge branch 'dario/master'
swistaczek Nov 5, 2013
b480d89
Add the ability to set API info (title, description, license, terms a…
mattbeedle Nov 25, 2013
59c9f57
version update
swistaczek Nov 27, 2013
032a831
add stomplets
swistaczek Nov 27, 2013
69994a7
add stomplets
swistaczek Nov 27, 2013
3dc0120
min fix
swistaczek Nov 27, 2013
652464f
fix
swistaczek Nov 27, 2013
1ffde40
fix
swistaczek Nov 27, 2013
1a097b4
fix
swistaczek Nov 27, 2013
41f4330
fix
swistaczek Nov 27, 2013
1d03228
fix
swistaczek Nov 27, 2013
3958a1c
fix
swistaczek Nov 27, 2013
85caf9f
Don't add "info" by default
joelvh Dec 5, 2013
506eb7a
Add "operations" back by default
joelvh Dec 5, 2013
8ba7215
Tests pass
joelvh Dec 5, 2013
9cd9a3d
Ignore .project files
joelvh Dec 5, 2013
391ca11
Removed debugging
joelvh Dec 5, 2013
0e15843
Fixed spelling of "authorizations"
joelvh Dec 6, 2013
61879bb
Renamed "dataType" to "type" for 1.2
joelvh Dec 6, 2013
e240ff2
Renamed "errorResponses" to "responseMessages" for 1.2
joelvh Dec 6, 2013
9d609e0
Added "produces" for 1.2
joelvh Dec 6, 2013
c5269bf
Updated tests for 1.2
joelvh Dec 6, 2013
53c8b45
Merge branch 'api-info' of github.com:mattbeedle/grape-swagger into m…
joelvh Dec 6, 2013
f4782f0
Rename "desc" to "description" for Grape Entities
joelvh Dec 6, 2013
b5b42ab
Fixed "desc" to "description" renaming
joelvh Dec 6, 2013
81bd20a
"notes" should be an empty string by default
joelvh Dec 6, 2013
b107f53
Use the proper default content types for "produces"
joelvh Dec 6, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ test/dummy/.sass-cache
# For MacOS:
#
.DS_Store
.project
275 changes: 177 additions & 98 deletions lib/grape-swagger.rb

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions spec/api_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def app; ModelsApi; end
get '/swagger_doc'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"info" => {},
"produces" => ["application/json"],
"operations" => [],
"apis" => [
{ "path" => "/swagger_doc/something.{format}" },
Expand All @@ -38,34 +40,35 @@ def app; ModelsApi; end
}
end

it "should include response_class when specified" do
it "should include type when specified" do
get '/swagger_doc/something.json'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"resourcePath" => "",
"apis" => [
{ "path" => "/something.{format}",
"operations" => [
{ "notes" => nil,
"responseClass" => "Something",
"summary" => "This gets something.",
"nickname" => "GET-something---format-",
"httpMethod" => "GET",
"parameters" => []
}
]
}
],
"apis" => [{
"path" => "/something.{format}",
"operations" => [{
"produces" => [
"application/json"
],
"notes" => "",
"type" => "Something",
"summary" => "This gets something.",
"nickname" => "GET-something---format-",
"httpMethod" => "GET",
"parameters" => []
}]
}],
"models" => {
"Something" => {
"id" => "Something",
"name" => "Something",
"properties" => {
"text" => {
"type" => "string",
"desc" => "Content of something."
"description" => "Content of something."
}
}
}
Expand Down
102 changes: 81 additions & 21 deletions spec/default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,91 @@

describe "Default API" do

before :all do
class NotAMountedApi < Grape::API
format :json
desc 'This gets something.'
get '/something' do
{ bla: 'something' }
context 'with no additional options' do
before :all do
class NotAMountedApi < Grape::API
format :json
desc 'This gets something.'
get '/something' do
{ bla: 'something' }
end
add_swagger_documentation
end
end

def app; NotAMountedApi; end

it "should document something" do
get '/swagger_doc'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"info" => {},
"produces" => ["application/json"],
"operations" => [],
"apis" => [
{ "path" => "/swagger_doc/something.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end

context "path inside the apis array" do
it "should start with a forward slash" do
get '/swagger_doc'
JSON.parse(last_response.body)['apis'].each do |api|
api['path'].should start_with "/"
end
end
add_swagger_documentation
end
end

def app; NotAMountedApi; end

it "should document something" do
get '/swagger_doc'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"basePath" => "http://example.org",
"operations" => [],
"apis" => [
{ "path" => "/swagger_doc/something.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
context 'with API info' do
before :all do
class ApiInfoTest < Grape::API
format :json
add_swagger_documentation info: {
title: 'My API Title',
description: 'A description of my API',
license: 'Apache 2',
license_url: 'http://test.com',
terms_of_service_url: 'http://terms.com',
contact: 'support@test.com'
}
end
get '/swagger_doc'
end

def app; ApiInfoTest; end

subject do
JSON.parse(last_response.body)['info']
end

it 'should document API title' do
expect(subject['title']).to eql('My API Title')
end

it 'should document API description' do
expect(subject['description']).to eql('A description of my API')
end

it 'should document the license' do
expect(subject['license']).to eql('Apache 2')
end

it 'should document the license url' do
expect(subject['licenseUrl']).to eql('http://test.com')
end

it 'should document the terms of service url' do
expect(subject['termsOfServiceUrl']).to eql('http://terms.com')
end

it 'should document the contact email' do
expect(subject['contact']).to eql('support@test.com')
end
end

end
12 changes: 6 additions & 6 deletions spec/grape-swagger_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class HelperTestAPI < Grape::API
path = "/coolness"
method = "GET"
@api.parse_params(params, path, method).should == [
{ paramType: "query", name: :name, description: "A name", dataType: "String", required: true },
{ paramType: "query", name: :level, description: "", dataType: "String", required: false }
{ paramType: "query", name: :name, description: "A name", type: "String", required: true },
{ paramType: "query", name: :level, description: "", type: "String", required: false }
]
end

Expand All @@ -40,8 +40,8 @@ class HelperTestAPI < Grape::API
path = "/coolness"
method = "POST"
@api.parse_params(params, path, method).should == [
{ paramType: "form", name: :name, description: "A name", dataType: "String", required: true },
{ paramType: "form", name: :level, description: "", dataType: "String", required: false }
{ paramType: "form", name: :name, description: "A name", type: "String", required: true },
{ paramType: "form", name: :level, description: "", type: "String", required: false }
]
end

Expand All @@ -57,7 +57,7 @@ class CustomType
path = "/coolness"
method = "GET"
@api.parse_params(params, path, method).should == [
{ paramType: "query", name: :option, description: "Custom option", dataType: "CustomType", required: false }
{ paramType: "query", name: :option, description: "Custom option", type: "CustomType", required: false }
]
end
end
Expand Down Expand Up @@ -99,7 +99,7 @@ class CustomType
"XAuthToken" => { description: "A required header.", required: true }
}
@api.parse_header_params(params).should == [
{ paramType: "header", name: "XAuthToken", description: "A required header.", dataType: "String", required: true }
{ paramType: "header", name: "XAuthToken", description: "A required header.", type: "String", required: true }
]
end
end
Expand Down
36 changes: 19 additions & 17 deletions spec/hide_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def app; HideApi end
get '/swagger_doc.json'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"info" => {},
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/swagger_doc/simple.{format}" },
Expand Down Expand Up @@ -68,8 +70,10 @@ def app; HideNamespaceApi end
get '/swagger_doc.json'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"info" => {},
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/swagger_doc/simple.{format}" },
Expand All @@ -82,23 +86,21 @@ def app; HideNamespaceApi end
get '/swagger_doc/simple.json'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
"swaggerVersion" => "1.1",
"swaggerVersion" => "1.2",
"basePath" => "http://example.org",
"resourcePath" => "",
"apis" => [
{
"path" => "/simple/show.{format}",
"operations" => [
{
"notes" => nil,
"summary" => "Show this endpoint",
"nickname" => "GET-simple-show---format-",
"httpMethod" => "GET",
"parameters" => []
}
]
}
]
"apis" => [{
"path" => "/simple/show.{format}",
"operations" => [{
"produces" => ["application/xml", "application/json", "text/plain"],
"notes" => nil,
"notes" => "",
"summary" => "Show this endpoint",
"nickname" => "GET-simple-show---format-",
"httpMethod" => "GET",
"parameters" => []
}]
}]
}
end
end
Loading