swagger-docs 0.2.0 → 0.2.1
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 +4 -0
 - data/README.md +5 -0
 - data/lib/swagger/docs/api_declaration_file.rb +6 -1
 - data/lib/swagger/docs/api_declaration_file_metadata.rb +2 -1
 - data/lib/swagger/docs/generator.rb +17 -6
 - data/lib/swagger/docs/version.rb +1 -1
 - data/spec/lib/swagger/docs/api_declaration_file_metadata_spec.rb +9 -16
 - data/spec/lib/swagger/docs/api_declaration_file_spec.rb +2 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c9fdc3f4f644a149fff976af8f32e4a084749d95
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ec345458634e9e25fee45ace966b271d1d8bd273
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 45bb296a5aa61b7b7ecae8eb1706da6483bb7febe4b189f36490203e39732ffc2e0f54271298aec7d1a0d0615eeedc808fa599ce5ff7bab1ba8ed2afb92911c6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 566577465f61ef479399c9ef270f5762905e4b9f173ce2d11d1111a3162ace73621b78b6b39fc489dca7793e7bbb47e301bafb65cf823a3b346d4302f8fe8ded
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -10,6 +10,11 @@ Generates swagger-ui json files for rails apps with APIs. You add the swagger DS 
     | 
|
| 
       10 
10 
     | 
    
         
             
            [gemnasium]: https://gemnasium.com/richhollis/swagger-docs
         
     | 
| 
       11 
11 
     | 
    
         
             
            [coveralls]: https://coveralls.io/r/richhollis/swagger-docs
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
      
 13 
     | 
    
         
            +
            ## Swagger Version Specification Support
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            This project supports elements of the v1.2 swagger specification. It *does not* support the v2 specification. If you are looking for support for the newer specification the please see the [swagger-blocks](https://github.com/fotinakis/swagger-blocks/) project. I don't currently have any plans to add support for v2.0 at this time.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ## Example usage
         
     | 
| 
       13 
18 
     | 
    
         | 
| 
       14 
19 
     | 
    
         
             
            Here is an extract of the DSL from a user controller API class:
         
     | 
| 
       15 
20 
     | 
    
         | 
| 
         @@ -52,6 +52,10 @@ module Swagger 
     | 
|
| 
       52 
52 
     | 
    
         
             
                    normalize_model_properties @models
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
                  def authorizations
         
     | 
| 
      
 56 
     | 
    
         
            +
                    metadata.authorizations
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       55 
59 
     | 
    
         
             
                  private
         
     | 
| 
       56 
60 
     | 
    
         | 
| 
       57 
61 
     | 
    
         
             
                  def build_resource_root_hash
         
     | 
| 
         @@ -61,7 +65,8 @@ module Swagger 
     | 
|
| 
       61 
65 
     | 
    
         
             
                      "basePath" => base_path,
         
     | 
| 
       62 
66 
     | 
    
         
             
                      "resourcePath" => resource_path,
         
     | 
| 
       63 
67 
     | 
    
         
             
                      "apis" => apis,
         
     | 
| 
       64 
     | 
    
         
            -
                      "resourceFilePath" => resource_file_path
         
     | 
| 
      
 68 
     | 
    
         
            +
                      "resourceFilePath" => resource_file_path,
         
     | 
| 
      
 69 
     | 
    
         
            +
                      "authorizations"   => authorizations
         
     | 
| 
       65 
70 
     | 
    
         
             
                    }
         
     | 
| 
       66 
71 
     | 
    
         
             
                  end
         
     | 
| 
       67 
72 
     | 
    
         | 
| 
         @@ -3,7 +3,7 @@ module Swagger 
     | 
|
| 
       3 
3 
     | 
    
         
             
                class ApiDeclarationFileMetadata
         
     | 
| 
       4 
4 
     | 
    
         
             
                  DEFAULT_SWAGGER_VERSION = "1.2"
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  attr_reader :api_version, :path, :base_path, :controller_base_path, :swagger_version, :camelize_model_properties
         
     | 
| 
      
 6 
     | 
    
         
            +
                  attr_reader :api_version, :path, :base_path, :controller_base_path, :swagger_version, :camelize_model_properties, :authorizations
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                  def initialize(api_version, path, base_path, controller_base_path, options={})
         
     | 
| 
       9 
9 
     | 
    
         
             
                    @api_version = api_version
         
     | 
| 
         @@ -12,6 +12,7 @@ module Swagger 
     | 
|
| 
       12 
