api_schema 0.1.2 → 0.1.3

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: b9f9615b4b22de2c2cb6dfa280bb272a67c31c49
4
- data.tar.gz: 7c21d543d28d7f9a87fa517f32c298c3faf53f01
3
+ metadata.gz: 3c1107551e7ed1520bba3597273977a97dcc3403
4
+ data.tar.gz: 989b92b544a4ac765456010a52e19070385bd39b
5
5
  SHA512:
6
- metadata.gz: 99014c93602f61c8c1beb85c9fad1303c38b686f66facde75cb7cdd313b42567a123b3c7d035f53affc5cffaf2f9de0f546df0e6281043a8bf56b09c6fc00b7c
7
- data.tar.gz: acf2bf69a52e23564a0f62e8bb0364078d0cfbb0e0014d116979d8cd624a2daf13465319506569afa11638a51323de0d5c9c4f2aa2762c866a1dfdce797f612d
6
+ metadata.gz: b06b88aa9b4490e6751978ed85ce84c2072d62c78a0a3aeae5908966a9f94d251d8fa73be1acfe546c2830af9587994cdd1ac8e7ad774a872df95ce7ea4a852a
7
+ data.tar.gz: 3ae635ef41a88bbf511e483dbbe9a88ff7a09b73e68043e8bf74e680b0adde4cfe895890b2bddb31bdfc6caa37d8427982701e239b9e3d393445a0935ce129f6
data/README.md CHANGED
@@ -23,8 +23,9 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- Just add `include ApiSchema` and configurations to your base class and inherit from it.
27
- To generate json use `BaseDocs.generate_json` method.
26
+ Just add `include ApiSchema` and configurations to your base class and inherit from it. You also should define your default `:error_model`
27
+
28
+ **To generate json use `BaseDocs.generate_json` method.**
28
29
 
29
30
  #### BaseDocs
30
31
 
@@ -52,6 +53,11 @@ module V1
52
53
  '422' => "Unprocessable Entity"
53
54
  }
54
55
  end
56
+
57
+ serializer :error_model do |f|
58
+ f.integer :code, required: true
59
+ f.string :message, required: true
60
+ end
55
61
  end
56
62
  end
57
63
  ```
@@ -2,7 +2,7 @@ module ApiSchema
2
2
  class ResourceDefinition
3
3
  include ::Swagger::Blocks::ClassMethods
4
4
 
5
- @@neighbors = {}
5
+ @neighbors = {}
6
6
 
7
7
  def initialize(method, base_path, extra_path = nil)
8
8
  @base_path = base_path
@@ -21,6 +21,10 @@ module ApiSchema
21
21
  :path_params, :query_params, :resp,
22
22
  :errors, :base_path, :extra_path, :full_path
23
23
 
24
+ def self.neighbors
25
+ @neighbors
26
+ end
27
+
24
28
  def name(name)
25
29
  @summary = name
26
30
  end
@@ -75,8 +79,8 @@ module ApiSchema
75
79
 
76
80
  def build_neighbors
77
81
  generate_full_path
78
- @@neighbors[full_path] ||= []
79
- @@neighbors[full_path] << self
82
+ self.class.neighbors[full_path] ||= []
83
+ self.class.neighbors[full_path] << self
80
84
  end
81
85
 
82
86
  def build
@@ -88,9 +92,9 @@ module ApiSchema
88
92
  '422' => "Unprocessable Entity"
89
93
  }
90
94
  resource = self
91
-
95
+ resource_class = self.class
92
96
  swagger_path resource.full_path do
93
- @@neighbors[resource.full_path].each do |r|
97
+ resource_class.neighbors[resource.full_path].each do |r|
94
98
  operation(r.method) do
95
99
  key :summary, r.summary
96
100
  key :description, r.description
@@ -1,21 +1,27 @@
1
1
  module ApiSchema
2
2
  module RootMethods
3
+
4
+ def inherited(subclass)
5
+ instance_var = "@api_version"
6
+ subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
7
+ end
8
+
3
9
  def configure
4
- configuration ||= Configuration.new
10
+ configuration = Configuration.new
5
11
  yield(configuration)
6
- @@api_version = ApiVersion.new(configuration)
12
+ @api_version = ApiVersion.new(configuration)
7
13
  end
8
14
 
9
15
  def api_version
10
- @@api_version
16
+ @api_version
11
17
  end
12
18
 
13
19
  def generate_json
14
- @@api_version.configuration.build
15
- @@api_version.serializers.each { |s| s.build }
16
- @@api_version.resources.each { |r| r.build }
20
+ @api_version.configuration.build
21
+ @api_version.serializers.each { |s| s.build }
22
+ @api_version.resources.each { |r| r.build }
17
23
 
18
- nodes = [@@api_version.configuration] + @@api_version.serializers + @@api_version.resources
24
+ nodes = [@api_version.configuration] + @api_version.serializers + @api_version.resources
19
25
  ::Swagger::Blocks.build_root_json(nodes)
20
26
  end
21
27
  end
@@ -2,7 +2,7 @@ module ApiSchema
2
2
  class SerializerDefinition
3
3
  include ::Swagger::Blocks::ClassMethods
4
4
 
5
- @@serializers = {}
5
+ @serializers = {}
6
6
 
7
7
  PriorReference = ::Struct.new(:id, :type, :desc)
8
8
 
@@ -13,11 +13,15 @@ module ApiSchema
13
13
  @id = id
14
14
  @type = type
15
15
  @name = name || id
16
- @parent = @@serializers[parent_id]
16
+ @parent = self.class.serializers[parent_id]
17
17
  @fields = parent&.fields || []
18
18
  @prior_references = parent&.prior_references || []
19
19
  @references = []
20
- @@serializers[id] = self
20
+ self.class.serializers[id] = self
21
+ end
22
+
23
+ def self.serializers
24
+ @serializers
21
25
  end
22
26
 
23
27
  def required_fields
@@ -36,7 +40,7 @@ module ApiSchema
36
40
 
37
41
  def build_references
38
42
  @prior_references.each do |pr|
39
- reference = @@serializers[pr.id].clone
43
+ reference = self.class.serializers[pr.id].clone
40
44
  reference.type = pr.type
41
45
  reference.description = pr.desc
42
46
  reference.name = reference.name.to_s.pluralize if reference.type == :array
@@ -1,3 +1,3 @@
1
1
  module ApiSchema
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Chopey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport