lambda_open_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +9 -0
- data/lambda_open_api.gemspec +38 -0
- data/lib/lambda_open_api/action.rb +62 -0
- data/lib/lambda_open_api/body_parameter.rb +38 -0
- data/lib/lambda_open_api/body_property.rb +35 -0
- data/lib/lambda_open_api/builder.rb +105 -0
- data/lib/lambda_open_api/configuration.rb +16 -0
- data/lib/lambda_open_api/event.rb +33 -0
- data/lib/lambda_open_api/formatter.rb +34 -0
- data/lib/lambda_open_api/invoker.rb +15 -0
- data/lib/lambda_open_api/path_parameter.rb +22 -0
- data/lib/lambda_open_api/response.rb +22 -0
- data/lib/lambda_open_api/version.rb +5 -0
- data/lib/lambda_open_api.rb +37 -0
- data/sig/lambda_open_api.rbs +4 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c565a700e0bceffbac7749e3dda568cc957a12134d132ee24ec5c525851f394
|
4
|
+
data.tar.gz: 8a478edc71b50c63a18654c66ad577f1454565d2f5699eeb1b0337e108c3f73e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88788828d826014db9639e1e0525185e3a626ce8c645195a24211d03974bcd4dbccb85f4faa3d3347fe2c864b40ef46f6e92dfbcfffce64b7e8e90f9630fc5d1
|
7
|
+
data.tar.gz: ca67c4eb57ea54bc37f0e90c1a5c38c2f8925600a999b33e618430733901dcfae221e33f06c580f813a49cd8f4a0f53dfd7cfe8037abe755e0945c0e099a8f7e
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lambda_open_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
builder (3.2.4)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
minitest (5.16.3)
|
13
|
+
minitest-reporters (1.5.0)
|
14
|
+
ansi
|
15
|
+
builder
|
16
|
+
minitest (>= 5.0)
|
17
|
+
ruby-progressbar
|
18
|
+
rake (13.0.6)
|
19
|
+
rspec (3.12.0)
|
20
|
+
rspec-core (~> 3.12.0)
|
21
|
+
rspec-expectations (~> 3.12.0)
|
22
|
+
rspec-mocks (~> 3.12.0)
|
23
|
+
rspec-core (3.12.0)
|
24
|
+
rspec-support (~> 3.12.0)
|
25
|
+
rspec-expectations (3.12.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.12.0)
|
28
|
+
rspec-mocks (3.12.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-support (3.12.0)
|
32
|
+
ruby-progressbar (1.11.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
arm64-darwin-21
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
lambda_open_api!
|
39
|
+
minitest
|
40
|
+
minitest-reporters
|
41
|
+
rake (~> 13.0)
|
42
|
+
rspec
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
2.3.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Tim
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# LambdaOpenApi
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lambda_open_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add lambda_open_api
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install lambda_open_api
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lambda_open_api.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/lambda_open_api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "lambda_open_api"
|
7
|
+
spec.version = LambdaOpenApi::VERSION
|
8
|
+
spec.authors = ["Timothyjb"]
|
9
|
+
spec.email = ["timothyjbarkley@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A DSL for generating OpenAPI (swagger) files for APIs using AWS Lambda"
|
12
|
+
spec.description = "This gem is a light weight DSL that works with rspec to allow developers to generate an OpenAPI (swagger) file based an AWS Lambda invoked by API Gateway. It works by writing a simple unit test for your lambda's code. When the test is executed, the input event and returned response are captured and used to build an OpenAPI file."
|
13
|
+
spec.homepage = "https://github.com/Timothyjb/lambda_open_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/Timothyjb/lambda_open_api"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_development_dependency "minitest"
|
33
|
+
spec.add_development_dependency "minitest-reporters"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "path_parameter"
|
2
|
+
require_relative "body_parameter"
|
3
|
+
require_relative "response"
|
4
|
+
|
5
|
+
module LambdaOpenApi
|
6
|
+
class Action
|
7
|
+
PARAMATER_EXPRESION = /[:\{](\w+)\}?/
|
8
|
+
|
9
|
+
attr_accessor :method, :http_verb, :name, :param, :path_name, :parameters, :responses, :code, :description, :summery
|
10
|
+
|
11
|
+
def initialize(name:, http_verb:, path_name:)
|
12
|
+
@responses = {}
|
13
|
+
@parameters = []
|
14
|
+
@name = name
|
15
|
+
@http_verb = http_verb
|
16
|
+
@path_name = path_name
|
17
|
+
|
18
|
+
interpolate_path_paramater
|
19
|
+
end
|
20
|
+
|
21
|
+
def interpolate_path_paramater
|
22
|
+
matches = @path_name.scan PARAMATER_EXPRESION
|
23
|
+
|
24
|
+
return unless matches.any?
|
25
|
+
|
26
|
+
matches.flatten.each do |match|
|
27
|
+
@parameters << LambdaOpenApi::PathParameter.new(name: match).json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_request_body(data)
|
32
|
+
@parameters << LambdaOpenApi::BodyParameter.new(data).json
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_response(data)
|
36
|
+
@responses["200"] = LambdaOpenApi::Response.new(data).json
|
37
|
+
end
|
38
|
+
|
39
|
+
def action_json
|
40
|
+
{
|
41
|
+
"tags"=> [titleize(@name)],
|
42
|
+
"summary"=> @summery,
|
43
|
+
"description"=> @description,
|
44
|
+
"consumes"=> [
|
45
|
+
"application/json"
|
46
|
+
],
|
47
|
+
"produces"=> [
|
48
|
+
"application/json"
|
49
|
+
],
|
50
|
+
"parameters" => @parameters,
|
51
|
+
"responses" => @responses
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def titleize(string)
|
57
|
+
string.to_s.split("_").map{|word| word.capitalize}.join(" ")
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "body_property.rb"
|
2
|
+
|
3
|
+
module LambdaOpenApi
|
4
|
+
class BodyParameter
|
5
|
+
attr_accessor :data
|
6
|
+
|
7
|
+
def initialize(data = nil, file_name: nil)
|
8
|
+
@file_name = file_name
|
9
|
+
|
10
|
+
@data = data
|
11
|
+
if data.nil? && File.exists?("lib/lambda_open_api/examples/requests/#{file_name}.json")
|
12
|
+
json = File.open("lib/lambda_open_api/examples/requests/#{file_name}.json").read
|
13
|
+
@data = JSON.parse(json)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def json
|
18
|
+
hash = LambdaOpenApi::BodyProperty.new
|
19
|
+
hash.generate(@data)
|
20
|
+
{
|
21
|
+
"name"=> "body",
|
22
|
+
"in"=> "body",
|
23
|
+
"description"=> "",
|
24
|
+
"required"=> false,
|
25
|
+
"schema"=> {
|
26
|
+
"description"=> "",
|
27
|
+
"type"=> "object",
|
28
|
+
"properties"=> hash.props,
|
29
|
+
"required"=> []
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LambdaOpenApi
|
2
|
+
class BodyProperty
|
3
|
+
|
4
|
+
attr_accessor :props
|
5
|
+
|
6
|
+
def generate(hash)
|
7
|
+
@props = {}
|
8
|
+
|
9
|
+
hash.each do |key, value|
|
10
|
+
if value.is_a?(Hash)
|
11
|
+
hash = LambdaOpenApi::BodyProperty.new
|
12
|
+
hash.generate(value)
|
13
|
+
|
14
|
+
props[key.to_s] = {
|
15
|
+
"type"=> "object",
|
16
|
+
"properties"=> hash.props
|
17
|
+
}
|
18
|
+
else
|
19
|
+
props[key.to_s] = {
|
20
|
+
"type"=> value_type(value)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def value_type(value)
|
27
|
+
klass = value.class.name.downcase
|
28
|
+
return "boolean" if klass == "trueclass" || klass == "falseclass"
|
29
|
+
klass
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require_relative "action"
|
3
|
+
require_relative "event"
|
4
|
+
|
5
|
+
module LambdaOpenApi
|
6
|
+
module Builder
|
7
|
+
attr_accessor :actions, :name, :default_event_hash
|
8
|
+
|
9
|
+
CRUD_VERBS = [:get, :put, :post, :delete]
|
10
|
+
|
11
|
+
def resource(name)
|
12
|
+
@actions = []
|
13
|
+
@default_event = LambdaOpenApi::Event.new
|
14
|
+
@name = name
|
15
|
+
|
16
|
+
yield
|
17
|
+
|
18
|
+
actions.each do |request|
|
19
|
+
LambdaOpenApi::Formatter.add_request(request)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method, *args, &block)
|
24
|
+
if CRUD_VERBS.include?(method)
|
25
|
+
crud_verb(method.to_s, args.first, &block)
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
if method.to_s.start_with?("event")
|
30
|
+
variable = method.to_s.sub("event_", "")
|
31
|
+
return @event.send("#{variable}=", args.first)
|
32
|
+
end
|
33
|
+
|
34
|
+
if method.to_s.start_with?("default_event")
|
35
|
+
variable = method.to_s.sub("default_event_", "")
|
36
|
+
return @default_event.send("#{variable}=", args.first)
|
37
|
+
end
|
38
|
+
|
39
|
+
if method.to_s.start_with?("path")
|
40
|
+
string = method.to_s.sub("path_", "")
|
41
|
+
if @action.respond_to?(string)
|
42
|
+
return @action.send("#{string}=", args.first)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
raise NameError.new("NameError (undefined local variable or method `#{method}' for #{self})")
|
47
|
+
end
|
48
|
+
|
49
|
+
# get, put, post, delete
|
50
|
+
def crud_verb(verb, path)
|
51
|
+
@action = LambdaOpenApi::Action.new(name: @name, http_verb: verb, path_name: path)
|
52
|
+
@event = @default_event.dup
|
53
|
+
@event.request_context = {"httpMethod": verb.upcase}
|
54
|
+
|
55
|
+
yield
|
56
|
+
|
57
|
+
@action.set_request_body(JSON.parse(@event.body))
|
58
|
+
actions << @action
|
59
|
+
end
|
60
|
+
|
61
|
+
def example_case(code)
|
62
|
+
@action.code = code
|
63
|
+
|
64
|
+
yield
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_example(test_name=nil, &block)
|
68
|
+
lambda_response_value = invoke_lambda
|
69
|
+
@action.set_response(lambda_response_value)
|
70
|
+
|
71
|
+
it "#{test_name || @action.path_name}" do
|
72
|
+
@lambda_response_value = lambda_response_value
|
73
|
+
|
74
|
+
def lambda_response
|
75
|
+
@lambda_response_value
|
76
|
+
end
|
77
|
+
|
78
|
+
instance_eval &block
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def parameter(hash)
|
84
|
+
path = @action.path_name.dup
|
85
|
+
@event.resource = path.gsub(LambdaOpenApi::Action::PARAMATER_EXPRESION) {|match|
|
86
|
+
match = hash[match.delete('{}:').to_sym]
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def invoke_lambda
|
91
|
+
parameter({}) if @event.resource.nil?
|
92
|
+
|
93
|
+
invokcation = LambdaOpenApi::Invoker.new(klass: described_class, method: "process", event: @event.json, context: lambda_context)
|
94
|
+
|
95
|
+
invokcation.response_body
|
96
|
+
end
|
97
|
+
|
98
|
+
def lambda_context
|
99
|
+
OpenStruct.new(aws_request_id: "123")
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module LambdaOpenApi
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :file_name, :title, :description, :version, :host, :schemes, :consumes, :produces
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@file_name = "open_api.json"
|
7
|
+
@title = "Workflow Settings Api"
|
8
|
+
@description = "About this api"
|
9
|
+
@version = "1"
|
10
|
+
@host = "https://google.com"
|
11
|
+
@schemes = ["https"]
|
12
|
+
@consumes = ["application/json"]
|
13
|
+
@produces = ["application/json"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LambdaOpenApi
|
2
|
+
class Event
|
3
|
+
attr_accessor :resource,
|
4
|
+
:path,
|
5
|
+
:http_method,
|
6
|
+
:request_context,
|
7
|
+
:headers,
|
8
|
+
:multi_value_headers,
|
9
|
+
:query_string_parameters,
|
10
|
+
:multi_value_query_string_parameters,
|
11
|
+
:path_parameters,
|
12
|
+
:stage_variables,
|
13
|
+
:body,
|
14
|
+
:is_base64_encoded
|
15
|
+
|
16
|
+
def json
|
17
|
+
{
|
18
|
+
"resource" => resource,
|
19
|
+
"path" => path,
|
20
|
+
"httpMethod" => http_method,
|
21
|
+
"requestContext" => request_context,
|
22
|
+
"headers" => headers,
|
23
|
+
"multiValueHeaders" => multi_value_headers,
|
24
|
+
"queryStringParameters" => query_string_parameters,
|
25
|
+
"multiValueQueryStringParameters" => multi_value_query_string_parameters,
|
26
|
+
"pathParameters" => path_parameters,
|
27
|
+
"stageVariables" => stage_variables,
|
28
|
+
"body" => body,
|
29
|
+
"isBase64Encoded" => is_base64_encoded
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module LambdaOpenApi
|
3
|
+
class Formatter
|
4
|
+
@paths = {}
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def add_request(resource)
|
8
|
+
@paths[resource.path_name] ||= {}
|
9
|
+
@paths[resource.path_name][resource.http_verb] = resource.action_json
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_docs
|
13
|
+
open_api = high_level.merge({"paths" => @paths})
|
14
|
+
|
15
|
+
File.open(LambdaOpenApi.configuration.file_name, "w") {|f| f.write(JSON.pretty_generate(open_api) + "\n") }
|
16
|
+
end
|
17
|
+
|
18
|
+
def high_level
|
19
|
+
{
|
20
|
+
"swagger" => "2.0",
|
21
|
+
"info" => {
|
22
|
+
"title" => LambdaOpenApi.configuration.title,
|
23
|
+
"description" => LambdaOpenApi.configuration.description,
|
24
|
+
"version" => LambdaOpenApi.configuration.version
|
25
|
+
},
|
26
|
+
"host" => LambdaOpenApi.configuration.host,
|
27
|
+
"schemes" => LambdaOpenApi.configuration.schemes,
|
28
|
+
"consumes" => LambdaOpenApi.configuration.consumes,
|
29
|
+
"produces" => LambdaOpenApi.configuration.produces
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LambdaOpenApi
|
2
|
+
class Invoker
|
3
|
+
|
4
|
+
attr_accessor :response
|
5
|
+
|
6
|
+
def initialize(klass:, method:, event:, context:)
|
7
|
+
@response = klass.send(method || "process", event: event, context: context)
|
8
|
+
end
|
9
|
+
|
10
|
+
def response_body
|
11
|
+
response["body"] || response
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module LambdaOpenApi
|
2
|
+
class PathParameter
|
3
|
+
attr_accessor :name, :in, :description, :required, :type
|
4
|
+
|
5
|
+
def initialize(name: nil)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def json
|
10
|
+
{
|
11
|
+
"name"=> @name || "id",
|
12
|
+
"in"=> @in || "path",
|
13
|
+
"description"=> @description || "",
|
14
|
+
"required"=> @required || true,
|
15
|
+
"type"=> @type || "integer"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
require_relative "lambda_open_api/formatter"
|
5
|
+
require_relative "lambda_open_api/version"
|
6
|
+
require_relative "lambda_open_api/configuration"
|
7
|
+
require_relative "lambda_open_api/builder"
|
8
|
+
require_relative "lambda_open_api/invoker"
|
9
|
+
|
10
|
+
module LambdaOpenApi
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield(configuration)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Monkey patching
|
28
|
+
|
29
|
+
module LambdaOpenApiNotification
|
30
|
+
def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
|
31
|
+
LambdaOpenApi::Formatter.generate_docs unless failure_count > 0 || errors_outside_of_examples_count > 0
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::Notifications::SummaryNotification.prepend(LambdaOpenApiNotification)
|
37
|
+
RSpec::Core::ExampleGroup.extend(LambdaOpenApi::Builder)
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lambda_open_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timothyjb
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest-reporters
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem is a light weight DSL that works with rspec to allow developers
|
56
|
+
to generate an OpenAPI (swagger) file based an AWS Lambda invoked by API Gateway.
|
57
|
+
It works by writing a simple unit test for your lambda's code. When the test is
|
58
|
+
executed, the input event and returned response are captured and used to build an
|
59
|
+
OpenAPI file.
|
60
|
+
email:
|
61
|
+
- timothyjbarkley@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".rspec"
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lambda_open_api.gemspec
|
74
|
+
- lib/lambda_open_api.rb
|
75
|
+
- lib/lambda_open_api/action.rb
|
76
|
+
- lib/lambda_open_api/body_parameter.rb
|
77
|
+
- lib/lambda_open_api/body_property.rb
|
78
|
+
- lib/lambda_open_api/builder.rb
|
79
|
+
- lib/lambda_open_api/configuration.rb
|
80
|
+
- lib/lambda_open_api/event.rb
|
81
|
+
- lib/lambda_open_api/formatter.rb
|
82
|
+
- lib/lambda_open_api/invoker.rb
|
83
|
+
- lib/lambda_open_api/path_parameter.rb
|
84
|
+
- lib/lambda_open_api/response.rb
|
85
|
+
- lib/lambda_open_api/version.rb
|
86
|
+
- sig/lambda_open_api.rbs
|
87
|
+
homepage: https://github.com/Timothyjb/lambda_open_api
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
homepage_uri: https://github.com/Timothyjb/lambda_open_api
|
92
|
+
source_code_uri: https://github.com/Timothyjb/lambda_open_api
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.5.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubygems_version: 3.1.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A DSL for generating OpenAPI (swagger) files for APIs using AWS Lambda
|
112
|
+
test_files: []
|