acos_jekyll_openapi_helper 1.4.4 → 1.6.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/acos_jekyll_openapi.rb +26 -101
  3. metadata +6 -7
  4. data/bin/start.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a40bc0f1850def91fb789ae62bab398bab43f3cc726a32b5ff0392c2b33760a
4
- data.tar.gz: bf8e2c0fa31c6ffef260e92c49594b5a64a79cbf12deb32293814c0524370d85
3
+ metadata.gz: 403ad932887e7f941556a76ef2e1e6b6a889f2bc8e3fb82fe6017a5f0bb8e89c
4
+ data.tar.gz: d72b874f04ec17c65517bacea4d39159c83d2a5141c32dfebaa557491f45c8c1
5
5
  SHA512:
6
- metadata.gz: c4ac0ef5edb9422156548e2881fd5f0058077d98bd26f7d164cc7627189734b0157a737bd19df8ab5dfd83b69ba067c43e88af9e3818a0160eb37896af257031
7
- data.tar.gz: cfd15f06fce7bdcede9032945ace499cd2d7bfe87e8e28d75b982601b178fa33a4ac3716e7010c7f05243d8b358ed90fbe175b964c94fa9e8a931b9ccfca26da
6
+ metadata.gz: 95b4553ff5b42116de09c47a69caae0e755f826b74929fd66295df68f7ca45400d0b35be78d538ee2a7b196bbf383e0f4599cfa0290c776b10739647a07bb45c
7
+ data.tar.gz: d3a64d49e31098a179c8e038bbf597c51c81c33faf72e71202cc1a0f3a44f7b4c8ca7b49453d69897ee16f7b2be23a969bffad653288ab350e91bf126aea72c1
@@ -11,8 +11,16 @@ class AcosOpenApiHelper
11
11
  engine.generate
12
12
  end
13
13
 
14
- def self.generate_pages_from_data(datafolder, basePath, output_path)
14
+ def self.generate_pages_from_data(datafolder, basePath, output_path, only_files = [])
15
15
  json_files = Dir["%s/*.json" % datafolder]
16
+ wanted = Array(only_files).map { |name| File.basename(name.to_s.strip) }.reject(&:empty?)
17
+ unless wanted.empty?
18
+ json_files = json_files.select { |jf| wanted.include?(File.basename(jf)) }
19
+ missing = wanted - json_files.map { |jf| File.basename(jf) }
20
+ unless missing.empty?
21
+ raise "No swagger JSON matched: #{missing.join(', ')} in #{datafolder}"
22
+ end
23
+ end
16
24
  json_files.each do | jf |
17
25
  puts "Generating pages based on: %s" % jf
18
26
  generate_pages(jf, basePath, output_path)
@@ -56,113 +64,21 @@ class AcosOpenApiHelper::PageEngine
56
64
  puts "Open API version %s in .json file" % (@data.key?("openapi") ? @data['openapi'] : @data['swagger'])
57
65
  docTitle = (@data["info"]["title"])
58
66
  _components = @data.key?("components") ? "components" :"definitions"
