api_schema 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cff8687bdc853cb34bb933797a9b4a473e4bca9
4
- data.tar.gz: 35d16cbfe9164e5543036d281d16986bd7e8b2be
3
+ metadata.gz: 759b1621326cb4e389d1d206caa8b46bdaca8ab5
4
+ data.tar.gz: 77d40d48136c9cc920b7144f8c0c14f5aa477456
5
5
  SHA512:
6
- metadata.gz: 9855664484e98ae0b87980d844530ddde94efb0223fcc6f54e081a0fef7ea10afbba24cb3ea1a749a6036e58e8cc90500903a84a2c9b07f1449f16b62bb07d49
7
- data.tar.gz: bc7d283475496e8c355250a6ee14154cb23c8ce2447b243f52d167812ae701012827758d1f2b1fcd08eeb34c3e3d0262b66997814b1f503a688f306d4425cbea
6
+ metadata.gz: da31dd7f8468d0837dbf581d8076ae54f48ba3e834b74507a48d224d1994f9d6c4b1b7b03cb42072bb629b9444334326a8a3d493c929c64b002e73e2f63cc18b
7
+ data.tar.gz: 02e0d8027769603ed3ec147d14c03750bd8abe001bbd69dd617ed110f62a549c76437377cac98c04273e0955d5f9a601e3e928df132905b2a5e8dee0ea959e0b
@@ -6,8 +6,6 @@ module ApiSchema
6
6
  subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
7
7
  instance_var_neighbors = "@version_resources"
8
8
  subclass.instance_variable_set(instance_var_neighbors, instance_variable_get(instance_var_neighbors))
9
- instance_var_neighbors = "@version_serializers"
10
- subclass.instance_variable_set(instance_var_neighbors, instance_variable_get(instance_var_neighbors))
11
9
  end
12
10
 
13
11
  def configure
@@ -37,11 +35,8 @@ module ApiSchema
37
35
 
38
36
  def generate_json
39
37
  @api_version.configuration.build
40
- @api_version.serializers.each { |s| s.build_references(version_serializers) }
41
-
42
38
  @api_version.check_consistency
43
-
44
- @api_version.serializers.each { |s| s.build(version_serializers) }
39
+ @api_version.serializers.each { |s| s.build }
45
40
  @api_version.resources.each { |r| r.build(version_resources) }
46
41
 
47
42
  nodes = [@api_version.configuration] + @api_version.serializers + @api_version.resources
@@ -4,19 +4,18 @@ module ApiSchema
4
4
 
5
5
  PriorReference = ::Struct.new(:id, :type, :desc)
6
6
 
7
- attr_reader :id, :fields, :references, :parent
7
+ attr_reader :id, :fields, :references, :parent, :api_version
8
8
  attr_accessor :type, :name, :description, :prior_references
9
9
 
10
- def initialize(id, type, serializers, name=nil, parent_id = nil)
10
+ def initialize(id, type, api_version, name=nil, parent_id = nil)
11
11
  @id = id
12
12
  @type = type
13
13
  @name = name || id
14
- @parent = serializers[parent_id]
14
+ @api_version = api_version
15
+ @parent = api_version.serializers.detect { |s| s.id == parent_id } if parent_id
15
16
  @fields = parent&.fields || []
16
17
  @prior_references = parent&.prior_references || []
17
18
  @references = []
18
-
19
- serializers[id] = self
20
19
  end
21
20
 
22
21
  def required_fields
@@ -27,16 +26,15 @@ module ApiSchema
27
26
  @prior_references << PriorReference.new(refernce_id, type, desc)
28
27
  end
29
28
 
30
- def build(serializers)
31
- build_references(serializers)
29
+ def build
30
+ build_references
32
31
  sd = self
33
32
  swagger_schema(id) { schema_for(sd) }
34
33
  end
35
34
 
36
- def build_references(serializers)
35
+ def build_references
37
36
  @prior_references.each do |pr|
38
- raise "Model #{pr.id} is not defined" unless serializers[pr.id]
39
- reference = serializers[pr.id].clone
37
+ reference = api_version.serializers.detect { |s| s.id == pr.id }
40
38
  reference.type = pr.type
41
39
  reference.description = pr.desc
42
40
  reference.name = reference.name.to_s.pluralize if reference.type == :array
@@ -4,13 +4,13 @@ module ApiSchema
4
4
  private
5
5
 
6
6
  def serializer(id, structure: :object, name: nil, parent: nil)
7
- serializer = SerializerDefinition.new(id, structure, version_serializers, name, parent)
7
+ serializer = SerializerDefinition.new(id, structure, api_version, name, parent)
8
8
  yield serializer if block_given?
9
9
  api_version.serializers << serializer
10
10
  end
11
11
 
12
12
  def array_serializer(id, name: nil, parent: nil)
13
- serializer = SerializerDefinition.new(id, :array, version_serializers, name, parent)
13
+ serializer = SerializerDefinition.new(id, :array, api_version, name, parent)
14
14
  yield serializer if block_given?
15
15
  api_version.serializers << serializer
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module ApiSchema
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Chopey