swagger_docs_generator 0.4.0 → 0.5.0.pre.38

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: b1acc55b2ce3bf7a00dd5181f202f40639ee86ae
4
- data.tar.gz: baba1e428c1cf9df4195ff207cda25e94eab922a
3
+ metadata.gz: 99671fbfa13e6100c95d70456f4bd7e68a91665e
4
+ data.tar.gz: a239e809a764c71c7be6951bf9711e1a90b105fb
5
5
  SHA512:
6
- metadata.gz: 93ea4e3b522dcf2d842f20a9a7f90ba809566abe4f1b63d7e93d3942310c2c6b95446402b71957a1c845f3f53ad121aa94e9e4358c945f8bb62d24424ee2eee1
7
- data.tar.gz: ae86e26cf7d4a46915ca71d290c6b929f92bef02da20252bfc9d1cc17ef3fbcd431ac97b43b2cd72ced90eb8fabf84c866c8337395a627577be87b66b051cbc2
6
+ metadata.gz: 9d71ec8f62af085153f19b39f9683926de3373e1316ca2dd9e9511d3895a03275a609122ea5199d8ed891f6cc9c7f1ddfefe3ca14964a7fb61eca8034e153fbb
7
+ data.tar.gz: 07b1283f91640ba7002ab53518e2a8fc57d304afa6708a748f7f15e2b5d8ca8967a3e69e15b272e05d802d452113c7b86755cbddbac0afe8ee8b583f32c4e364
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # :reek:Attribute
4
+ # :reek:TooManyInstanceVariables
4
5
  module SwaggerDocsGenerator
5
6
  # # Configuration to swagger json file
6
7
  #
@@ -18,7 +19,7 @@ module SwaggerDocsGenerator
18
19
  # @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
19
20
  class Configuration
20
21
  # Accessors with default value
21
- attr_accessor :swagger, :cleanning, :base_path, :compress
22
+ attr_accessor :swagger, :cleanning, :base_path, :compress, :sort
22
23
 
23
24
  # Accessors without default value
24
25
  attr_accessor :schemes, :consumes, :produces, :host, :external_docs,
@@ -30,6 +31,7 @@ module SwaggerDocsGenerator
30
31
  @base_path = '/'
31
32
  @cleanning = true
32
33
  @compress = false
34
+ @sort = 'tag'
33
35
  end
34
36
  end
35
37
 
@@ -5,7 +5,7 @@ module SwaggerDocsGenerator
5
5
  # Name to gem
6
6
  GEM = 'swagger_docs_generator'
7
7
  # Version to gem
8
- VERSION = '0.4.0'
8
+ VERSION = '0.5.0'
9
9
  # Authors contributed to gem
10
10
  AUTHORS = ['VAILLANT Jeremy'].freeze
11
11
  # Email to ahuthors
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'swagger_docs_generator/metadata/sort'
4
+
3
5
  module SwaggerDocsGenerator
4
6
  # Parse temporary json files
5
7
  class MetadataJsons
@@ -14,7 +16,7 @@ module SwaggerDocsGenerator
14
16
  @paths[:paths].merge!(read_part_json(file, 'paths'))
15
17
  @tags_array.push read_part_json(file, 'tags')
16
18
  end
17
- hash.merge(@paths).merge(tags: @tags_array)
19
+ hash.merge(sort_paths).merge(tags: @tags_array)
18
20
  end
19
21
 
20
22
  private
@@ -28,5 +30,15 @@ module SwaggerDocsGenerator
28
30
  def read_part_json(file, key)
29
31
  JSON.parse(File.read(file))[key]
30
32
  end
33
+
34
+ def sort_paths
35
+ order = Sort.new(@paths)
36
+ case SwaggerDocsGenerator.configure.sort
37
+ when 'path' then order.sort_by_path
38
+ when 'tag' then order.sort_by_tag
39
+ else
40
+ @paths
41
+ end
42
+ end
31
43
  end
32
44
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:FeatureEnvy
4
+
5
+ module SwaggerDocsGenerator
6
+ # Sort routes in hash before writing in JSON file
7
+ class Sort
8
+ def initialize(hash)
9
+ @routes = hash
10
+ @readme = { README: @routes[:paths]['README'] }
11
+ end
12
+
13
+ # Sort routes by path
14
+ def sort_by_path
15
+ by_path = Hash[@routes[:paths].sort]
16
+ place_readme_first(by_path)
17
+ end
18
+
19
+ # Sort routes by tags
20
+ def sort_by_tag
21
+ by_tag = Hash[@routes[:paths].sort_by do |_key, value|
22
+ value.first[1]['tags']
23
+ end]
24
+ place_readme_first(by_tag)
25
+ end
26
+
27
+ private
28
+
29
+ def place_readme_first(hash)
30
+ if hash.key?('README')
31
+ hash.delete('README')
32
+ { paths: @readme.merge!(hash) }
33
+ else
34
+ { paths: hash }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -26,8 +26,15 @@ module SwaggerDocsGenerator
26
26
  parse.adding_definition
