Class: OpenapiFirst::Operation
- Inherits:
-
Object
- Object
- OpenapiFirst::Operation
- Extended by:
- Forwardable
- Defined in:
- lib/openapi_first/operation.rb
Instance Method Summary collapse
- #content_type_for(status) ⇒ Object
-
#initialize(parsed) ⇒ Operation
constructor
A new instance of Operation.
- #name ⇒ Object
- #parameters_json_schema ⇒ Object
- #parameters_schema ⇒ Object
- #path ⇒ Object
- #response_for(status) ⇒ Object
- #response_schema_for(status, content_type) ⇒ Object
Constructor Details
#initialize(parsed) ⇒ Operation
Returns a new instance of Operation.
17 18 19 |
# File 'lib/openapi_first/operation.rb', line 17 def initialize(parsed) @operation = parsed end |
Instance Method Details
#content_type_for(status) ⇒ Object
33 34 35 36 |
# File 'lib/openapi_first/operation.rb', line 33 def content_type_for(status) content = response_for(status)['content'] content.keys[0] if content end |
#name ⇒ Object
59 60 61 |
# File 'lib/openapi_first/operation.rb', line 59 def name "#{method.upcase} #{path} (#{operation_id})" end |
#parameters_json_schema ⇒ Object
25 26 27 |
# File 'lib/openapi_first/operation.rb', line 25 def parameters_json_schema @parameters_json_schema ||= build_parameters_json_schema end |
#parameters_schema ⇒ Object
29 30 31 |
# File 'lib/openapi_first/operation.rb', line 29 def parameters_schema @parameters_schema ||= parameters_json_schema && JSONSchemer.schema(parameters_json_schema) end |
#path ⇒ Object
21 22 23 |
# File 'lib/openapi_first/operation.rb', line 21 def path @operation.path.path end |
#response_for(status) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/openapi_first/operation.rb', line 52 def response_for(status) @operation.response_by_code(status.to_s, use_default: true).raw rescue OasParser::ResponseCodeNotFound = "Response status code or default not found: #{status} for '#{name}'" raise OpenapiFirst::ResponseCodeNotFoundError, end |
#response_schema_for(status, content_type) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/openapi_first/operation.rb', line 38 def response_schema_for(status, content_type) content = response_for(status)['content'] return if content.nil? || content.empty? raise ResponseInvalid, "Response has no content-type for '#{name}'" unless content_type media_type = content[content_type] unless media_type = "Response content type not found '#{content_type}' for '#{name}'" raise ResponseContentTypeNotFoundError, end media_type['schema'] end |