esplanade 1.3.0 → 1.4.0

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: ff2aa7471fbccccd7a52e52ba79faa5c181c3fc9
4
- data.tar.gz: 34d21fc0cb3cf09954ce401805076c206508b9d2
3
+ metadata.gz: f025bdf4dd1ab531595638a97e29c752ff806f67
4
+ data.tar.gz: e0fed6c59b1d29d6f093ed56f499ef0671f51214
5
5
  SHA512:
6
- metadata.gz: e4cf2e079c8773cdb0b10241ba8166834ab6b6c03b108273e9b7963efa7d812b8a2a2cc7ba249b7c429fffdb80b0dcf36b5b167665b7fef2e00177568f51a32c
7
- data.tar.gz: 62b6623aa9df749907c7d6dc5e6413103bab3083368cc616140c63b9bb3cd4cdfa596a60c857fef5ab57e40b9e8d7a168a606b421ed8db7c079e640387bc8c7a
6
+ metadata.gz: e54ccff39207044c6cb62e4e58d6d4b4372841a3dad3a2392994b3817074f9bf74ab8c93872992ac0ec2b45dbbb4584ddbec45545cb3d39d29c8d63bb0aace53
7
+ data.tar.gz: 201f34eca6b8e5b351f14aab8734efcf73797e64856d62a6c5872bdcb361c29d53f5bb00f3a02d7908bc61ba2691b574958eb4c49b974bfe0793b6e40581d198
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Change log
2
2
 
3
+ ### 1.4.0 - 2019-08-19
4
+
5
+ * features
6
+ * add details for Esplanade::Response::Error
7
+
3
8
  ### 1.3.0 - 2018-03-16
4
9
 
5
10
  * features
6
- * add Esplanade::Request::ContentTypeIsNotJson erro
11
+ * add Esplanade::Request::ContentTypeIsNotJson error
7
12
  * add reduced version message about request body
8
13
 
