lambda_open_api 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3d36e338d14f7ec73fa44a6dcff28a9318d8232211e060ff4b9e831b1c32592
4
- data.tar.gz: ec5683c9cae85aeddfd0c391d7ee46ecda7b7ba221c766cf63cd0ee64185e846
3
+ metadata.gz: c42e035e2e2bf496ab96a72b0c831856b4b6f49e748d475a35c2c169d102e440
4
+ data.tar.gz: 6ab00c5232cfe9999917f687bfdc4c12b6a0d7e78803ced3300115539a64aecf
5
5
  SHA512:
6
- metadata.gz: 50a309862a63e87bc791ffff8740deb6e6cdbfb28885045576acd767479997548321ef29a0c0d489a432f8031d71c6b3c9c110e3e1cadca376709a311b027b48
7
- data.tar.gz: 3b2dad01c575f9df59d532608de110617f2f9ee2378504410669c27d0f1573d6cc41dea41693c2096d93a26e605451541a0a09eac3a09b0f119ea9b94660b0eb
6
+ metadata.gz: fd2c7d7f46ac767dadf2c322ce1e5d5ba7d6241ffddaba5fd555fb2f7aeff1bac2e8c77abf4ba0cfc0929c5f39d43a127f2f7bf92bb387daac7ba8c2bb9db9fd
7
+ data.tar.gz: 1b142c252b123faeacc91d60e364fc0e6988c7ed9f03bc8f3de8ea6c10c91470dc0c5817037335ce31de203c555a8c43a918a52952cc55ede69902fa11095217
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lambda_open_api (0.2.0)
4
+ lambda_open_api (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -66,8 +66,9 @@ module LambdaOpenApi
66
66
 
67
67
  def run_example(test_name=nil, &block)
68
68
  klass = create_class
69
+ test_name ||= "#{@action.http_verb} #{@action.path_name}"
69
70
 
70
- it "#{test_name || @action.path_name}" do
71
+ it "#{test_name}" do
71
72
  @klass = klass
72
73
  def lambda_response
73
74
  @lambda_response ||= @klass.invoke
@@ -83,6 +84,7 @@ module LambdaOpenApi
83
84
  @event.resource = path.gsub(LambdaOpenApi::Action::PARAMATER_EXPRESION) {|match|
84
85
  match = hash[match.delete('{}:').to_sym]
85
86
  }
87
+ @event.path_parameters = hash.inject({}) {|hash, (key, value)| hash[key.to_s] = value; hash}
86
88
  end
87
89
 
88
90
  def invoke_lambda
@@ -1,9 +1,9 @@
1
1
  module LambdaOpenApi
2
2
  class Configuration
3
- attr_accessor :file_name, :title, :description, :version, :host, :schemes, :consumes, :produces
3
+ attr_accessor :file_name, :title, :description, :version, :host, :schemes, :consumes, :produces, :file_sets
4
4
 
5
5
  def initialize
6
- @file_name = "open_api.json"
6
+ @file_name = "open_api/open_api.json"
7
7
  @title = "Workflow Settings Api"
8
8
  @description = "About this api"
9
9
  @version = "1"
@@ -11,6 +11,7 @@ module LambdaOpenApi
11
11
  @schemes = ["https"]
12
12
  @consumes = ["application/json"]
13
13
  @produces = ["application/json"]
14
+ @file_sets = []
14
15
  end
15
16
  end
16
17
  end
@@ -13,6 +13,10 @@ module LambdaOpenApi
13
13
  :body,
14
14
  :is_base64_encoded
15
15
 
16
+ def initialize
17
+ @body = "{}"
18
+ end
19
+
16
20
  def json
17
21
  {
18
22
  "resource" => resource,
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
 
2
3
  module LambdaOpenApi
3
4
  class Formatter
@@ -10,12 +11,25 @@ module LambdaOpenApi
10
11
  end
11
12
 
12
13
  def generate_docs
13
- open_api = high_level.merge({"paths" => @paths})
14
14
 
15
- File.open(LambdaOpenApi.configuration.file_name, "w") {|f| f.write(JSON.pretty_generate(open_api) + "\n") }
15
+
16
+
17
+
18
+ if uses_file_sets?
19
+ LambdaOpenApi.configuration.file_sets.each do |file_set|
20
+ LambdaOpenApi.configuration.host = file_set[:host]
21
+
22
+ open_api = high_level_structure.merge({"paths" => @paths})
23
+
24
+ create_file(file_set[:file_name], open_api)
25
+ end
26
+ else
27
+ open_api = high_level_structure.merge({"paths" => @paths})
28
+ create_file(LambdaOpenApi.configuration.file_name, open_api)
29
+ end
16
30
  end
17
31
 
18
- def high_level
32
+ def high_level_structure
19
33
  {
20
34
  "swagger" => "2.0",
21
35
  "info" => {
@@ -29,6 +43,23 @@ module LambdaOpenApi
29
43
  "produces" => LambdaOpenApi.configuration.produces
30
44
  }
31
45
  end
46
+
47
+ def uses_file_sets?
48
+ LambdaOpenApi.configuration.file_sets&.is_a?(Array) &&
49
+ LambdaOpenApi.configuration.file_sets.any?
50
+ end
51
+
52
+ def create_file(file_name, file_content)
53
+ dirname = File.dirname(file_name)
54
+ p dirname
55
+ unless File.directory?(dirname)
56
+ p 'to create'
57
+ p FileUtils.mkdir_p(dirname)
58
+ end
59
+
60
+
61
+ File.open(file_name, "w") {|f| f.write(JSON.pretty_generate(file_content) + "\n") }
62
+ end
32
63
  end
33
64
  end
34
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LambdaOpenApi
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda_open_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothyjb