Class: Yori::Schema::V3::Responses

Inherits:
Yori::SchemaBase show all
Defined in:
lib/yori/schema/v3/responses.rb

Overview

Responses:

A container for the expected responses of an operation.
The container maps a HTTP response code to the expected response.
The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance.
However, documentation is expected to cover a successful operation response and any known errors.
The default MAY be used as a default response object for all HTTP codes that are not covered individually by the specification.
The Responses Object MUST contain at least one response code, and it SHOULD be the response for a successful operation call.

Instance Attribute Summary

Attributes inherited from Yori::SchemaBase

#id

Instance Method Summary collapse

Methods inherited from Yori::SchemaBase

eval_class!, eval_hash!, eval_input!, #ref, #validator

Instance Method Details

#defaultObject

The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses. A Reference Object can link to a response that the OpenAPI Object’s components/responses section defines.



19
# File 'lib/yori/schema/v3/responses.rb', line 19

field_block :default, Yori::Schema::V3::Response

#responseObject Also known as: status, http_status_code



28
29
30
# File 'lib/yori/schema/v3/responses.rb', line 28

def response(status_code, &block)
  self[status_code.to_s] = self.class.eval_class!(Yori::Schema::V3::Response, id, &block)
end

#validate!Object



35
36
37
38
# File 'lib/yori/schema/v3/responses.rb', line 35

def validate!
  status_keys = keys.reject { |x| x == 'default' }
  raise Yori::Errors::InvalidSchemaError, 'The Responses Object MUST contain at least one response code.' if status_keys.empty?
end