openapi3_invoker 0.1.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: bba8b08b9ad66d44f3acf497a35c6eabb18df985d2afbd77746f6f9f4f372718
4
- data.tar.gz: 154d5af22babe40808e9b457c207b361b6fac1b704b4f98418e6a09994b19792
3
+ metadata.gz: 387f982fcf4f6b91e0aa79c0147afab483a082452dcacddd7a0c894f7be04fcf
4
+ data.tar.gz: 4c9600cc1a03afd90720a46d2bf120d89586961949b534fe0e129a4e6ba14d5d
5
5
  SHA512:
6
- metadata.gz: 23dc0b036008cb6aaf8087c3e9153614b86f22198e82d10379908bd572a1e05fe88e8ff9d6a6d657cf6139b0ebff079cc67b0d394eaafd3cd991d91a434a40fe
7
- data.tar.gz: e291750b6e312732e224d3df3dc6aeb6c7b02bf48a872e3b31ca5c9fbbb70989b8f057bb3e984989e29bca4647623d3cf93e7b144734c9ecb5100d3046a5dead
6
+ metadata.gz: 066b31aab5d1046ffe4b125f0f2c359e5e424a8cff972a642ca89b559fdad184a9c1dd27dc780caa5f93217a0d2907b63980b3c134cc8ccf17033724ae8c0538
7
+ data.tar.gz: 19131179c9e43e4349ac61ee29db4847a7ca91e4a9a236b46ed0acfb059a7e347f932f801b91098747031c30995ceb2850b28050c51a137b90d31f431dce9f1f
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,20 +31,25 @@ 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
30
41
 
31
- response = case method_name
42
+ response = case method_name.downcase
32
43
  when "get"
33
44
  resulting_url = full_url(path_name, method, parameters: parameters)
34
- connection.get(resulting_url, headers)
35
- when "delete", "put", "patch", "post", "head", "trace", "options"
36
- raise Error::NotYetImplemented.new("Only GET requests are currently supported")
45
+ connection.get(resulting_url, nil, headers)
46
+ when "post"
47
+ resulting_url = full_url(path_name, method, parameters: parameters)
48
+ connection.post(resulting_url, body, headers)
49
+ when "delete", "put", "patch", "head", "trace", "options"
50
+ raise Error::NotYetImplemented.new("Only GET and POST requests are currently supported")
37
51
  end
38
- response.body
52
+ [response.status, response.headers.to_h.transform_keys(&:downcase), response.body]
39
53
  end
40
54
 
41
55
  # We're expect this method to called from invoke, so much of the error checking has already happened
@@ -71,4 +85,4 @@ module Openapi3Invoker
71
85
  end
72
86
  end
73
87
  end
74
- end
88
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openapi3Invoker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Petersen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-06 00:00:00.000000000 Z
11
+ date: 2025-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openapi3_parser
@@ -80,7 +80,7 @@ metadata:
80
80
  homepage_uri: https://github.com/assaydepot/openapi3_invoker
81
81
  source_code_uri: https://github.com/assaydepot/openapi3_invoker
82
82
  changelog_uri: https://github.com/assaydepot/openapi3_invoker/releases
83
- post_install_message:
83
+ post_install_message:
84
84
  rdoc_options: []
85
85
  require_paths:
86
86
  - lib
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubygems_version: 3.5.3
99
- signing_key:
99
+ signing_key:
100
100
  specification_version: 4
101
101
  summary: A gem to simplify invoking OpenAPI 3.0 operations
102
102
  test_files: []