swagger_model 0.4.5 → 0.4.6

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: 3cb3ff5a74100d4be68752e3362d7d87555279c2
4
- data.tar.gz: ea1d7ff34e9e3d1bc6235e82191ed4124b05a1ab
3
+ metadata.gz: a5ec4250155f5596fbfdb895c1fc77431e25f5f4
4
+ data.tar.gz: dcf3da9f4d97070fe08cce538785e8dac2317388
5
5
  SHA512:
6
- metadata.gz: c9990cff7967bfa7ce66928b4e56e8bd763c76475650c6e659b6d45d8a9e3fa56e8a4e69e6491d175aa89a34a495e28a8309536b7a77351ea63162036e3b9dbf
7
- data.tar.gz: f3754297208ebf2396b0b0ec23e7bb4590111ed2f6a0a06c1f2fd668a037ecf077d4f6b7e89bd3efd7af13701a34ccf379e9cb500a25811c8b66f63ae6940934
6
+ metadata.gz: 09134da0a1689dae2551e7afeec93553e8ce9f61124c17839092c198ee0fd828d9602d193026b4932c399d967f01a2f5ed557b07b3e542d6c00f1a27d213bab0
7
+ data.tar.gz: d46e008d49dfc2be4def4223fb2e20e7de85426704346a4812cd9fe917b5196bc139a7dcd6ce9493d730558a5650dcd17ee17f08dfcb011388903cdf56f18144
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagger_model (0.4.5)
4
+ swagger_model (0.4.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -45,4 +45,4 @@ DEPENDENCIES
45
45
  swagger_model!
46
46
 
47
47
  BUNDLED WITH
48
- 1.16.1
48
+ 1.16.4
data/lib/swagger_model.rb CHANGED
@@ -310,6 +310,12 @@ module SwaggerModel
310
310
  obj['required'] = required
311
311
  obj
312
312
  end
313
+ def self.result_to_yaml(result)
314
+ models = {}
315
+ result['models'].each { |key, value| models.merge!(value) }
316
+ data = result['responses'].merge(models)
317
+ data.to_yaml
318
+ end
313
319
  def self.create_from_json(params)
314
320
  response = {}.to_json
315
321
  json_string = params[:json_string]
@@ -329,15 +335,20 @@ module SwaggerModel
329
335
  response_model[response_name]['properties'] = {}
330
336
  model = {}
331
337
 
338
+ # For validate
339
+ modelData = []
340
+
332
341
  # Create response data
333
342
  if response.has_key?('data')
334
343
  data = response['data']
335
344
  case data.class.to_s
336
345
  when 'Hash'
337
346
  m = Model.new(data)
347
+ modelData.push(m)
338
348
  response_model[response_name]['properties']['data'] = m.to_swagger_hash(model)
339
349
  when 'Array'
340
350
  m = Model.new(data.first)
351
+ modelData.push(m)
341
352
  response_model[response_name]['properties']['data'] = {
342
353
  'type' => 'array',
343
354
  'items' => m.to_swagger_hash(model)
@@ -348,6 +359,7 @@ module SwaggerModel
348
359
  # Create included key models but not add included key to response
349
360
  if response.has_key?('included')
350
361
  included = Included.new(response['included'])
362
+ modelData.concat(included.models)
351
363
  included.models_to_swagger_hash(model)
352
364
  end
353
365
 
@@ -388,6 +400,24 @@ module SwaggerModel
388
400
  response_model['ErrorModelMeta'] = ErrorModelMeta.new().to_swagger_hash
389
401
  end
390
402
 
403
+ # validate models
404
+ modelTypes = modelData.map { |e| e.type }
405
+ modelData.each do |m|
406
+ next if m.relationships.nil?
407
+ next if m.relationships.relationships.empty?
408
+ m.relationships.relationships.each do |e|
409
+ next if e['data'].relation.nil?
410
+ type = e['data'].relation.type
411
+ if !modelTypes.include?(type)
412
+ newModel = Model.new({
413
+ 'id' => '',
414
+ 'type' => type
415
+ })
416
+ newModel.to_swagger_hash(model)
417
+ end
418
+ end
419
+ end
420
+
391
421
  # Set required
392
422
  response_model[response_name]['required'] = response_model[response_name]['properties'].keys
393
423
 
@@ -1,6 +1,8 @@
1
1
  module SwaggerModel
2
2
  module SwaggerV2
3
3
  class Included
4
+ attr_accessor :models
5
+
4
6
  def initialize(array)
5
7
  @models = array.map { |e| Model.new(e) }
6
8
  end
@@ -4,11 +4,15 @@ require_relative 'attributes'
4
4
  module SwaggerModel
5
5
  module SwaggerV2
6
6
  class Model
7
+ attr_accessor :relationships, :type
8
+
7
9
  def initialize(hash)
8
10
  @id = hash['id']
9
11
  @type = hash['type']
10
12
  @model_name = ActiveSupport::Inflector.classify(@type.gsub('-', '_'))
11
- @attributes = Attributes.new(hash['attributes'], @model_name)
13
+ if !hash['attributes'].nil?
14
+ @attributes = Attributes.new(hash['attributes'], @model_name)
15
+ end
12
16
  if !hash['relationships'].nil?
13
17
  @relationships = Relationships.new(hash['relationships'])
14
18
  end
@@ -27,11 +31,21 @@ module SwaggerModel
27
31
  'type' => {
28
32
  'type' => 'string',
29
33
  'example' => @type
30
- },
31
- 'attributes' => @attributes.to_swagger_hash(aModel)
32
- }
34
+ }
35
+ },
36
+ 'required' => [
37
+ 'id',
38
+ 'type'
39
+ ]
33
40
  }
34
- hash['properties']['relationships'] = @relationships.to_swagger_hash(aModel, @model_name) unless @relationships.nil?
41
+ unless @attributes.nil?
42
+ hash['properties']['attributes'] = @attributes.to_swagger_hash(aModel)
43
+ hash['required'].push('attributes')
44
+ end
45
+ unless @relationships.nil?
46
+ hash['properties']['relationships'] = @relationships.to_swagger_hash(aModel, @model_name)
47
+ hash['required'].push('relationships')
48
+ end
35
49
  aModel[@model_name] = hash
36
50
 
37
51
  {
@@ -4,6 +4,7 @@ require 'active_support/core_ext'
4
4
  module SwaggerModel
5
5
  module SwaggerV2
6
6
  class Relation
7
+ attr_accessor :type
7
8
  def initialize(hash)
8
9
  @type = hash['type']
9
10
  end
@@ -1,6 +1,7 @@
1
1
  module SwaggerModel
2
2
  module SwaggerV2
3
3
  class RelationData
4
+ attr_accessor :relation
4
5
  def initialize(hash)
5
6
  @relation = Relation.new(hash)
6
7
  end
@@ -3,6 +3,7 @@ require_relative 'relation'
3
3
  module SwaggerModel
4
4
  module SwaggerV2
5
5
  class RelationDataArray
6
+ attr_accessor :relation
6
7
  def initialize(array)
7
8
  if array.size > 0
8
9
  @relation = Relation.new(array.first)
@@ -4,6 +4,8 @@ require_relative 'relation_data_array'
4
4
  module SwaggerModel
5
5
  module SwaggerV2
6
6
  class Relationships
7
+ attr_accessor :relationships
8
+
7
9
  def initialize(hash)
8
10
  @relationships = []
9
11
  hash.keys.each do |key|
@@ -1,3 +1,3 @@
1
1
  module SwaggerModel
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  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.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - marumemomo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-07 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.5.2
118
+ rubygems_version: 2.5.1
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: swagger_model