acos_jekyll_openapi_helper 1.2.0 → 1.4.5

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
  SHA256:
3
- metadata.gz: 379d31b769f0d185b71695e2e84022303c7db8593f8514ece50ff643af76bc48
4
- data.tar.gz: 60ae793d36db87efa0c18e131a3af1473ad118d4ef94269f60ef9aace0974899
3
+ metadata.gz: e14565e520d910b4fb71d19d57b32315fdf2ea1592a932fe98c12c8c0e0362fe
4
+ data.tar.gz: 87e9f0168e68274c41387e1148fa9e60371ff10e15300ca05fde77f2534b5a16
5
5
  SHA512:
6
- metadata.gz: f60c5bed27fb06a1f58d409bf558472c5bc62b5d13420b793a8df804152d951cd65d6ab565cc8162d15f4b5aa677e223b10764ada92218414b99b66e8b354c79
7
- data.tar.gz: 53c6359dafde8abd8c34aa10b72c5285f19f9de4f7bbadb0deb06d98299f7ff8ee74100990407c390776f1450be4560f7c749306866a94a0c659cf4ffa66a7d8
6
+ metadata.gz: f2b31b4d1e8c4fb37cccaa3924fb1a15341b39bed0d71c9996cb4396f6f151071e188f0d56635d6ddb708669ff2f59aa00e36d8176c3ffcd8686aa06122fc0e8
7
+ data.tar.gz: e094bbbcef3b62db93109913245944d0940dc8e8689f5ea3a3a20d52fa5d14d8a269a2169ac5086ab1b98e13fe59c668b04b9ee363d1b3ea9191f1783f5d82f7
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'acos_jekyll_openapi'
4
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"
5
+ "/mnt/c/Kode/github/Acos.Integration.Documentation/_data/swagger",
6
+ "/mnt/c/Kode/github/Acos.Integration.Documentation",
7
+ "/mnt/c/Kode/github/Acos.Integration.Documentation/pages/swagger"
8
8
  )
@@ -46,47 +46,51 @@ class AcosOpenApiHelper::PageEngine
46
46
  def initialize(data, basePath, output_path, swaggerfile)
47
47
  @data = data
48
48
  @output_path = output_path
49
- #@sidebar = sidebar
50
49
  @swaggerfile = swaggerfile
51
50
  @basePath = basePath
52
51
  end
53
52
 
54
53
  def generate
55
- puts "generating pages..."
54
+ puts "Generating pages..."
56
55
  cnt = 0