59
- docFile = docTitle.gsub(/\s+|{|}|\//, "_").downcase
67
+ docFile = docTitle.gsub(/\+|\s+|{|}|\//, "_").downcase
60
68
  puts "Document title : %s" % docTitle
61
69
  sidebar = "%s_sidebar" % docFile
62
- menu = AcosOpenApiHelper::SidebarMenu.new()
63
-
64
- if File.exists?("%s/%s_index.md" % [@output_path, docFile] )
65
- _indexMenu = AcosOpenApiHelper::MenuItem.new("Overview %s " % docTitle, "%s_index" % docFile)
66
- menu.add(_indexMenu)
67
- cnt = cnt + 1
68
- else
69
- puts "No index file found for %s" % docFile
70
- end
71
70
 
72
71
  @data['paths'].each do |path|
73
- _path = path[0] #path of swagger method
74
- _methods = @data['paths'][_path]
75
- #(path, basePath, output_path, swaggerfile, sidebar, docFile, component)
72
+ _path = path[0]
76
73
  writer = AcosOpenApiHelper::PageCreator.new(_path, @basePath, @output_path, @swaggerfile, sidebar, docFile, _components)
77
74
  writer.write
78
- _permalink = AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
79
- _menuItem = AcosOpenApiHelper::MenuItem.new(_path, _permalink)
80
- menu.add(_menuItem)
81
75
  cnt = cnt + 1
82
76
  end
83
- # Adding component page for models
84
- #createComponents(basePath, title, sidebar, swaggerfile, docFile)
85
77
  AcosOpenApiHelper::PageCreator.createComponents(@basePath, docTitle, sidebar, @swaggerfile, docFile, _components)
86
- _componentMenu = AcosOpenApiHelper::MenuItem.new("%s Models" % docTitle, "%s_components" % docFile)
87
- menu.add(_componentMenu)
88
78
  cnt = cnt + 1
89
79
 
90
80
  puts "Done generating %s pages..." % cnt
91
- puts "Writing menu"
92
- menu.write("%s/_data/sidebars" % @basePath, sidebar, docTitle)
93
- end
94
- end
95
-
96
- class AcosOpenApiHelper::SidebarMenu
97
- @@entries = Array.new
98
- #attr_accessor :title, :url
99
-
100
- def self.all_entries
101
- @@entries
102
- end
103
-
104
- def add(entry)
105
- @@entries.push(entry)
106
- end
107
-
108
-
109
- def initialize()
110
- # @title = title
111
- # @url = url
112
- #@@entries << self
113
- end
114
-
115
- def write (output_path, name, menuTitle)
116
- #no spaces in filename ofr sidebar.yml
117
- name = name.gsub(/\s+|{|}|\//, "_").downcase
118
- _standardLines = [
119
- "# THIS PAGE IS GENERATED. ANY CHANGES TO PAGE WILL POTENTIALLY BE OVERWRITTEN.",
120
- "# This is your sidebar TOC. The sidebar code loops through sections here and provides the appropriate formatting.",
121
- "entries:",
122
- "- title: sidebar",
123
- " # product: Documentation",
124
- " # version: 1.0",
125
- " folders:",
126
- " - title: %s" % menuTitle,
127
- " output: web",
128
- " type: frontmatter",
129
- " folderitems: "
130
- ]
131
- puts "Writing menu with length: %s" % @@entries.length
132
- @@entries.each do | item |
133
- #puts "Entry: %s, url: %s" % [item.title, item.url]
134
- _standardLines << " - title: %s" % item.title
135
- _standardLines << " url: /%s.html" % item.url
136
- _standardLines << " output: web, pdf"
137
- end
138
-
139
- # _standardLines << " - title: %s" % "Models"
140
- # _standardLines << " url: /%s.html" % "userapi_components"
141
- # _standardLines << " output: web, pdf"
142
- # File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
143
- # f.puts(@lines)
144
- # end
145
- puts "Writing menu file for %s at %s" % [name, output_path]
146
- File.open("%s/%s.%s" % [output_path, name, "yml"], "w+") do | f |
147
- f.puts(_standardLines)
148
- end
149
-
150
- @@entries.clear
151
- end
152
-
153
- end
154
-
155
- class AcosOpenApiHelper::MenuItem
156
- def initialize(title, url)
157
- @title = title
158
- @url = url
159
- end
160
-
161
- def title
162
- @title
163
- end
164
- def url
165
- @url
81
+ puts "Sidebar is owned by overlay compose; gem does not write sidebar YAML."
166
82
  end
167
83
  end
168
84
 
@@ -170,7 +86,10 @@ class AcosOpenApiHelper::PermalinkGenerator
170
86
  def self.create(path, swaggerfile)
171
87
  @swaggerfileBase = File.basename(swaggerfile, ".*")
172
88
  @permalinkBase = "%s_%s" % [@swaggerfileBase, path]
173
- @permalink = @permalinkBase.gsub(/\s+|{|}|\//, "_").downcase
89
+ @permalink = @permalinkBase.gsub(/\+|\s+|{|}|\//, "_").downcase
90
+ unless @permalink =~ /\A[a-z0-9_-]+\z/
91
+ raise "Unsafe permalink: #{@permalink}"
92
+ end
174
93
  return @permalink
175
94
  end
176
95
 
@@ -183,7 +102,10 @@ end
183
102
  class AcosOpenApiHelper::FileNameGenerator
184
103
  def self.create(path, docFile)
185
104
  @docFileBase = "%s_%s" % [docFile, path]
186
- @docFileName = @docFileBase.gsub(/\s+|{|}|\//, "_").downcase
105
+ @docFileName = @docFileBase.gsub(/\+|\s+|{|}|\//, "_").downcase
106
+ unless @docFileName =~ /\A[a-z0-9_-]+\z/
107
+ raise "Unsafe generated filename: #{@docFileName}"
108
+ end
187
109
  return @docFileName
188
110
  end
189
111
 
@@ -194,7 +116,6 @@ end
194
116
 
195
117
  class AcosOpenApiHelper::PageCreator
196
118
  def initialize(path, basePath, output_path, swaggerfile, sidebar, docFile, component)
197
- # puts "Initialize intput %s, %s, %s, %s" % [path, output_path, swaggerfile, sidebar]
198
119
  @path = path
199
120
  @output_path = output_path
200
121
  @swaggerfile = swaggerfile
@@ -220,7 +141,8 @@ class AcosOpenApiHelper::PageCreator
220
141
  "swagger_components: %s" % component,
221
142
  "components_file: %s" % docFile,
222
143
  "---",
223
- "{\% include swagger_json/get_path.md \%}"
144
+ "{\% include swagger_json/get_path.md \%}",
145
+ "{\% include swagger_json/overlay_slot.md slot=\"after_page\" \%}"
224
146
  ]
225
147
  end
226
148
 
@@ -232,6 +154,9 @@ class AcosOpenApiHelper::PageCreator
232
154
 
233
155
  def self.createComponents(basePath, title, sidebar, swaggerfile, docFile, componentsKey)
234
156
  swaggerfileName = File.basename(swaggerfile, ".*")
157
+ unless docFile =~ /\A[a-z0-9_-]+\z/
158
+ raise "Unsafe generated filename: #{docFile}"
159
+ end
235
160
  contentLines = [
236
161
  "---",
237
162
  "title: %s Models" % title,
@@ -257,4 +182,4 @@ class AcosOpenApiHelper::PageCreator
257
182
  f.puts(contentLines)
258
183
  end
259
184
  end
260
- end
185
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acos_jekyll_openapi_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Acos AS
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-28 00:00:00.000000000 Z
11
+ date: 2026-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -30,13 +30,12 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - bin/start.rb
34
33
  - lib/acos_jekyll_openapi.rb
35
34
  homepage: https://rubygems.org/gems/acos_jekyll_openapi_helper
36
35
  licenses:
37
36
  - MIT
38
37
  metadata: {}
39
- post_install_message:
38
+ post_install_message:
40
39
  rdoc_options: []
41
40
  require_paths:
42
41
  - lib
@@ -51,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
- rubygems_version: 3.0.3
55
- signing_key:
53
+ rubygems_version: 3.4.20
54
+ signing_key:
56
55
  specification_version: 4
57
56
  summary: Open API json file helper
58
57
  test_files: []
data/bin/start.rb DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'acos_jekyll_openapi'
4
- AcosOpenApiHelper.generate_pages_from_data(
5
- "/mnt/c/code/github/Acos.Integration.Documentation/_data/swagger",
6
- "/mnt/c/code/github/Acos.Integration.Documentation",
7
- "/mnt/c/code/github/Acos.Integration.Documentation/pages/swagger"
8
- )