|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'describing versions' do |
| 4 | + describe 'nothings given' do |
| 5 | + def app |
| 6 | + Class.new(Grape::API) do |
| 7 | + desc 'no versions given' |
| 8 | + get '/nothings' do |
| 9 | + { message: 'hello world …'} |
| 10 | + end |
| 11 | + |
| 12 | + add_swagger_documentation format: :json |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + subject do |
| 17 | + get '/swagger_doc' |
| 18 | + JSON.parse(last_response.body , symbolize_names: true) |
| 19 | + end |
| 20 | + |
| 21 | + specify do |
| 22 | + expect(subject).to eql({ |
| 23 | + info: {title: "API title", version: "0.0.1"}, |
| 24 | + swagger: "2.0", |
| 25 | + produces: ["application/xml", "application/json", "application/octet-stream", "text/plain"], |
| 26 | + host: "example.org", |
| 27 | + tags: [{name: "nothings", description: "Operations about nothings"}], |
| 28 | + paths: { |
| 29 | + '/nothings': { |
| 30 | + get: { |
| 31 | + description: "no versions given", |
| 32 | + produces: ["application/json"], |
| 33 | + responses: { |
| 34 | + '200': {description: "no versions given"} |
| 35 | + }, |
| 36 | + tags: ["nothings"], |
| 37 | + operationId: "getNothings" |
| 38 | + }}}}) |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe 'API version given' do |
| 43 | + def app |
| 44 | + Class.new(Grape::API) do |
| 45 | + version 'v2', using: :path |
| 46 | + desc 'api versions given' |
| 47 | + get '/api_version' do |
| 48 | + { message: 'hello world …'} |
| 49 | + end |
| 50 | + |
| 51 | + add_swagger_documentation format: :json |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + subject do |
| 56 | + get '/v2/swagger_doc' |
| 57 | + JSON.parse(last_response.body , symbolize_names: true) |
| 58 | + end |
| 59 | + |
| 60 | + specify do |
| 61 | + expect(subject).to eql({ |
| 62 | + info: {title: "API title", version: "0.0.1"}, |
| 63 | + swagger: "2.0", |
| 64 | + produces: ["application/xml", "application/json", "application/octet-stream", "text/plain"], |
| 65 | + host: "example.org", |
| 66 | + tags: [{name: "api_version", description: "Operations about api_versions"}], |
| 67 | + paths: { |
| 68 | + '/v2/api_version': { |
| 69 | + get: { |
| 70 | + description: "api versions given", |
| 71 | + produces: ["application/json"], |
| 72 | + responses: { |
| 73 | + '200': {description: "api versions given"} |
| 74 | + }, |
| 75 | + tags: ["api_version"], |
| 76 | + operationId: "getV2ApiVersion" |
| 77 | + }}}}) |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + describe 'DOC version given' do |
| 82 | + def app |
| 83 | + Class.new(Grape::API) do |
| 84 | + desc 'doc versions given' |
| 85 | + get '/doc_version' do |
| 86 | + { message: 'hello world …'} |
| 87 | + end |
| 88 | + |
| 89 | + add_swagger_documentation doc_version: '0.0.2' |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + subject do |
| 94 | + get '/swagger_doc' |
| 95 | + JSON.parse(last_response.body , symbolize_names: true) |
| 96 | + end |
| 97 | + |
| 98 | + specify do |
| 99 | + expect(subject).to eql({ |
| 100 | + info: {title: "API title", version: "0.0.2"}, |
| 101 | + swagger: "2.0", |
| 102 | + produces: ["application/xml", "application/json", "application/octet-stream", "text/plain"], |
| 103 | + host: "example.org", |
| 104 | + tags: [{name: "doc_version", description: "Operations about doc_versions"}], |
| 105 | + paths: { |
| 106 | + '/doc_version': { |
| 107 | + get: { |
| 108 | + description: "doc versions given", |
| 109 | + produces: ["application/json"], |
| 110 | + responses: { |
| 111 | + '200': {description: "doc versions given"} |
| 112 | + }, |
| 113 | + tags: ["doc_version"], |
| 114 | + operationId: "getDocVersion" |
| 115 | + }}}}) |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + describe 'both versions given' do |
| 120 | + def app |
| 121 | + Class.new(Grape::API) do |
| 122 | + version :v2, using: :path |
| 123 | + desc 'both versions given' |
| 124 | + get '/both_versions' do |
| 125 | + { message: 'hello world …'} |
| 126 | + end |
| 127 | + |
| 128 | + add_swagger_documentation doc_version: '0.0.2' |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + subject do |
| 133 | + get '/v2/swagger_doc' |
| 134 | + JSON.parse(last_response.body , symbolize_names: true) |
| 135 | + end |
| 136 | + |
| 137 | + specify do |
| 138 | + expect(subject).to eql({ |
| 139 | + info: {title: "API title", version: "0.0.2"}, |
| 140 | + swagger: "2.0", |
| 141 | + produces: ["application/xml", "application/json", "application/octet-stream", "text/plain"], |
| 142 | + host: "example.org", |
| 143 | + tags: [{name: "both_versions", description: "Operations about both_versions"}], |
| 144 | + paths: { |
| 145 | + '/v2/both_versions': { |
| 146 | + get: { |
| 147 | + description: "both versions given", |
| 148 | + produces: ["application/json"], |
| 149 | + responses: { |
| 150 | + '200': {description: "both versions given"} |
| 151 | + }, |
| 152 | + tags: ["both_versions"], |
| 153 | + operationId: "getV2BothVersions" |
| 154 | + }}}}) |
| 155 | + end |
| 156 | + end |
| 157 | +end |
0 commit comments