12 
     | 
    
         
             
                    @controller_base_path = controller_base_path
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @swagger_version = options.fetch(:swagger_version, DEFAULT_SWAGGER_VERSION)
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @camelize_model_properties = options.fetch(:camelize_model_properties, true)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @authorizations = options.fetch(:authorizations, {})
         
     | 
| 
       15 
16 
     | 
    
         
             
                  end
         
     | 
| 
       16 
17 
     | 
    
         
             
                end
         
     | 
| 
       17 
18 
     | 
    
         
             
              end
         
     | 
| 
         @@ -61,7 +61,13 @@ module Swagger 
     | 
|
| 
       61 
61 
     | 
    
         
             
                    end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                    def generate_doc(api_version, settings, config)
         
     | 
| 
       64 
     | 
    
         
            -
                      root = {  
     | 
| 
      
 64 
     | 
    
         
            +
                      root = { 
         
     | 
| 
      
 65 
     | 
    
         
            +
                        "apiVersion" => api_version, 
         
     | 
| 
      
 66 
     | 
    
         
            +
                        "swaggerVersion" => "1.2", 
         
     | 
| 
      
 67 
     | 
    
         
            +
                        "basePath" => settings[:base_path], 
         
     | 
| 
      
 68 
     | 
    
         
            +
                        :apis => [],
         
     | 
| 
      
 69 
     | 
    
         
            +
                        :authorizations => settings[:authorizations]
         
     | 
| 
      
 70 
     | 
    
         
            +
                      }
         
     | 
| 
       65 
71 
     | 
    
         
             
                      results = {:processed => [], :skipped => []}
         
     | 
| 
       66 
72 
     | 
    
         
             
                      resources = []
         
     | 
| 
       67 
73 
     | 
    
         | 
| 
         @@ -159,10 +165,13 @@ module Swagger 
     | 
|
| 
       159 
165 
     | 
    
         
             
                    end
         
     | 
| 
       160 
166 
     | 
    
         | 
| 
       161 
167 
     | 
    
         
             
                    def generate_resource(path, apis, models, settings, root, config)
         
     | 
| 
       162 
     | 
    
         
            -
                      metadata = ApiDeclarationFileMetadata.new( 
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
      
 168 
     | 
    
         
            +
                      metadata = ApiDeclarationFileMetadata.new(
         
     | 
| 
      
 169 
     | 
    
         
            +
                        root["apiVersion"], path, root["basePath"],
         
     | 
| 
      
 170 
     | 
    
         
            +
                        settings[:controller_base_path],
         
     | 
| 
      
 171 
     | 
    
         
            +
                        camelize_model_properties: config.fetch(:camelize_model_properties, true),
         
     | 
| 
      
 172 
     | 
    
         
            +
                        swagger_version: root["swaggerVersion"],
         
     | 
| 
      
 173 
     | 
    
         
            +
                        authorizations: root[:authorizations]
         
     | 
| 
      
 174 
     | 
    
         
            +
                      )
         
     | 
| 
       166 
175 
     | 
    
         
             
                      declaration = ApiDeclarationFile.new(metadata, apis, models)
         
     | 
| 
       167 
176 
     | 
    
         
             
                      declaration.generate_resource
         
     | 
| 
       168 
177 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -210,10 +219,12 @@ module Swagger 
     | 
|
| 
       210 
219 
     | 
    
         
             
                      controller_base_path = trim_leading_slash(config[:controller_base_path] || "")
         
     | 
| 
       211 
220 
     | 
    
         
             
                      base_path += "/#{controller_base_path}" unless controller_base_path.empty?
         
     | 
| 
       212 
221 
     | 
    
         
             
                      api_file_path = config[:api_file_path]
         
     | 
| 
      
 222 
     | 
    
         
            +
                      authorizations = config[:authorizations]
         
     | 
| 
       213 
223 
     | 
    
         
             
                      settings = {
         
     | 
| 
       214 
224 
     | 
    
         
             
                        base_path: base_path,
         
     | 
| 
       215 
225 
     | 
    
         
             
                        controller_base_path: controller_base_path,
         
     | 
| 
       216 
     | 
    
         
            -
                        api_file_path: api_file_path
         
     | 
| 
      
 226 
     | 
    
         
            +
                        api_file_path: api_file_path,
         
     | 
| 
      
 227 
     | 
    
         
            +
                        authorizations: authorizations
         
     | 
| 
       217 
228 
     | 
    
         
             
                      }.freeze
         
     | 
| 
       218 
229 
     | 
    
         
             
                    end
         
     | 
| 
       219 
230 
     | 
    
         | 
    
        data/lib/swagger/docs/version.rb
    CHANGED
    
    
| 
         @@ -5,51 +5,44 @@ describe Swagger::Docs::ApiDeclarationFileMetadata do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              describe "#initialize" do
         
     | 
| 
       6 
6 
     | 
    
         
             
                it "sets the api_version property" do
         
     | 
| 
       7 
7 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
8 
     | 
    
         
             
                  expect(metadata.api_version).to eq("1.0")
         
     | 
| 
       10 
9 
     | 
    
         
             
                end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
10 
     | 
    
         
             
                it "sets the path property" do
         
     | 
| 
       13 
11 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
12 
     | 
    
         
             
                  expect(metadata.path).to eq("path")
         
     | 
| 
       16 
13 
     | 
    
         
             
                end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
14 
     | 
    
         
             
                it "sets the base_path property" do
         
     | 
| 
       19 
15 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
16 
     | 
    
         
             
                  expect(metadata.base_path).to eq("basePath")
         
     | 
| 
       22 
17 
     | 
    
         
             
                end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
18 
     | 
    
         
             
                it "sets the controller_base_path property" do
         
     | 
| 
       25 
19 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
20 
     | 
    
         
             
                  expect(metadata.controller_base_path).to eq("controllerBasePath")
         
     | 
| 
       28 
21 
     | 
    
         
             
                end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
22 
     | 
    
         
             
                it "defaults the swagger_version property to DEFAULT_SWAGGER_VERSION" do
         
     | 
| 
       31 
23 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
24 
     | 
    
         
             
                  expect(metadata.swagger_version).to eq(described_class::DEFAULT_SWAGGER_VERSION)
         
     | 
| 
       34 
25 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
26 
     | 
    
         
             
                it "allows the swagger_version property to be_overriden" do
         
     | 
| 
       37 
27 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath", swagger_version: "2.0")
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
28 
     | 
    
         
             
                  expect(metadata.swagger_version).to eq("2.0")
         
     | 
| 
       40 
29 
     | 
    
         
             
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
30 
     | 
    
         
             
                it "defaults the camelize_model_properties property to true" do
         
     | 
| 
       44 
31 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
32 
     | 
    
         
             
                  expect(metadata.camelize_model_properties).to eq(true)
         
     | 
| 
       47 
33 
     | 
    
         
             
                end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
34 
     | 
    
         
             
                it "allows the camelize_model_properties property to be overidden" do
         
     | 
| 
       50 
35 
     | 
    
         
             
                  metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath", camelize_model_properties: false)
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
36 
     | 
    
         
             
                  expect(metadata.camelize_model_properties).to eq(false)
         
     | 
| 
       53 
37 
     | 
    
         
             
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
                it "defaults the authorizations property to empty hash" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                 metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath")
         
     | 
| 
      
 40 
     | 
    
         
            +
                 expect(metadata.authorizations).to eq({})
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
                it "allows the authorizations property to be overidden" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                 authorizations = {foo: 'bar'}
         
     | 
| 
      
 44 
     | 
    
         
            +
                 metadata = described_class.new("1.0", "path", "basePath", "controllerBasePath", authorizations: authorizations)
         
     | 
| 
      
 45 
     | 
    
         
            +
                 expect(metadata.authorizations).to eq(authorizations)
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
       54 
47 
     | 
    
         
             
              end
         
     | 
| 
       55 
48 
     | 
    
         
             
            end
         
     | 
| 
         @@ -63,7 +63,8 @@ describe Swagger::Docs::ApiDeclarationFile do 
     | 
|
| 
       63 
63 
     | 
    
         
             
                    "apis"=> declaration.apis,
         
     | 
| 
       64 
64 
     | 
    
         
             
                    "resourcePath"=> declaration.resource_path,
         
     | 
| 
       65 
65 
     | 
    
         
             
                    :models=> declaration.models,
         
     | 
| 
       66 
     | 
    
         
            -
                    "resourceFilePath" => declaration.resource_file_path
         
     | 
| 
      
 66 
     | 
    
         
            +
                    "resourceFilePath" => declaration.resource_file_path,
         
     | 
| 
      
 67 
     | 
    
         
            +
                    "authorizations" => {}
         
     | 
| 
       67 
68 
     | 
    
         
             
                  }
         
     | 
| 
       68 
69 
     | 
    
         
             
                  expect(declaration.generate_resource).to eq(expected_response)
         
     | 
| 
       69 
70 
     | 
    
         
             
                end
         
     |