open_api_import 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -1
- data/bin/open_api_import +65 -0
- data/lib/open_api_import.rb +6 -2
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b391f64d44cb78f95b9e4765f98023d3939752f5802e390fd8b972502061579
|
4
|
+
data.tar.gz: '08f6d8b7427f2dd8251c220314288b7e36cfdad30d89cf5d83e462640a5679cd'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e42c5dbde362282c5385b48d21852166dacb9283f5fd0e19a52a45f001a94a92d85df840c462c87252521b3a70f90bc2a1911b3cf55a787127df35bc6ca177f
|
7
|
+
data.tar.gz: 589ce2df15ad9589fe1900db1a2ff455b7c9e73cd98f07eda7005f79c221f65f2f149bc99ce45246979fe84a5cf993ff2a0809cea481799a99637698c9b57acd
|
data/README.md
CHANGED
@@ -57,7 +57,43 @@ Take in consideration open_api_import gem is using the 'rufo' gem that executes
|
|
57
57
|
|
58
58
|
## Usage
|
59
59
|
|
60
|
-
|
60
|
+
After installation you can run using command line executable or importing from Ruby.
|
61
|
+
|
62
|
+
You have all the json and yaml examples that the Open API project supplies on /spec/fixtures/ folder. To test it you can use any of those ones or your own Swagger or Open API file.
|
63
|
+
|
64
|
+
### Executable
|
65
|
+
|
66
|
+
For help and see the options, run in command line / bash: `open_api_import -h`
|
67
|
+
|
68
|
+
Example:
|
69
|
+
```bash
|
70
|
+
open_api_import ./spec/fixtures/v2.0/yaml/uber.yaml -fp
|
71
|
+
```
|
72
|
+
|
73
|
+
This is the output:
|
74
|
+
|
75
|
+
```
|
76
|
+
Usage: open_api_import [open_api_file] [options]
|
77
|
+
Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses.
|
78
|
+
More info: https://github.com/MarioRuiz/open_api_import
|
79
|
+
|
80
|
+
In case no options supplied:
|
81
|
+
* It will be used the value of operation_id on snake_case for the name of the methods
|
82
|
+
* It will be used the first folder of the path to create the module name
|
83
|
+
-n, --no_responses if you don't want to add the examples of responses in the resultant file.
|
84
|
+
-m, --mock Add the first response on the request as mock_response
|
85
|
+
-p, --path_method it will be used the path and http method to create the method names
|
86
|
+
-o, --operationId_method It will be used the operationId field like it is to create the method names
|
87
|
+
-f, --create_files It will create a file per module
|
88
|
+
-T, --tags_module It will be used the tags key to create the module name
|
89
|
+
-F, --fixed_module all the requests will be under the module Requests
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
### Ruby file
|
94
|
+
Write your ruby code on a file and in command line/bash: `ruby my_file.rb`
|
95
|
+
|
96
|
+
To convert the Swagger or Open API file into a Request Hash:
|
61
97
|
|
62
98
|
```ruby
|
63
99
|
require 'open_api_import'
|
data/bin/open_api_import
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'open_api_import'
|
4
|
+
|
5
|
+
options = {
|
6
|
+
name_for_module: :path
|
7
|
+
}
|
8
|
+
|
9
|
+
optparse = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: open_api_import [open_api_file] [options]\n"
|
11
|
+
opts.banner+= "Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses.\n"
|
12
|
+
opts.banner+= "More info: https://github.com/MarioRuiz/open_api_import\n\n"
|
13
|
+
opts.banner+= "In case no options supplied: \n"
|
14
|
+
opts.banner+= " * It will be used the value of operation_id on snake_case for the name of the methods\n"
|
15
|
+
opts.banner+= " * It will be used the first folder of the path to create the module name\n"
|
16
|
+
|
17
|
+
opts.on("-n", "--no_responses", "if you don't want to add the examples of responses in the resultant file.") do
|
18
|
+
options[:include_responses] = false
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-m", "--mock", "Add the first response on the request as mock_response") do
|
22
|
+
options[:mock_response] = true
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-p", "--path_method", "it will be used the path and http method to create the method names") do
|
26
|
+
options[:create_method_name] = :path
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-o", "--operationId_method", "It will be used the operationId field like it is to create the method names") do
|
30
|
+
options[:create_method_name] = :operationId
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-f", "--create_files", "It will create a file per module") do
|
34
|
+
options[:create_files] = true
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-T", "--tags_module", "It will be used the tags key to create the module name") do
|
38
|
+
options[:name_for_module] = :tags
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-F", "--fixed_module", "all the requests will be under the module Requests") do
|
42
|
+
options[:name_for_module] = :fixed
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
optparse.parse!
|
49
|
+
|
50
|
+
if options.key?(:create_files)
|
51
|
+
if options[:name_for_module] == :path
|
52
|
+
options[:name_for_module] = :path_file
|
53
|
+
elsif options[:name_for_module] == :tags
|
54
|
+
options[:name_for_module] = :tags_file
|
55
|
+
end
|
56
|
+
options.delete(:create_files)
|
57
|
+
end
|
58
|
+
|
59
|
+
filename = ARGV.pop
|
60
|
+
if filename.to_s==''
|
61
|
+
puts optparse
|
62
|
+
puts "** Need to specify at least a file to import."
|
63
|
+
else
|
64
|
+
OpenApiImport.from filename, options
|
65
|
+
end
|
data/lib/open_api_import.rb
CHANGED
@@ -17,7 +17,7 @@ class OpenApiImport
|
|
17
17
|
# path: it will be used the path and http method, for example for a GET on path: /users/list, the method name will be get_users_list
|
18
18
|
# operation_id: it will be used the operationId field but using the snake_case version, for example for listUsers: list_users
|
19
19
|
# operationId: it will be used the operationId field like it is, for example: listUsers
|
20
|
-
# @param name_for_module [Symbol]. (:path, :path_file, :fixed) (default: :path). How the module names will be created.
|
20
|
+
# @param name_for_module [Symbol]. (:path, :path_file, :fixed, :tags, :tags_file) (default: :path). How the module names will be created.
|
21
21
|
# path: It will be used the first folder of the path to create the module name, for example the path /users/list will be in the module Users and all the requests from all modules in the same file.
|
22
22
|
# path_file: It will be used the first folder of the path to create the module name, for example the path /users/list will be in the module Users and each module will be in a new requests file.
|
23
23
|
# tags: It will be used the tags key to create the module name, for example the tags: [users,list] will create the module UsersList and all the requests from all modules in the same file.
|
@@ -443,7 +443,11 @@ class OpenApiImport
|
|
443
443
|
puts message
|
444
444
|
@logger.info message
|
445
445
|
else
|
446
|
-
files
|
446
|
+
unless files.key?(module_requests)
|
447
|
+
files[module_requests] = Array.new
|
448
|
+
end
|
449
|
+
files[module_requests].concat(output) #for the last one
|
450
|
+
|
447
451
|
requires_txt = ""
|
448
452
|
message = "** Generated files that contain the code of the requests after importing the Swagger file: "
|
449
453
|
puts message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_api_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oas_parser
|
@@ -54,16 +54,22 @@ dependencies:
|
|
54
54
|
name: nice_hash
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.9'
|
57
60
|
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
62
|
+
version: 1.9.0
|
60
63
|
type: :runtime
|
61
64
|
prerelease: false
|
62
65
|
version_requirements: !ruby/object:Gem::Requirement
|
63
66
|
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.9'
|
64
70
|
- - ">="
|
65
71
|
- !ruby/object:Gem::Version
|
66
|
-
version: 1.
|
72
|
+
version: 1.9.0
|
67
73
|
- !ruby/object:Gem::Dependency
|
68
74
|
name: rspec
|
69
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +114,8 @@ description: OpenApiImport -- Import a Swagger or Open API file and create a Rub
|
|
108
114
|
Request Hash file including all requests and responses with all the examples. The
|
109
115
|
file can be in JSON or YAML
|
110
116
|
email: marioruizs@gmail.com
|
111
|
-
executables:
|
117
|
+
executables:
|
118
|
+
- open_api_import
|
112
119
|
extensions: []
|
113
120
|
extra_rdoc_files:
|
114
121
|
- LICENSE
|
@@ -117,6 +124,7 @@ files:
|
|
117
124
|
- ".yardopts"
|
118
125
|
- LICENSE
|
119
126
|
- README.md
|
127
|
+
- bin/open_api_import
|
120
128
|
- lib/open_api_import.rb
|
121
129
|
- lib/open_api_import/utils.rb
|
122
130
|
homepage: https://github.com/MarioRuiz/open_api_import
|