openapi3_invoker 0.1.0 → 0.2.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: bba8b08b9ad66d44f3acf497a35c6eabb18df985d2afbd77746f6f9f4f372718
4
- data.tar.gz: 154d5af22babe40808e9b457c207b361b6fac1b704b4f98418e6a09994b19792
3
+ metadata.gz: 825e84d5ec194ba8b8e4051647f0d451e2b3d99694d775321ebf176288737e22
4
+ data.tar.gz: fa85add880217f71a25db80561a2a2cd5686930f116178189da43f1c94c002f9
5
5
  SHA512:
6
- metadata.gz: 23dc0b036008cb6aaf8087c3e9153614b86f22198e82d10379908bd572a1e05fe88e8ff9d6a6d657cf6139b0ebff079cc67b0d394eaafd3cd991d91a434a40fe
7
- data.tar.gz: e291750b6e312732e224d3df3dc6aeb6c7b02bf48a872e3b31ca5c9fbbb70989b8f057bb3e984989e29bca4647623d3cf93e7b144734c9ecb5100d3046a5dead
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
- TODO: Write usage instructions here
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
- 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.
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
- 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).
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 "delete", "put", "patch", "post", "head", "trace", "options"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openapi3Invoker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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-09-06 00:00:00.000000000 Z
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openapi3_parser