57
- puts "Open API version %s" % @data['openapi']
58
- docTitle = @data["info"]["title"]
59
- sidebar = "%s_sidebar" % docTitle
56
+ puts "Open API version %s in .json file" % (@data.key?("openapi") ? @data['openapi'] : @data['swagger'])
57
+ docTitle = (@data["info"]["title"])
58
+ _components = @data.key?("components") ? "components" :"definitions"
59
+ docFile = docTitle.gsub(/\+|\s+|{|}|\//, "_").downcase
60
+ puts "Document title : %s" % docTitle
61
+ sidebar = "%s_sidebar" % docFile
60
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
+
61
72
  @data['paths'].each do |path|
62
- #puts "Prop: %s at counter %s" % [path, cnt]
63
73
  _path = path[0] #path of swagger method
64
74
  _methods = @data['paths'][_path]
65
- #puts "Path: %s has methods: %s " % [_path, _methods]
66
- # puts "Methods: %s" % _methods
67
- puts "Path: %s" % [_path]
68
- #Should not need this. yet...
69
- # _methods.each do | _method |
70
- # puts "Method: %s " % _method
71
- # _md = _methods[_method]
72
- # puts "Method description: %s" % [_md]
73
- # end
74
- #@prop = @data['paths'][cnt]
75
- #puts "Found property %s" [@prop]
76
- #puts "Constants: %s, %s, %s, %s" % [_path, @output_path, @swaggerfile, @sidebar]
77
- writer = AcosOpenApiHelper::PageCreator.new(_path, @basePath, @output_path, @swaggerfile, sidebar)
75
+ #(path, basePath, output_path, swaggerfile, sidebar, docFile, component)
76
+ writer = AcosOpenApiHelper::PageCreator.new(_path, @basePath, @output_path, @swaggerfile, sidebar, docFile, _components)
78
77
  writer.write
79
- _permalink =AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
78
+ _permalink = AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
80
79
  _menuItem = AcosOpenApiHelper::MenuItem.new(_path, _permalink)
81
80
  menu.add(_menuItem)
82
81
  cnt = cnt + 1
83
-
84
82
  end
83
+ # Adding component page for models
84
+ #createComponents(basePath, title, sidebar, swaggerfile, docFile)
85
+ 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
+ cnt = cnt + 1
89
+
85
90
  puts "Done generating %s pages..." % cnt
86
91
  puts "Writing menu"
87
92
  menu.write("%s/_data/sidebars" % @basePath, sidebar, docTitle)
88
93
  end
89
-
90
94
  end
91
95
 
92
96
  class AcosOpenApiHelper::SidebarMenu
@@ -109,7 +113,11 @@ class AcosOpenApiHelper::SidebarMenu
109
113
  end
110
114
 
111
115
  def write (output_path, name, menuTitle)
116
+ #no spaces in filename ofr sidebar.yml
117
+ name = name.gsub(/\s+|{|}|\/|\+/, "_").downcase
118
+ puts "Name of file %s" % [name]
112
119
  _standardLines = [
120
+ "# THIS PAGE IS GENERATED. ANY CHANGES TO PAGE WILL POTENTIALLY BE OVERWRITTEN.",
113
121
  "# This is your sidebar TOC. The sidebar code loops through sections here and provides the appropriate formatting.",
114
122
  "entries:",
115
123
  "- title: sidebar",
@@ -123,15 +131,15 @@ class AcosOpenApiHelper::SidebarMenu
123
131
  ]
124
132
  puts "Writing menu with length: %s" % @@entries.length
125
133
  @@entries.each do | item |
126
- puts "Entry: %s, url: %s" % [item.title, item.url]
134
+ #puts "Entry: %s, url: %s" % [item.title, item.url]
127
135
  _standardLines << " - title: %s" % item.title
128
136
  _standardLines << " url: /%s.html" % item.url
129
137
  _standardLines << " output: web, pdf"
130
138
  end
131
139
 
132
- _standardLines << " - title: %s" % "Models"
133
- _standardLines << " url: /%s.html" % "userapi_components"
134
- _standardLines << " output: web, pdf"
140
+ # _standardLines << " - title: %s" % "Models"
141
+ # _standardLines << " url: /%s.html" % "userapi_components"
142
+ # _standardLines << " output: web, pdf"
135
143
  # File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
136
144
  # f.puts(@lines)
137
145
  # end
@@ -139,6 +147,8 @@ class AcosOpenApiHelper::SidebarMenu
139
147
  File.open("%s/%s.%s" % [output_path, name, "yml"], "w+") do | f |
140
148
  f.puts(_standardLines)
141
149
  end
150
+
151
+ @@entries.clear
142
152
  end
143
153
 
144
154
  end
@@ -161,7 +171,7 @@ class AcosOpenApiHelper::PermalinkGenerator
161
171
  def self.create(path, swaggerfile)
162
172
  @swaggerfileBase = File.basename(swaggerfile, ".*")
163
173
  @permalinkBase = "%s_%s" % [@swaggerfileBase, path]
164
- @permalink = @permalinkBase.gsub(/\s+|{|}|\//, "_").downcase
174
+ @permalink = @permalinkBase.gsub(/\+|\s+|{|}|\//, "_").downcase
165
175
  return @permalink
166
176
  end
167
177
 
@@ -171,38 +181,81 @@ class AcosOpenApiHelper::PermalinkGenerator
171
181
 
172
182
  end
173
183
 
184
+ class AcosOpenApiHelper::FileNameGenerator
185
+ def self.create(path, docFile)
186
+ @docFileBase = "%s_%s" % [docFile, path]
187
+ @docFileName = @docFileBase.gsub(/\+|\s+|{|}|\//, "_").downcase
188
+ return @docFileName
189
+ end
190
+
191
+ def fileName
192
+ @docFileName
193
+ end
194
+ end
195
+
174
196
  class AcosOpenApiHelper::PageCreator
175
- def initialize(path, basePath, output_path, swaggerfile, sidebar)
197
+ def initialize(path, basePath, output_path, swaggerfile, sidebar, docFile, component)
176
198
  # puts "Initialize intput %s, %s, %s, %s" % [path, output_path, swaggerfile, sidebar]
177
199
  @path = path
178
200
  @output_path = output_path
179
201
  @swaggerfile = swaggerfile
180
202
  @sidebar = sidebar
203
+ @docFile = AcosOpenApiHelper::FileNameGenerator.create(@path, docFile)
181
204
  @basePath = basePath
182
205
  @swaggerfileBase = File.basename(@swaggerfile, ".*")
183
206
  @permalink = AcosOpenApiHelper::PermalinkGenerator.create(path, @swaggerfile)
184
207
  @lines = [
185
208
  "---",
186
- "title: User API %s" % path,
209
+ "# THIS PAGE IS GENERATED. ANY CHANGES TO PAGE WILL POTENTIALLY BE OVERWRITTEN.",
210
+ "title: %s" % path,
187
211
  "keywords: json, openapi",
188
212
  "# summary: test med json fil",
189
- "sidebars: ",
190
- " - name: %s" % @sidebar,
213
+ " #sidebars: ",
214
+ " # - name: %s" % @sidebar,
191
215
  "permalink: %s.html" % @permalink,
192
216
  "folder: swagger",
193
217
  "toc: false",
194
218
  "swaggerfile: %s" % @swaggerfileBase,
195
219
  "swaggerpath: paths",
196
220
  "swaggerkey: %s" % @path,
221
+ "swagger_components: %s" % component,
222
+ "components_file: %s" % docFile,
197
223
  "---",
198
224
  "{\% include swagger_json/get_path.md \%}"
199
225
  ]
200
226
  end
201
227
 
202
228
  def write
203
- File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
229
+ File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @docFile, "md"], "w+") do |f|
204
230
  f.puts(@lines)
205
231
  end
206
232
  end
207
- end
208
233
 
234
+ def self.createComponents(basePath, title, sidebar, swaggerfile, docFile, componentsKey)
235
+ swaggerfileName = File.basename(swaggerfile, ".*")
236
+ contentLines = [
237
+ "---",
238
+ "title: %s Models" % title,
239
+ "keyword: json, openapi, models, components",
240
+ "sidebars:",
241
+ " - name: %s" % sidebar,
242
+ "folder: swagger",
243
+ "toc: false",
244
+ "swaggerfile: %s" % swaggerfileName,
245
+ "swaggerkey: %s" % componentsKey,
246
+ "permalink: %s_components.html" % docFile,
247
+ "link: %s_components.html" % docFile,
248
+ "---",
249
+ "{% include swagger_json/get_components.md attribute='page.swaggerkey' %}",
250
+ "",
251
+ "{% include links.html %}",
252
+ ]
253
+ AcosOpenApiHelper::PageCreator.writeFile("%s/pages/swagger/%s_components.md" % [basePath, docFile], contentLines)
254
+ end
255
+
256
+ def self.writeFile(fullPath, contentLines )
257
+ File.open("%s" % fullPath, "w+") do | f |
258
+ f.puts(contentLines)
259
+ end
260
+ end
261
+ 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.2.0
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Acos AS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.0.3
54
+ rubygems_version: 3.1.2
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Open API json file helper