esplanade 1.3.0 → 1.4.0
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 +4 -4
 - data/CHANGELOG.md +6 -1
 - data/README.md +1 -1
 - data/esplanade.gemspec +1 -1
 - data/lib/esplanade/middlewares/check_custom_response_middleware.rb +3 -3
 - data/lib/esplanade/request/doc.rb +2 -0
 - data/lib/esplanade/request/raw/body.rb +7 -10
 - data/lib/esplanade/request/validation.rb +6 -5
 - data/lib/esplanade/response.rb +1 -5
 - data/lib/esplanade/response/doc.rb +1 -0
 - data/lib/esplanade/response/error.rb +74 -0
 - data/lib/esplanade/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f025bdf4dd1ab531595638a97e29c752ff806f67
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e0fed6c59b1d29d6f093ed56f499ef0671f51214
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
             
            [](https://badge.fury.io/rb/esplanade)
         
     | 
| 
       8 
8 
     | 
    
         
             
            [](https://travis-ci.org/funbox/esplanade)
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            This gem will help you  
     | 
| 
      
 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
    
    
| 
         @@ -6,9 +6,9 @@ module Esplanade 
     | 
|
| 
       6 
6 
     | 
    
         
             
              class CheckCustomResponseMiddleware
         
     | 
| 
       7 
7 
     | 
    
         
             
                def initialize(
         
     | 
| 
       8 
8 
     | 
    
         
             
                  app,
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 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 ||=  
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
| 
      
 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: 
     | 
| 
      
 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: 
     | 
| 
      
 33 
     | 
    
         
            +
                      path: @raw.path,
         
     | 
| 
       33 
34 
     | 
    
         
             
                      content_type: @raw.content_type,
         
     | 
| 
       34 
     | 
    
         
            -
                      body: 
     | 
| 
       35 
     | 
    
         
            -
                      error: 
     | 
| 
      
 35 
     | 
    
         
            +
                      body: @raw.body.to_hash,
         
     | 
| 
      
 36 
     | 
    
         
            +
                      error: @error
         
     | 
| 
       36 
37 
     | 
    
         
             
                    }
         
     | 
| 
       37 
38 
     | 
    
         
             
                  end
         
     | 
| 
       38 
39 
     | 
    
         
             
                end
         
     | 
    
        data/lib/esplanade/response.rb
    CHANGED
    
    | 
         @@ -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)
         
     | 
| 
         @@ -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
         
     | 
    
        data/lib/esplanade/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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:  
     | 
| 
      
 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
         
     |