Class: Apia::OpenApi::Objects::RequestBody
- Inherits:
-
Object
- Object
- Apia::OpenApi::Objects::RequestBody
- Includes:
- Helpers
- Defined in:
- lib/apia/open_api/objects/request_body.rb
Instance Method Summary collapse
- #add_to_spec ⇒ Object
-
#initialize(spec:, route:, route_spec:) ⇒ RequestBody
constructor
A new instance of RequestBody.
Methods included from Helpers
#add_to_components_schemas, #convert_type_to_open_api_data_type, #formatted_description, #generate_array_schema, #generate_id_from_definition, #generate_scalar_schema, #generate_schema_ref
Constructor Details
#initialize(spec:, route:, route_spec:) ⇒ RequestBody
Returns a new instance of RequestBody.
26 27 28 29 30 31 |
# File 'lib/apia/open_api/objects/request_body.rb', line 26 def initialize(spec:, route:, route_spec:) @spec = spec @route = route @route_spec = route_spec @properties = {} end |
Instance Method Details
#add_to_spec ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/apia/open_api/objects/request_body.rb', line 33 def add_to_spec required = [] @route.endpoint.definition.argument_set.definition.arguments.each_value do |arg| required << arg.name.to_s if arg.required? if arg.array? if arg.type.argument_set? || arg.type.enum? items = generate_schema_ref(arg) else items = generate_scalar_schema(arg) end @properties[arg.name.to_s] = { type: "array", items: items } elsif arg.type.argument_set? || arg.type.enum? @properties[arg.name.to_s] = generate_schema_ref(arg) else @properties[arg.name.to_s] = generate_scalar_schema(arg) end end schema = { properties: @properties } schema[:required] = required unless required.empty? @route_spec[:requestBody] = { content: { "application/json": { schema: schema } } } end |