acos_jekyll_openapi_helper 1.4.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/acos_jekyll_openapi.rb +67 -29
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a476f2e49f239cb44b14d518fa996e8ac1526d8aed78bd8492013ced5f3168b
4
- data.tar.gz: bbb1182273672c521c182c4bbcccd2cdee6d9672b0639a77e48943df7897ef4f
3
+ metadata.gz: d00cea2080b6f56489bd291fc1f99f40b15d24fb4239069eeb1cac49ad3e80d4
4
+ data.tar.gz: f9f43ac742804cf156780fc0c9b728f6aa552783067c680d5955efb45578c67e
5
5
  SHA512:
6
- metadata.gz: 46758cefc2a3cc5c067115f73f1c0861f3f1c8ecadffacd2946634b25c3f825754344fd655dfa65f77a2b2659085b434b3e436647c517513fd0886b40574e0ce
7
- data.tar.gz: 3f252cb117ff922b4877e0e6cfc894bb026652d6f5f692b7aa220db6793dc72192b0419e4ed51efb24f993304a8fa303ac235cdfa802282454bd868fe1045238
6
+ metadata.gz: 690fb0719009b4690a8173b4fa4c23ab6bc644f536fbc3f58210b5694e8d4e474bb6d549699fc1f56d77705b9b5ea1b5dbfb428d4132cf6854babee6c02d2b82
7
+ data.tar.gz: 5e5ae160424c995101aa7efb7e0fe9a85a45eb0cc53998a049f5127357cadd0eb2858d40b5cc92fdc26657bd1751465080c074d3d67baa7d8f5630a35d7ae6e8
@@ -46,7 +46,6 @@ 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
@@ -54,39 +53,34 @@ class AcosOpenApiHelper::PageEngine
54
53
  def generate
55
54
  puts "Generating pages..."
56
55
  cnt = 0
57
- puts "Open API version %s in .json file" % @data['openapi']
58
- docTitle = @data["info"]["title"]
59
- sidebar = "%s_sidebar" % docTitle.gsub(/\s+|{|}|\//, "_").downcase
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()
61
63
  @data['paths'].each do |path|
62
- #puts "Prop: %s at counter %s" % [path, cnt]
63
64
  _path = path[0] #path of swagger method
64
65
  _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)
66
+ writer = AcosOpenApiHelper::PageCreator.new(_path, @basePath, @output_path, @swaggerfile, sidebar, docFile)
78
67
  writer.write
79
- _permalink =AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
68
+ _permalink = AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
80
69
  _menuItem = AcosOpenApiHelper::MenuItem.new(_path, _permalink)
81
70
  menu.add(_menuItem)
82
71
  cnt = cnt + 1
83
-
84
72
  end
73
+ # Adding component page for models
74
+ #createComponents(basePath, title, sidebar, swaggerfile, docFile)
75
+ AcosOpenApiHelper::PageCreator.createComponents(@basePath, docTitle, sidebar, @swaggerfile, docFile, _components)
76
+ _componentMenu = AcosOpenApiHelper::MenuItem.new("%s Models" % docTitle, "%s_components" % docFile)
77
+ menu.add(_componentMenu)
78
+ cnt = cnt + 1
79
+
85
80
  puts "Done generating %s pages..." % cnt
86
81
  puts "Writing menu"
87
82
  menu.write("%s/_data/sidebars" % @basePath, sidebar, docTitle)
88
83
  end
89
-
90
84
  end
91
85
 
92
86
  class AcosOpenApiHelper::SidebarMenu
@@ -132,9 +126,9 @@ class AcosOpenApiHelper::SidebarMenu
132
126
  _standardLines << " output: web, pdf"
133
127
  end
134
128
 
135
- _standardLines << " - title: %s" % "Models"
136
- _standardLines << " url: /%s.html" % "userapi_components"
137
- _standardLines << " output: web, pdf"
129
+ # _standardLines << " - title: %s" % "Models"
130
+ # _standardLines << " url: /%s.html" % "userapi_components"
131
+ # _standardLines << " output: web, pdf"
138
132
  # File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
