Class: ThreeScaleToolbox::OpenAPI::OAS3
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::OpenAPI::OAS3
- Defined in:
- lib/3scale_toolbox/openapi/oas3.rb
Overview
OAS3 object
-
OAS3.title -> string
-
OAS3.description -> string
-
OAS3.version -> string
-
OAS3.base_path -> string
-
OAS3.host -> string
-
OAS3.scheme -> string
-
OAS3.operation -> array of operation hash
-
operation hash properties
-
:verb
-
:path
-
:description
-
:operation_id
-
-
-
OAS3.security -> security hash
-
security hash properties
-
:id -> string
-
:type -> string
-
:name -> string
-
:in_f -> string
-
:flow -> symbol (:implicit_flow_enabled, :direct_access_grants_enabled, :service_accounts_enabled, :standard_flow_enabled)
-
:scopes -> array of string
-
-
-
OAS3.service_backend_version -> string (‘1’,‘2’,‘oidc’)
-
OAS3.set_server_url -> def(spec, url)
-
OAS3.set_oauth2_urls-> def(spec, scheme_id, authorization_url, token_url)
Constant Summary collapse
- META_SCHEMA_PATH =
File.('../../../resources/oas3_meta_schema.json', __dir__)
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Class Method Summary collapse
Instance Method Summary collapse
- #base_path ⇒ Object
- #description ⇒ Object
- #host ⇒ Object
- #operations ⇒ Object
- #scheme ⇒ Object
- #security ⇒ Object
- #service_backend_version ⇒ Object
-
#set_oauth2_urls(spec, sec_scheme_id, authorization_url, token_url) ⇒ Object
Update given spec with urls It is expected identified security scheme to be oauth2 type.
- #set_server_url(spec, url) ⇒ Object
- #title ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
43 44 45 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 43 def definition @definition end |
Class Method Details
.build(path, raw, validate: true) ⇒ Object
37 38 39 40 41 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 37 def self.build(path, raw, validate: true) self.validate(raw) if validate new(path, raw) end |
.validate(raw) ⇒ Object
32 33 34 35 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 32 def self.validate(raw) = JSON.parse(File.read(META_SCHEMA_PATH)) JSON::Validator.validate!(, raw) end |
Instance Method Details
#base_path ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 57 def base_path # If there are many? take first # From https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#openapi-object # If the servers property is not provided, or is an empty array, # the default value would be a Server Object with a url value of / server_objects(&:path).first || '/' end |
#description ⇒ Object
49 50 51 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 49 def description definition.info['description'] end |
#host ⇒ Object
65 66 67 68 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 65 def host # If there are many? take first server_objects(&:host).first end |
#operations ⇒ Object
75 76 77 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 75 def operations @operations ||= parse_operations end |
#scheme ⇒ Object
70 71 72 73 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 70 def scheme # If there are many? take first server_objects(&:scheme).first end |
#security ⇒ Object
79 80 81 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 79 def security @security ||= parse_security end |
#service_backend_version ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 83 def service_backend_version # default authentication mode if no security requirement return '1' if security.nil? case security[:type] when 'oauth2' 'oidc' when 'apiKey' '1' else raise ThreeScaleToolbox::Error, "Unexpected security scheme type #{security[:type]}" end end |
#set_oauth2_urls(spec, sec_scheme_id, authorization_url, token_url) ⇒ Object
Update given spec with urls It is expected identified security scheme to be oauth2 type
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 100 def set_oauth2_urls(spec, sec_scheme_id, , token_url) sec_scheme_obj = spec.dig('components', 'securitySchemes', sec_scheme_id) if sec_scheme_obj.nil? || sec_scheme_obj['type'] != 'oauth2' raise ThreeScaleToolbox::Error, "Expected security scheme {#{sec_scheme_id}} not found or not oauth2" end flow_key, flow_obj = sec_scheme_obj['flows'].first flow_obj['authorizationUrl'] = if %w[implicit authorizationCode].include?(flow_key) flow_obj['tokenUrl'] = token_url if %w[password clientCredentials authorizationCode].include?(flow_key) end |
#set_server_url(spec, url) ⇒ Object
111 112 113 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 111 def set_server_url(spec, url) spec['servers'] = [{ 'url' => url }] end |
#title ⇒ Object
45 46 47 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 45 def title definition.info['title'] end |
#version ⇒ Object
53 54 55 |
# File 'lib/3scale_toolbox/openapi/oas3.rb', line 53 def version definition.info['version'] end |