Skip to content

Commit 6e181f1

Browse files
author
Peter Scholz
committed
Merge remote-tracking branch 'ruby-grape/swagger-2.0'
2 parents 314793d + f57dd80 commit 6e181f1

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

lib/grape-swagger/endpoint.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
module Grape
55
class Endpoint
6+
PRIMITIVE_MAPPINGS = {
7+
'integer' => %w(integer int32),
8+
'long' => %w(integer int64),
9+
'float' => %w(number float),
10+
'double' => %w(number double),
11+
'byte' => %w(string byte),
12+
'date' => %w(string date),
13+
'dateTime' => %w(string date-time)
14+
}.freeze
15+
616
def content_types_for(target_class)
717
content_types = (target_class.content_types || {}).values
818

spec/doc_methods/produces_spec.rb

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
require 'spec_helper'
2+
3+
describe GrapeSwagger::DocMethods::Produces do
4+
describe ":json (default)" do
5+
subject { described_class.call }
6+
7+
specify do
8+
expect(subject).to eql( ['application/json'] )
9+
end
10+
end
11+
12+
describe "accept symbols of" do
13+
describe "single" do
14+
subject { described_class.call(:xml) }
15+
16+
specify do
17+
expect(subject).to eql( ['application/xml'] )
18+
end
19+
end
20+
21+
describe "multiple" do
22+
subject { described_class.call(:xml, :serializable_hash, :json, :binary, :txt) }
23+
24+
specify do
25+
expect(subject).to eql( [
26+
'application/xml',
27+
'application/json',
28+
'application/octet-stream',
29+
'text/plain'
30+
] )
31+
end
32+
end
33+
end
34+
35+
describe "accept mime_types of" do
36+
describe "single" do
37+
subject { described_class.call('application/xml') }
38+
39+
specify do
40+
expect(subject).to eql( ['application/xml'] )
41+
end
42+
end
43+
44+
describe "multiple" do
45+
subject { described_class.call(
46+
'application/xml',
47+
'application/json',
48+
'application/octet-stream',
49+
'text/plain'
50+
) }
51+
52+
specify do
53+
expect(subject).to eql( [
54+
'application/xml',
55+
'application/json',
56+
'application/octet-stream',
57+
'text/plain'
58+
] )
59+
end
60+
end
61+
end
62+
63+
describe "mix it up" do
64+
subject { described_class.call(
65+
:xml,
66+
:serializable_hash,
67+
'application/json',
68+
'application/octet-stream',
69+
:txt
70+
) }
71+
72+
specify do
73+
expect(subject).to eql( [
74+
'application/xml',
75+
'application/json',
76+
'application/octet-stream',
77+
'text/plain'
78+
] )
79+
end
80+
81+
subject { described_class.call( [
82+
:xml,
83+
:serializable_hash,
84+
'application/json',
85+
'application/octet-stream',
86+
:txt
87+
] ) }
88+
89+
specify do
90+
expect(subject).to eql( [
91+
'application/xml',
92+
'application/json',
93+
'application/octet-stream',
94+
'text/plain'
95+
] )
96+
end
97+
end
98+
end

0 commit comments

Comments
 (0)