139
133
  # f.puts(@lines)
140
134
  # end
@@ -142,6 +136,8 @@ class AcosOpenApiHelper::SidebarMenu
142
136
  File.open("%s/%s.%s" % [output_path, name, "yml"], "w+") do | f |
143
137
  f.puts(_standardLines)
144
138
  end
139
+
140
+ @@entries.clear
145
141
  end
146
142
 
147
143
  end
@@ -174,24 +170,38 @@ class AcosOpenApiHelper::PermalinkGenerator
174
170
 
175
171
  end
176
172
 
173
+ class AcosOpenApiHelper::FileNameGenerator
174
+ def self.create(path, docFile)
175
+ @docFileBase = "%s_%s" % [docFile, path]
176
+ @docFileName = @docFileBase.gsub(/\s+|{|}|\//, "_").downcase
177
+ return @docFileName
178
+ end
179
+
180
+ def fileName
181
+ @docFileName
182
+ end
183
+
184
+ end
185
+
177
186
  class AcosOpenApiHelper::PageCreator
178
- def initialize(path, basePath, output_path, swaggerfile, sidebar)
187
+ def initialize(path, basePath, output_path, swaggerfile, sidebar, docFile)
179
188
  # puts "Initialize intput %s, %s, %s, %s" % [path, output_path, swaggerfile, sidebar]
180
189
  @path = path
181
190
  @output_path = output_path
182
191
  @swaggerfile = swaggerfile
183
192
  @sidebar = sidebar
193
+ @docFile = AcosOpenApiHelper::FileNameGenerator.create(@path, docFile)
184
194
  @basePath = basePath
185
195
  @swaggerfileBase = File.basename(@swaggerfile, ".*")
186
196
  @permalink = AcosOpenApiHelper::PermalinkGenerator.create(path, @swaggerfile)
187
197
  @lines = [
188
198
  "---",
189
199
  "# THIS PAGE IS GENERATED. ANY CHANGES TO PAGE WILL POTENTIALLY BE OVERWRITTEN.",
190
- "title: User API %s" % path,
200
+ "title: %s" % path,
191
201
  "keywords: json, openapi",
192
202
  "# summary: test med json fil",
193
- "sidebars: ",
194
- " - name: %s" % @sidebar,
203
+ " #sidebars: ",
204
+ " # - name: %s" % @sidebar,
195
205
  "permalink: %s.html" % @permalink,
196
206
  "folder: swagger",
197
207
  "toc: false",
@@ -204,9 +214,37 @@ class AcosOpenApiHelper::PageCreator
204
214
  end
205
215
 
206
216
  def write
207
- File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
217
+ File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @docFile, "md"], "w+") do |f|
208
218
  f.puts(@lines)
209
219
  end
210
220
  end
221
+
222
+ def self.createComponents(basePath, title, sidebar, swaggerfile, docFile, componentsKey)
223
+ swaggerfileName = File.basename(swaggerfile, ".*")
224
+ contentLines = [
225
+ "---",
226
+ "title: %s Models" % title,
227
+ "keyword: json, openapi, models, components",
228
+ "sidebars:",
229
+ " - name: %s" % sidebar,
230
+ "folder: swagger",
231
+ "toc: false",
232
+ "swaggerfile: %s" % swaggerfileName,
233
+ "swaggerkey: %s" % componentsKey,
234
+ "permalink: %s_components.html" % docFile,
235
+ "link: %s_components.html" % docFile,
236
+ "---",
237
+ "{% include swagger_json/get_components.md attribute='page.swaggerkey' %}",
238
+ "",
239
+ "{% include links.html %}",
240
+ ]
241
+ AcosOpenApiHelper::PageCreator.writeFile("%s/pages/swagger/%s_components.md" % [basePath, docFile], contentLines)
242
+ end
243
+
244
+ def self.writeFile(fullPath, contentLines )
245
+ File.open("%s" % fullPath, "w+") do | f |
246
+ f.puts(contentLines)
247
+ end
248
+ end
211
249
  end
212
250
 
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.0
4
+ version: 1.4.3
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-24 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