Class: OdataDuty::OAS2::CollectionPostPath

Inherits:
Object
  • Object
show all
Defined in:
lib/odata_duty/oas2/collection_post_path.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_set) ⇒ CollectionPostPath

Returns a new instance of CollectionPostPath.



24
25
26
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 24

def initialize(entity_set)
  @entity_set = entity_set
end

Class Method Details

.request_body_definition(entity_set) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 15

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
13
# 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
  }.merge(path_info.summary_and_description).merge(
    'produces' => path_info.produces,
    'parameters' => path_info.parameters,
    'responses' => path_info.responses
  )
end

Instance Method Details

#operation_idObject



28
29
30
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 28

def operation_id
  "Create#{@entity_set.name}"
end

#parametersObject



43
44
45
46
47
48
49
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 43

def parameters
  [
    {
      'name' => 'body', 'in' => 'body', 'required' => true, 'schema' => create_schema
    }
  ]
end

#producesObject



39
40
41
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 39

def produces
  ['application/json']
end

#responsesObject



51
52
53
54
55
56
57
58
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 51

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

#summary_and_descriptionObject



32
33
34
35
36
37
# File 'lib/odata_duty/oas2/collection_post_path.rb', line 32

def summary_and_description
  return {} unless @entity_set.description

  { 'summary' => OperationVerbs.create(@entity_set.name),
    'description' => @entity_set.description }
end