Class: OdataDuty::OAS2::CollectionPostPath
- Inherits:
-
Object
- Object
- OdataDuty::OAS2::CollectionPostPath
- Defined in:
- lib/odata_duty/oas2/collection_post_path.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(entity_set) ⇒ CollectionPostPath
constructor
A new instance of CollectionPostPath.
- #operation_id ⇒ Object
- #parameters ⇒ Object
- #produces ⇒ Object
- #responses ⇒ Object
Constructor Details
#initialize(entity_set) ⇒ CollectionPostPath
Returns a new instance of CollectionPostPath.
23 24 25 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 23 def initialize(entity_set) @entity_set = entity_set end |
Class Method Details
.request_body_definition(entity_set) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 14 def self.request_body_definition(entity_set) writable = entity_set.entity_type.properties.select(&:settable_on_create?) definition = { 'type' => 'object', 'properties' => writable.to_h { |p| [p.name.to_s, p.to_oas2] } } required = writable.reject(&:nullable).map { |p| p.name.to_s } definition['required'] = required unless required.empty? ["#{entity_set.entity_type.name}Create", definition] end |
.to_oas2(entity_set) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 4 def self.to_oas2(entity_set) path_info = new(entity_set) { 'operationId' => path_info.operation_id, 'produces' => path_info.produces, 'parameters' => path_info.parameters, 'responses' => path_info.responses } end |
Instance Method Details
#operation_id ⇒ Object
27 28 29 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 27 def operation_id "Create#{@entity_set.name}" end |
#parameters ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 35 def parameters [ { 'name' => 'body', 'in' => 'body', 'required' => true, 'schema' => create_schema } ] end |
#produces ⇒ Object
31 32 33 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 31 def produces ['application/json'] end |
#responses ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 43 def responses { '200' => { 'description' => 'Success', 'schema' => entity_type_schema }, '201' => { 'description' => 'Created', 'schema' => entity_type_schema }, 'default' => { 'description' => 'Unexpected error', 'schema' => { '$ref' => '#/definitions/Error' } } } end |