9
14
  ### 1.2.1 - 2018-02-20
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Gem Version](https://badge.fury.io/rb/esplanade.svg)](https://badge.fury.io/rb/esplanade)
8
8
  [![Build Status](https://travis-ci.org/funbox/esplanade.svg?branch=master)](https://travis-ci.org/funbox/esplanade)
9
9
 
10
- This gem will help you validation and sinhronize your API in strict accordance to the documentation in
10
+ This gem will help you to validate and synchronize your API in strict accordance to the documentation in
11
11
  [API Blueprint](https://apiblueprint.org/) format.
12
12
  To do this it automatically searches received requestes and responses in the documentation and run validates
13
13
  json-schemas.
data/esplanade.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'esplanade/version'
4
4
 
@@ -6,9 +6,9 @@ module Esplanade
6
6
  class CheckCustomResponseMiddleware
7
7
  def initialize(
8
8
  app,
9
- prefix: Esplanade.configuration.prefix,
10
- apib_path: Esplanade.configuration.apib_path,
11
- drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
9
+ prefix: Esplanade.configuration.prefix,
10
+ apib_path: Esplanade.configuration.apib_path,
11
+ drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
12
12
  )
13
13
  @app = app
14
14
  @documentation = Tomograph::Tomogram.new(
@@ -8,12 +8,14 @@ module Esplanade
8
8
 
9
9
  def tomogram
10
10
  raise PrefixNotMatch, message unless @main_documentation.prefix_match?(@raw.path)
11
+
11
12
  @tomogram = @main_documentation.find_request_with_content_type(
12
13
  method: @raw.method,
13
14
  path: @raw.path,
14
15
  content_type: @raw.content_type
15
16
  )
16
17
  raise NotDocumented, message if @tomogram.nil?
18
+
17
19
  @tomogram
18
20
  end
19
21
 
@@ -11,27 +11,24 @@ module Esplanade
11
11
 
12
12
  def to_string
13
13
  return @string if @string
14
+
14
15
  @string = @env['rack.input'].read
15
16
  @env['rack.input'].rewind
16
17
  @string
17
18
  end
18
19
 
19
20
  def to_hash
20
- @hash ||= if to_string.nil?
21
- {}
22
- else
23
- MultiJson.load(to_string)
24
- end
21
+ @hash ||= MultiJson.load(to_string)
25
22
  rescue MultiJson::ParseError
26
23
  raise BodyIsNotJson, message
27
24
  end
28
25
 
29
26
  def reduced_version
30
- @reduced_version ||= if to_string.size >= 1000
31
- "#{to_string[0..499]}...#{to_string[500..-1]}"
32
- else
33
- to_string
34
- end
27
+ @reduced_version ||= if to_string && to_string.size >= 1000
28
+ "#{to_string[0..499]}...#{to_string[500..-1]}"
29
+ else
30
+ to_string
31
+ end
35
32
  end
36
33
 
37
34
  private
@@ -10,7 +10,8 @@ module Esplanade
10
10
  end
11
11
 
12
12
  def valid!
13
- raise ContentTypeIsNotJson, mini_message unless @doc.content_type == 'application/json'
13
+ raise ContentTypeIsNotJson, mini_message unless @doc.content_type == 'application/json'
14
+
14
15
  @error ||= JSON::Validator.fully_validate(@doc.json_schema, @raw.body.to_hash)
15
16
 
16
17
  raise Invalid, message unless @error.empty?
@@ -21,7 +22,7 @@ module Esplanade
21
22
  def mini_message
22
23
  {
23
24
  method: @doc.method,
24
- path: @doc.path,
25
+ path: @doc.path,
25
26
  content_type: @doc.content_type
26
27
  }
27
28
  end
@@ -29,10 +30,10 @@ module Esplanade
29
30
  def message
30
31
  {
31
32
  method: @raw.method,
32
- path: @raw.path,
33
+ path: @raw.path,
33
34
  content_type: @raw.content_type,
34
- body: @raw.body.to_hash,
35
- error: @error
35
+ body: @raw.body.to_hash,
36
+ error: @error
36
37
  }
37
38
  end
38
39
  end
@@ -1,14 +1,10 @@
1
1
  require 'esplanade/response/doc'
2
2
  require 'esplanade/response/raw'
3
3
  require 'esplanade/response/validation'
4
+ require 'esplanade/response/error'
4
5
 
5
6
  module Esplanade
6
7
  class Response
7
- class Error < Esplanade::Error; end
8
- class NotDocumented < Error; end
9
- class BodyIsNotJson < Error; end
10
- class Invalid < Error; end
11
-
12
8
  attr_reader :request
13
9
 
14
10
  def initialize(request, status, raw_body)
@@ -9,6 +9,7 @@ module Esplanade
9
9
  def tomogram
10
10
  @tomogram ||= @request.doc.responses.find_all { |response| response['status'] == @raw.status }
11
11
  raise NotDocumented, message if @tomogram == []
12
+
12
13
  @tomogram
13
14
  end
14
15
 
@@ -0,0 +1,74 @@
1
+ module Esplanade
2
+ class Response
3
+ class Error < Esplanade::Error; end
4
+
5
+ class NotDocumented < Error
6
+ def initialize(request:, status:)
7
+ @method = request[:method]
8
+ @path = request[:path]
9
+ @status = status
10
+
11
+ super(to_hash)
12
+ end
13
+
14
+ def to_hash
15
+ {
16
+ request:
17
+ {
18
+ method: @method,
19
+ path: @path
20
+ },
21
+ status: @status
22
+ }
23
+ end
24
+ end
25
+
26
+ class BodyIsNotJson < Error
27
+ def initialize(request:, status:, body:)
28
+ @method = request[:method]
29
+ @path = request[:path]
30
+ @status = status
31
+ @body = body
32
+
33
+ super(to_hash)
34
+ end
35
+
36
+ def to_hash
37
+ {
38
+ request:
39
+ {
40
+ method: @method,
41
+ path: @path
42
+ },
43
+ status: @status,
44
+ body: @body
45
+ }
46
+ end
47
+ end
48
+
49
+ class Invalid < Error
50
+ def initialize(request:, status:, body:, error:)
51
+ @method = request[:method]
52
+ @path = request[:path]
53
+ @status = status
54
+ @body = body
55
+ @error = error
56
+
57
+ super(to_hash)
58
+ end
59
+
60
+ def to_hash
61
+ {
62
+ request:
63
+ {
64
+ method: @method,
65
+ path: @path
66
+ },
67
+ status: @status,
68
+ body: @body,
69
+ error: @error
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module Esplanade
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esplanade
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -213,6 +213,7 @@ files:
213
213
  - lib/esplanade/request/validation.rb
214
214
  - lib/esplanade/response.rb
215
215
  - lib/esplanade/response/doc.rb
216
+ - lib/esplanade/response/error.rb
216
217
  - lib/esplanade/response/raw.rb
217
218
  - lib/esplanade/response/raw/body.rb
218
219
  - lib/esplanade/response/validation.rb