swagger_model 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5db8605584c6f6c42787bf6629316212236ac785
4
- data.tar.gz: b19bce8c3a190a2058f40723e0a228bf92ee7bad
3
+ metadata.gz: 70a7b07c81b02668f2669f4330cfcfd3df16351d
4
+ data.tar.gz: 3f942dcf8fac1e9ee8b4dbb2bea7bb1ffa2aabaa
5
5
  SHA512:
6
- metadata.gz: cbbd902d7f22ed04c1aa5b6d42e7d5c8ac522994d6bc20e711202fbc9e4ac5e135a235dbea08350d6400b75d7bbb876a667711aa05180062c46dd6bbeca101a8
7
- data.tar.gz: d8989fcf66046ec6f0d07bce910eb2a34eee6119702833f980ad89e37a4a55b57a362f2eb206e11ec950f2556ca71dfff7f526f1d2f5638eb980a14854888c72
6
+ metadata.gz: 88e47d4ef78d6d1d4cdeb755cfcd85365829538eddc72a01b5c3c576edec15141cbad9c51f2f82b3c39caf9de76c95dbf994880fab2fbb0517392dc95329edfe
7
+ data.tar.gz: 80aa617ffee27a101f488bd6f4da8db7efdf644c2c3870fdb7c78b4e980a2aa9169eadbe75eecb6e7af2a20b43fe8150321b2c0864074a45949ab676c7a6df9e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagger_model (0.2.0)
4
+ swagger_model (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,10 +12,24 @@ GEM
12
12
  minitest (~> 5.1)
13
13
  tzinfo (~> 1.1)
14
14
  concurrent-ruby (1.0.5)
15
+ diff-lcs (1.3)
15
16
  i18n (1.0.1)
16
17
  concurrent-ruby (~> 1.0)
17
18
  minitest (5.11.3)
18
19
  rake (10.5.0)
20
+ rspec (3.7.0)
21
+ rspec-core (~> 3.7.0)
22
+ rspec-expectations (~> 3.7.0)
23
+ rspec-mocks (~> 3.7.0)
24
+ rspec-core (3.7.1)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-expectations (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-mocks (3.7.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-support (3.7.1)
19
33
  thread_safe (0.3.6)
20
34
  tzinfo (1.2.5)
21
35
  thread_safe (~> 0.1)
@@ -27,6 +41,7 @@ DEPENDENCIES
27
41
  activesupport (~> 5.2.0)
28
42
  bundler (~> 1.16)
29
43
  rake (~> 10.0)
44
+ rspec
30
45
  swagger_model!
31
46
 
32
47
  BUNDLED WITH
data/README.md CHANGED
@@ -71,7 +71,19 @@ Or install it yourself as:
71
71
  ```ruby
72
72
  require 'swagger_model'
73
73
 
74
- SwaggerModel.create_from_json(json_file_path: 'example/Example.json', output_path: './example/output/')
74
+ json = <<-EOS
75
+ {
76
+ "user": {
77
+ "name": "marumemomo",
78
+ "age": 24
79
+ },
80
+ "message": "hello",
81
+ "created_at": "2018-05-05T20:02:24.000+09:00",
82
+ "updated_at": null
83
+ }
84
+ EOS
85
+
86
+ SwaggerModel.create_from_json(json_string: json, output_path: './example/output/', response_name: "ExampleResponse")
75
87
  ```
76
88
 
77
89
  ## Development
@@ -1,5 +1,5 @@
1
1
  ---
2
- Example:
2
+ ExampleResponse:
3
3
  type: object
4
4
  properties:
5
5
  user:
@@ -1,3 +1,3 @@
1
1
  module SwaggerModel
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/swagger_model.rb CHANGED
@@ -120,16 +120,22 @@ module SwaggerModel
120
120
  obj
121
121
  end
122
122
  def self.create_from_json(params)
123
- json_file_path = params[:json_file_path] || gets
124
- json = open(json_file_path) do |io|
125
- JSON.load(io)
123
+ response = {}.to_json
124
+ json_string = params[:json_string]
125
+ if !json_string.nil?
126
+ response = JSON.load(json_string)
127
+ else
128
+ json_file_path = params[:json_file_path] || gets
129
+ json = open(json_file_path) do |io|
130
+ JSON.load(io)
131
+ end
132
+ response = json
126
133
  end
127
- model_name = params[:model_name] || File.basename(json_file_path, '.json')
128
- response = json
129
- model = {}
130
- model[model_name] = {}
131
- model[model_name]['type'] = "object"
132
- object = parse_object(response, model, model_name)
134
+ response_name = params[:response_name] || gets
135
+ response_model = {}
136
+ response_model[response_name] = {}
137
+ response_model[response_name]['type'] = "object"
138
+ object = parse_object(response, response_model, response_name)
133
139
  properties = object['properties']
134
140
  if properties.has_key?('links')
135
141
  links = {}
@@ -137,21 +143,21 @@ module SwaggerModel
137
143
  properties['links'] = links
138
144
  end
139
145
  if properties.has_key?('meta')
140
- meta_name = model_name + 'Meta'
141
- model[meta_name] = properties['meta']
146
+ meta_name = response_name + 'Meta'
147
+ response_model[meta_name] = properties['meta']
142
148
  meta = {}
143
149
  meta['$ref'] = '#/components/schemas/' + meta_name
144
150
  properties['meta'] = meta
145
151
  end
146
- model[model_name]['properties'] = properties
152
+ response_model[response_name]['properties'] = properties
147
153
  if object['required'].size > 0
148
- model[model_name]['required'] = object['required']
154
+ response_model[response_name]['required'] = object['required']
149
155
  end
150
156
  output_path = params[:output_path] || './'
151
157
  if params[:output_type] == 'json'
152
- File.write(File.join(output_path, "#{model_name}_model.json"), model.to_json)
158
+ File.write(File.join(output_path, "#{response_name}_model.json"), response_model.to_json)
153
159
  else
154
- File.write(File.join(output_path, "#{model_name}_model.yaml"), model.to_yaml)
160
+ File.write(File.join(output_path, "#{response_name}_model.yaml"), response_model.to_yaml)
155
161
  end
156
162
  end
157
163
  end
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "bundler", "~> 1.16"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "activesupport", "~> 5.2.0"
36
+ spec.add_development_dependency "rspec"
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - marumemomo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-28 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 5.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: swagger_model
56
70
  email:
57
71
  - marumemomo@gmail.com
@@ -68,7 +82,7 @@ files:
68
82
  - bin/console
69
83
  - bin/setup
70
84
  - example/Example.json
71
- - example/output/Example_model.yaml
85
+ - example/output/ExampleResponse_model.yaml
72
86
  - lib/swagger_model.rb
73
87
  - lib/swagger_model/version.rb
74
88
  - swagger_model.gemspec