openapi3_invoker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -3
- data/lib/openapi3_invoker/client.rb +16 -3
- data/lib/openapi3_invoker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 825e84d5ec194ba8b8e4051647f0d451e2b3d99694d775321ebf176288737e22
|
4
|
+
data.tar.gz: fa85add880217f71a25db80561a2a2cd5686930f116178189da43f1c94c002f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a826e2d4ed7e5129e88d1147eb5541a8d7c3dc2fb296eb808bd7f08ec52eb8c409229b092216611d656476eeb5d12e37d331c8842f2d99fdbef62b646192197
|
7
|
+
data.tar.gz: 168185032a6eed2cb651b5920bcd6a60f63f81b2515750ef689331684d3e95c9c5e5a881624248d94271435a32204e2724972082b40a30026a7755fa892dc23f
|
data/README.md
CHANGED
@@ -18,13 +18,31 @@ gem install openapi3_invoker
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
openapi_parser = Openapi3Parser.load(open_api_definition)
|
23
|
+
path = "/api/function/name"
|
24
|
+
http_method = "get"
|
25
|
+
parameters = { "some" => "parameter" }
|
26
|
+
openapi_invoker = Openapi3Invoker.new(openapi_definition, base_url: tool.tool_set.base_url)
|
27
|
+
status, headers, result = openapi_invoker.invoke(path, http_method, parameters: parameters)
|
28
|
+
```
|
22
29
|
|
23
30
|
## Development
|
24
31
|
|
25
|
-
|
32
|
+
All development must be done in a pull request and approved before merging.
|
33
|
+
|
34
|
+
To run the specs do the following: `rake spec`
|
35
|
+
|
36
|
+
## Releasing
|
37
|
+
|
38
|
+
To release, first increment the version file, then cut a new tag of the form v#.#.#.
|
26
39
|
|
27
|
-
|
40
|
+
For example:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
git tag v0.2.0 -f
|
44
|
+
git push --tags -f
|
45
|
+
```
|
28
46
|
|
29
47
|
## Contributing
|
30
48
|
|
@@ -15,6 +15,15 @@ module Openapi3Invoker
|
|
15
15
|
@base_url = base_url || openapi.servers.first.url
|
16
16
|
end
|
17
17
|
|
18
|
+
def supported?(path_name, method_name)
|
19
|
+
raise Error::InvalidMethod unless %w[get delete put patch post head trace options].include?(method_name.to_s.downcase)
|
20
|
+
path = openapi.paths[path_name]
|
21
|
+
raise Error::InvalidPath unless path
|
22
|
+
method = path.send(method_name.to_s.downcase)
|
23
|
+
raise Error::InvalidMethodPathCombo unless method
|
24
|
+
raise Error::NotYetImplemented.new("Request Body is not yet supported") if method.request_body&.required?
|
25
|
+
end
|
26
|
+
|
18
27
|
def invoke(path_name, method_name, parameters: {}, headers: {}, body: nil)
|
19
28
|
raise Error::ServerNotSpecified unless base_url
|
20
29
|
raise Error::InvalidMethod unless %w[get delete put patch post head trace options].include?(method_name.to_s.downcase)
|
@@ -22,8 +31,10 @@ module Openapi3Invoker
|
|
22
31
|
raise Error::InvalidPath unless path
|
23
32
|
method = path.send(method_name.to_s.downcase)
|
24
33
|
raise Error::InvalidMethodPathCombo unless method
|
25
|
-
|
26
34
|
raise Error::NotYetImplemented.new("Request Body is not yet supported") if method.request_body&.required?
|
35
|
+
|
36
|
+
# parser.components.schemas["Smiles"].properties.each { |name, prop| puts "#{name}, #{prop.type}" }
|
37
|
+
|
27
38
|
method.parameters.each do |parameter|
|
28
39
|
raise Error::MissingParameter if(parameter.required? && !parameters.key?(parameter.name))
|
29
40
|
end
|
@@ -32,10 +43,12 @@ module Openapi3Invoker
|
|
32
43
|
when "get"
|
33
44
|
resulting_url = full_url(path_name, method, parameters: parameters)
|
34
45
|
connection.get(resulting_url, headers)
|
35
|
-
when "
|
46
|
+
when "post"
|
47
|
+
|
48
|
+
when "delete", "put", "patch", "head", "trace", "options"
|
36
49
|
raise Error::NotYetImplemented.new("Only GET requests are currently supported")
|
37
50
|
end
|
38
|
-
response.body
|
51
|
+
[response.status, response.headers.to_h.transform_keys(&:downcase), response.body]
|
39
52
|
end
|
40
53
|
|
41
54
|
# We're expect this method to called from invoke, so much of the error checking has already happened
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi3_invoker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openapi3_parser
|