grape-swagger 2.0.2 → 2.0.3
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 +9 -1
 - data/UPGRADING.md +9 -0
 - data/lib/grape-swagger/doc_methods/move_params.rb +4 -15
 - data/lib/grape-swagger/doc_methods/parse_params.rb +1 -1
 - data/lib/grape-swagger/rake/oapi_tasks.rb +5 -5
 - data/lib/grape-swagger/version.rb +1 -1
 - data/lib/grape-swagger.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c36235d1ec48b00075496c2d59151a87e42f2b7f34c876db913504a7706c1a70
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0d7aac2f325422f53218257e4cb8e2bef51e73e424a53d88b244c3073c614656
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 13d4c18cf80ce43aedde8a3347be17ebda40fd6e2b56496459226f350e273b31cd6c74d79d75b68e2461d47dd6f0aeaec3080709aebbcf5b6beb9b8162f949bb
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 949ebd6da1fcdb3c398e6070a035f50a9e211ed27a93694b275f5e09a9d1266c675f04f7b1e9583329689fcc9a38fd50cdac8dd6c1de87c486016e63faacce57
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -9,6 +9,15 @@ 
     | 
|
| 
       9 
9 
     | 
    
         
             
            * Your contribution here.
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
            ### 2.0.3 (April 26, 2024)
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            #### Fixes
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            * [#922](https://github.com/ruby-grape/grape-swagger/pull/922): Force request body to be an schema object - [@numbata](https://github.com/numbata)
         
     | 
| 
      
 17 
     | 
    
         
            +
            * [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)
         
     | 
| 
      
 18 
     | 
    
         
            +
            * [#924](https://github.com/ruby-grape/grape-swagger/pull/924): fix: Use mount_path to narrow down urls_for - [@chibicco](https://github.com/chibicco)
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       12 
21 
     | 
    
         
             
            ### 2.0.2 (Februar 2, 2024)
         
     | 
| 
       13 
22 
     | 
    
         | 
| 
       14 
23 
     | 
    
         
             
            #### Fixes
         
     | 
| 
         @@ -72,7 +81,6 @@ 
     | 
|
| 
       72 
81 
     | 
    
         
             
            * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
         
     | 
| 
       73 
82 
     | 
    
         
             
            * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)
         
     | 
| 
       74 
83 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
84 
     | 
    
         
             
            ### 1.4.3 (January 5, 2022)
         
     | 
| 
       77 
85 
     | 
    
         | 
| 
       78 
86 
     | 
    
         
             
            #### Fixes
         
     | 
    
        data/UPGRADING.md
    CHANGED
    
    | 
         @@ -1,5 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ## Upgrading Grape-swagger
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            ### Upgrading to >= x.y.z
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            - Grape-swagger now documents array parameters within an object schema in Swagger. This aligns with grape's JSON structure requirements and ensures the documentation is correct.
         
     | 
| 
      
 6 
     | 
    
         
            +
              - Previously, arrays were documented as standalone arrays, which could be incorrect based on grape's expectations.
         
     | 
| 
      
 7 
     | 
    
         
            +
              - Check your API documentation and update your code or tests that use the old array format.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              Attention: This update may require you to make changes to ensure your API integrations continue to work correctly.
         
     | 
| 
      
 10 
     | 
    
         
            +
              For detailed reasons behind this update, refer to GitHub issue #666.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       3 
12 
     | 
    
         
             
            ### Upgrading to >= 1.5.0
         
     | 
| 
       4 
13 
     | 
    
         | 
| 
       5 
14 
     | 
    
         
             
            - The names generated for body parameter definitions and their references has changed. It'll now include the HTTP action as well as any path parameters.
         
     | 
| 
         @@ -18,8 +18,6 @@ module GrapeSwagger 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                      params_to_move = movable_params(params)
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                      return (params + correct_array_param(params_to_move)) if should_correct_array?(params_to_move)
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
21 
     | 
    
         
             
                      params << parent_definition_of_params(params_to_move, path, route)
         
     | 
| 
       24 
22 
     | 
    
         | 
| 
       25 
23 
     | 
    
         
             
                      params
         
     | 
| 
         @@ -27,21 +25,11 @@ module GrapeSwagger 
     | 
|
| 
       27 
25 
     | 
    
         | 
| 
       28 
26 
     | 
    
         
             
                    private
         
     | 
| 
       29 
27 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                    def should_correct_array?(param)
         
     | 
| 
       31 
     | 
    
         
            -
                      param.length == 1 && param.first[:in] == 'body' && param.first[:type] == 'array'
         
     | 
| 
       32 
     | 
    
         
            -
                    end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                    def correct_array_param(param)
         
     | 
| 
       35 
     | 
    
         
            -
                      param.first[:schema] = { type: param.first.delete(:type), items: param.first.delete(:items) }
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                      param
         
     | 
| 
       38 
     | 
    
         
            -
                    end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
28 
     | 
    
         
             
                    def parent_definition_of_params(params, path, route)
         
     | 
| 
       41 
29 
     | 
    
         
             
                      definition_name = OperationId.build(route, path)
         
     | 
| 
       42 
     | 
    
         
            -
                       
     | 
| 
      
 30 
     | 
    
         
            +
                      # NOTE: Parent definition is always object
         
     | 
| 
      
 31 
     | 
    
         
            +
                      @definitions[definition_name] = object_type
         
     | 
| 
       43 
32 
     | 
    
         
             
                      definition = @definitions[definition_name]
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
33 
     | 
    
         
             
                      move_params_to_new(definition, params)
         
     | 
| 
       46 
34 
     | 
    
         | 
| 
       47 
35 
     | 
    
         
             
                      definition[:description] = route.description if route.try(:description)
         
     | 
| 
         @@ -53,6 +41,7 @@ module GrapeSwagger 
     | 
|
| 
       53 
41 
     | 
    
         
             
                      params, nested_params = params.partition { |x| !x[:name].to_s.include?('[') }
         
     | 
| 
       54 
42 
     | 
    
         
             
                      params.each do |param|
         
     | 
| 
       55 
43 
     | 
    
         
             
                        property = param[:name]
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       56 
45 
     | 
    
         
             
                        param_properties, param_required = build_properties([param])
         
     | 
| 
       57 
46 
     | 
    
         
             
                        add_properties_to_definition(definition, param_properties, param_required)
         
     | 
| 
       58 
47 
     | 
    
         
             
                        related_nested_params, nested_params = nested_params.partition { |x| x[:name].start_with?("#{property}[") }
         
     | 
| 
         @@ -197,7 +186,7 @@ module GrapeSwagger 
     | 
|
| 
       197 
186 
     | 
    
         
             
                    end
         
     | 
| 
       198 
187 
     | 
    
         | 
| 
       199 
188 
     | 
    
         
             
                    def move_methods
         
     | 
| 
       200 
     | 
    
         
            -
                      [:post, :put, :patch, 'POST', 'PUT', 'PATCH']
         
     | 
| 
      
 189 
     | 
    
         
            +
                      [:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
         
     | 
| 
       201 
190 
     | 
    
         
             
                    end
         
     | 
| 
       202 
191 
     | 
    
         | 
| 
       203 
192 
     | 
    
         
             
                    def includes_body_param?(params)
         
     | 
| 
         @@ -70,7 +70,7 @@ module GrapeSwagger 
     | 
|
| 
       70 
70 
     | 
    
         | 
| 
       71 
71 
     | 
    
         
             
                    def document_array_param(value_type, definitions)
         
     | 
| 
       72 
72 
     | 
    
         
             
                      if value_type[:documentation].present?
         
     | 
| 
       73 
     | 
    
         
            -
                        param_type = value_type[:documentation][:param_type]
         
     | 
| 
      
 73 
     | 
    
         
            +
                        param_type = value_type[:documentation][:param_type] || value_type[:documentation][:in]
         
     | 
| 
       74 
74 
     | 
    
         
             
                        doc_type = value_type[:documentation][:type]
         
     | 
| 
       75 
75 
     | 
    
         
             
                        type = DataType.mapping(doc_type) if doc_type && !DataType.request_primitive?(doc_type)
         
     | 
| 
       76 
76 
     | 
    
         
             
                        collection_format = value_type[:documentation][:collectionFormat]
         
     | 
| 
         @@ -63,7 +63,7 @@ module GrapeSwagger 
     | 
|
| 
       63 
63 
     | 
    
         
             
                      resource - if given only for that it would be generated (optional)'
         
     | 
| 
       64 
64 
     | 
    
         
             
                    task validate: :environment do
         
     | 
| 
       65 
65 
     | 
    
         
             
                      # :nocov:
         
     | 
| 
       66 
     | 
    
         
            -
                      ENV 
     | 
| 
      
 66 
     | 
    
         
            +
                      ENV.store('store', 'true')
         
     | 
| 
       67 
67 
     | 
    
         
             
                      ::Rake::Task['oapi:fetch'].invoke
         
     | 
| 
       68 
68 
     | 
    
         
             
                      exit if error?
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
         @@ -95,7 +95,7 @@ module GrapeSwagger 
     | 
|
| 
       95 
95 
     | 
    
         
             
                  def urls_for(api_class)
         
     | 
| 
       96 
96 
     | 
    
         
             
                    api_class.routes
         
     | 
| 
       97 
97 
     | 
    
         
             
                             .map(&:path)
         
     | 
| 
       98 
     | 
    
         
            -
                             . 
     | 
| 
      
 98 
     | 
    
         
            +
                             .grep(/#{GrapeSwagger::DocMethods.class_variable_get(:@@mount_path)}/)
         
     | 
| 
       99 
99 
     | 
    
         
             
                             .reject { |e| e.include?(':name') }
         
     | 
| 
       100 
100 
     | 
    
         
             
                             .map { |e| format_path(e) }
         
     | 
| 
       101 
101 
     | 
    
         
             
                             .map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }
         
     | 
| 
         @@ -108,7 +108,7 @@ module GrapeSwagger 
     | 
|
| 
       108 
108 
     | 
    
         
             
                  end
         
     | 
| 
       109 
109 
     | 
    
         | 
| 
       110 
110 
     | 
    
         
             
                  def save_to_file?
         
     | 
| 
       111 
     | 
    
         
            -
                    ENV 
     | 
| 
      
 111 
     | 
    
         
            +
                    ENV.fetch('store', nil).present? && !error?
         
     | 
| 
       112 
112 
     | 
    
         
             
                  end
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
                  def error?
         
     | 
| 
         @@ -118,10 +118,10 @@ module GrapeSwagger 
     | 
|
| 
       118 
118 
     | 
    
         
             
                  def file(url)
         
     | 
| 
       119 
119 
     | 
    
         
             
                    api_version = url.split('/').last
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                    name = if ENV 
     | 
| 
      
 121 
     | 
    
         
            +
                    name = if ENV.fetch('store', nil) == 'true' || ENV.fetch('store', nil).blank?
         
     | 
| 
       122 
122 
     | 
    
         
             
                             "swagger_doc_#{api_version}.json"
         
     | 
| 
       123 
123 
     | 
    
         
             
                           else
         
     | 
| 
       124 
     | 
    
         
            -
                             ENV 
     | 
| 
      
 124 
     | 
    
         
            +
                             ENV.fetch('store').sub('.json', "_#{api_version}.json")
         
     | 
| 
       125 
125 
     | 
    
         
             
                           end
         
     | 
| 
       126 
126 
     | 
    
         | 
| 
       127 
127 
     | 
    
         
             
                    File.join(Dir.getwd, name)
         
     | 
    
        data/lib/grape-swagger.rb
    CHANGED
    
    | 
         @@ -40,7 +40,7 @@ module SwaggerRouting 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  @target_class.combined_routes[resource] ||= []
         
     | 
| 
       41 
41 
     | 
    
         
             
                  next if doc_klass.hide_documentation_path && route.path.match(/#{doc_klass.mount_path}($|\/|\(\.)/)
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                  @target_class.combined_routes[resource] 
     | 
| 
      
 43 
     | 
    
         
            +
                  @target_class.combined_routes[resource] << route
         
     | 
| 
       44 
44 
     | 
    
         
             
                end
         
     | 
| 
       45 
45 
     | 
    
         
             
              end
         
     | 
| 
       46 
46 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: grape-swagger
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - LeFnord
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire:
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2024- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2024-04-26 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: grape
         
     | 
| 
         @@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       103 
103 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       104 
104 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       105 
105 
     | 
    
         
             
            requirements: []
         
     | 
| 
       106 
     | 
    
         
            -
            rubygems_version: 3.5. 
     | 
| 
      
 106 
     | 
    
         
            +
            rubygems_version: 3.5.9
         
     | 
| 
       107 
107 
     | 
    
         
             
            signing_key:
         
     | 
| 
       108 
108 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       109 
109 
     | 
    
         
             
            summary: Add auto generated documentation to your Grape API that can be displayed
         
     |