27
27
  end
28
28
 
29
+ # Create section for display a README in top to documentation
30
+ def swagger_readme(readme_file)
31
+ parse = ParserReadme.new(readme_file)
32
+ parse.adding_readme
33
+ end
34
+
29
35
  alias scontroller swagger_controller
30
36
  alias sdoc swagger_doc
31
37
  alias sdefinition swagger_definition
38
+ alias sreadme swagger_readme
32
39
  end
33
40
  end
@@ -44,7 +44,7 @@ module SwaggerDocsGenerator
44
44
  keys_new = hash.keys[0]
45
45
  paths = hash.keys.split.first
46
46
 
47
- test_tags(paths, hash)
47
+ # test_tags(paths, hash)
48
48
  merge_hashes(old_route, keys_new.to_s, paths, hash)
49
49
  end
50
50
 
@@ -41,3 +41,4 @@ end
41
41
  require 'swagger_docs_generator/parser/controller'
42
42
  require 'swagger_docs_generator/parser/action'
43
43
  require 'swagger_docs_generator/parser/definition'
44
+ require 'swagger_docs_generator/parser/readme'
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SwaggerDocsGenerator
4
+ # # Parse Readme information
5
+ #
6
+ # Parse block code for display basic information for this API Doc
7
+ class ParserReadme < Parser
8
+ def initialize(readme_file)
9
+ @tag_name = 'README'
10
+ @readme = readme_file
11
+ create_file
12
+ end
13
+
14
+ def adding_readme
15
+ json = JSON.parse(File.read(temporary_file))
16
+ File.open(temporary_file, 'w') do |file|
17
+ json['paths'].merge!(complete_path)
18
+ json['tags'].merge!(complete_tag)
19
+ file.puts(JSON.pretty_generate(json))
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def complete_path
26
+ {
27
+ @tag_name => {
28
+ get: {
29
+ summary: 'Introduction',
30
+ description: @readme,
31
+ tags: [@tag_name]
32
+ }
33
+ }
34
+ }
35
+ end
36
+
37
+ def complete_tag
38
+ {
39
+ name: @tag_name,
40
+ description: 'Display basic information to this API documentation'
41
+ }
42
+ end
43
+
44
+ def create_file
45
+ File.delete(temporary_file) if File.exist?(temporary_file)
46
+ base_file = { paths: {}, tags: {}, definitions: {} }
47
+ File.open(temporary_file, 'a+') { |file| file.puts(base_file.to_json) }
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_docs_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0.pre.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -255,6 +255,7 @@ files:
255
255
  - lib/swagger_docs_generator/metadata/info.rb
256
256
  - lib/swagger_docs_generator/metadata/jsons.rb
257
257
  - lib/swagger_docs_generator/metadata/metadata.rb
258
+ - lib/swagger_docs_generator/metadata/sort.rb
258
259
  - lib/swagger_docs_generator/methods.rb
259
260
  - lib/swagger_docs_generator/models/active_record.rb
260
261
  - lib/swagger_docs_generator/models/mongo.rb
@@ -272,6 +273,7 @@ files:
272
273
  - lib/swagger_docs_generator/parser/definition.rb
273
274
  - lib/swagger_docs_generator/parser/model.rb
274
275
  - lib/swagger_docs_generator/parser/parser.rb
276
+ - lib/swagger_docs_generator/parser/readme.rb
275
277
  - lib/swagger_docs_generator/parser/sub_definition.rb
276
278
  - lib/swagger_docs_generator/railtie.rb
277
279
  - lib/tasks/swagger.rake
@@ -326,9 +328,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
326
328
  version: '0'
327
329
  required_rubygems_version: !ruby/object:Gem::Requirement
328
330
  requirements:
329
- - - ">="
331
+ - - ">"
330
332
  - !ruby/object:Gem::Version
331
- version: '0'
333
+ version: 1.3.1
332
334
  requirements: []
333
335
  rubyforge_project:
334
336
  rubygems_version: 2.4.5