lambda_open_api 0.2.1 → 0.4.0

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: 6137354cc87bf29a177cf14e7c39685eea487dd949efe030370e60e9b5dc7024
4
- data.tar.gz: 9642be6e3096151850396b1ba80fc7192f2a76fac3345ccac6a2c44976bf8638
3
+ metadata.gz: 668813e6540b575a0f236bcd4573e62e8bbb1fd7a4da444cc4a45e12e8c79a19
4
+ data.tar.gz: 3cea133cc9dc22238667bc1015c913d3d9a9af18a2a4c1301617810ee252d5ab
5
5
  SHA512:
6
- metadata.gz: 54c93d2b44d05e8874ce6eb70b864c21a24c2a026cc393aaaed74889a827dd2868364bf43d8635f174a1ba314c4c6656d0b906ee2339d8dd05923d780eee2ee8
7
- data.tar.gz: 93571cf6046621d4efb026b9a0566f88487f6e3f56f60324ddd4136d8070497a8e81cf517087c6da16514051751fd136ecc11fa3e69e74813d684b5da0d3919e
6
+ metadata.gz: 9cb4df4f6c316ae4b94937dc35e156e6d882609a3ede0b72b19d58813bc2000654a88735721ecea9df1783fcead7e7141b9c7b59223df671becb646472c738ea
7
+ data.tar.gz: 4ffa3f982fedbf0bc6db2a24369f293780b77a78bf4c016b1dd839dcd68ec14ce764dca2438dac74acfbba12e470708e4658f59efd5268400cbfd7e6c5fb9a31
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.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,7 +50,7 @@ module LambdaOpenApi
50
50
  def crud_verb(verb, path)
51
51
  @action = LambdaOpenApi::Action.new(name: @name, http_verb: verb, path_name: path)
52
52
  @event = @default_event.dup
53
- @event.request_context = {"httpMethod" => verb.upcase}
53
+ @event.request_context = {"httpMethod" => verb.upcase, "http" => {"method" => verb.upcase}}
54
54
 
55
55
  yield
56
56
 
@@ -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
@@ -1,16 +1,17 @@
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"
10
- @host = "https://google.com"
10
+ @host = "google.com"
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.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda_open_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothyjb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest