|
1 | | -require 'open_api_import' |
| 1 | +require "open_api_import" |
2 | 2 |
|
3 | 3 | RSpec.describe OpenApiImport do |
| 4 | + describe "#from" do |
| 5 | + it "adds response codes as keys on responses array" do |
| 6 | + file_name = "./spec/fixtures/v2.0/yaml/petstore-simple.yaml" |
| 7 | + File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
| 8 | + OpenApiImport.from file_name, create_method_name: :operation_id |
| 9 | + expect(File.exist?("#{file_name}.rb")).to eq true |
| 10 | + content = File.read("#{file_name}.rb") |
| 11 | + eval(content) |
| 12 | + req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
| 13 | + expect(req.key?(:responses)).to eq true |
| 14 | + expect(req[:responses].class).to eq Hash |
| 15 | + expect(req[:responses].keys).to eq [:'200', :'default'] |
| 16 | + end |
4 | 17 |
|
5 | | - describe '#from' do |
6 | | - |
7 | | - it 'adds response codes as keys on responses array' do |
8 | | - file_name = './spec/fixtures/v2.0/yaml/petstore-simple.yaml' |
9 | | - File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
10 | | - OpenApiImport.from file_name, create_method_name: :operation_id |
11 | | - expect(File.exist?("#{file_name}.rb")).to eq true |
12 | | - content = File.read("#{file_name}.rb") |
13 | | - eval(content) |
14 | | - req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
15 | | - expect(req.key?(:responses)).to eq true |
16 | | - expect(req[:responses].class).to eq Hash |
17 | | - expect(req[:responses].keys).to eq [:'200', :'default'] |
18 | | - end |
19 | | - |
20 | | - it 'adds the message for the response on responses array' do |
21 | | - file_name = './spec/fixtures/v2.0/yaml/petstore-simple.yaml' |
22 | | - File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
23 | | - OpenApiImport.from file_name, create_method_name: :operation_id |
24 | | - expect(File.exist?("#{file_name}.rb")).to eq true |
25 | | - content = File.read("#{file_name}.rb") |
26 | | - eval(content) |
27 | | - req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
28 | | - expect(req[:responses][:'200'].key?(:message)).to eq true |
29 | | - expect(req[:responses][:'200'][:message]).to eq "pet response" |
30 | | - end |
31 | | - |
32 | | - it 'adds the data body for the response on responses array' do |
33 | | - file_name = './spec/fixtures/v2.0/yaml/petstore-simple.yaml' |
34 | | - File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
35 | | - OpenApiImport.from file_name, create_method_name: :operation_id |
36 | | - expect(File.exist?("#{file_name}.rb")).to eq true |
37 | | - content = File.read("#{file_name}.rb") |
38 | | - eval(content) |
39 | | - req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
40 | | - expect(req[:responses][:'200'].key?(:data)).to eq true |
41 | | - data = [{ |
42 | | - name: "string", |
43 | | - tag: "string", |
44 | | - id: 0, |
45 | | - }] |
46 | | - expect(req[:responses][:'200'][:data]).to eq data |
47 | | - end |
48 | | - |
49 | | - |
| 18 | + it "adds the message for the response on responses array" do |
| 19 | + file_name = "./spec/fixtures/v2.0/yaml/petstore-simple.yaml" |
| 20 | + File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
| 21 | + OpenApiImport.from file_name, create_method_name: :operation_id |
| 22 | + expect(File.exist?("#{file_name}.rb")).to eq true |
| 23 | + content = File.read("#{file_name}.rb") |
| 24 | + eval(content) |
| 25 | + req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
| 26 | + expect(req[:responses][:'200'].key?(:message)).to eq true |
| 27 | + expect(req[:responses][:'200'][:message]).to eq "pet response" |
50 | 28 | end |
51 | 29 |
|
| 30 | + it "adds the data body for the response on responses array" do |
| 31 | + file_name = "./spec/fixtures/v2.0/yaml/petstore-simple.yaml" |
| 32 | + File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
| 33 | + OpenApiImport.from file_name, create_method_name: :operation_id |
| 34 | + expect(File.exist?("#{file_name}.rb")).to eq true |
| 35 | + content = File.read("#{file_name}.rb") |
| 36 | + eval(content) |
| 37 | + req = Swagger::SwaggerPetstore::V1_0_0::Root.find_pets |
| 38 | + expect(req[:responses][:'200'].key?(:data)).to eq true |
| 39 | + data = [{ |
| 40 | + name: "string", |
| 41 | + tag: "string", |
| 42 | + id: 0, |
| 43 | + }] |
| 44 | + expect(req[:responses][:'200'][:data]).to eq data |
| 45 | + end |
52 | 46 |
|
| 47 | + it "uses 0.0 as default example for float numbers without explicit example" do |
| 48 | + file_name = "./spec/fixtures/v2.0/yaml/float_response.yaml" |
| 49 | + File.delete("#{file_name}.rb") if File.exist?("#{file_name}.rb") |
| 50 | + OpenApiImport.from file_name, create_method_name: :operation_id |
| 51 | + expect(File.exist?("#{file_name}.rb")).to eq true |
| 52 | + content = File.read("#{file_name}.rb") |
| 53 | + eval(content) |
| 54 | + req = Swagger::FloatApi::V1_0_0::Root.get_resource |
| 55 | + expect(req[:responses][:'200'][:data]).to eq({ |
| 56 | + floatValue: 0.0, |
| 57 | + integerValue: 0, |
| 58 | + }) |
| 59 | + end |
| 60 | + end |
53 | 61 | end |
0 commit comments