lib/apipie/swagger_generator.rb
#--------------------------------------------------------------------------
# The core routine for creating a swagger parameter definition block.
# The output is slightly different when the parameter is inside a schema block.
#--------------------------------------------------------------------------
The core routine for creating a swagger parameter definition block.
The output is slightly different when the parameter is inside a schema block.
The core routine for creating a swagger parameter definition block . The output is slightly different when the parameter is inside a schema block .
def swagger_atomic_param(param_desc, in_schema, name, allow_nulls)
      def save_field(entry, openapi_key, v, apipie_key=openapi_key, translate=false)
        if v.key?(apipie_key)
          if translate
            entry[openapi_key] = Apipie.app.translate(v[apipie_key], @current_lang)
          else
            entry[openapi_key] = v[apipie_key]
          end
        end
      end
      swagger_def = {}
      swagger_def[:name] = name if !name.nil?
      swg_param_type = swagger_param_type(param_desc)
      swagger_def[:type] = swg_param_type.to_s
      if (swg_param_type.is_a? SwaggerTypeWithFormat) && !swg_param_type.str_format.nil?
        swagger_def[:format] = swg_param_type.str_format
      end
      if swagger_def[:type] == "array"
        swagger_def[:items] = {type: "string"}
      end
      if swagger_def[:type] == "enum"
        swagger_def[:type] = "string"
        swagger_def[:enum] = param_desc.validator.values
      end
      if swagger_def[:type] == "object"  
        swagger_def[:additionalProperties] = true
        warn_hash_without_internal_typespec(param_desc.name)
      end
      if param_desc.is_array?
        new_swagger_def = {
            items: swagger_def,
            type: 'array'
        }
        swagger_def = new_swagger_def
        if allow_nulls
          swagger_def[:type] = [swagger_def[:type], "null"]
        end
      end
      if allow_nulls
        swagger_def[:type] = [swagger_def[:type], "null"]
      end
      if !in_schema
        swagger_def[:in] = param_desc.options.fetch(:in, @default_value_for_param_in)
        swagger_def[:required] = param_desc.required if param_desc.required
      end
      save_field(swagger_def, :description, param_desc.options, :desc, true) unless param_desc.options[:desc].nil?
      save_field(swagger_def, :default, param_desc.options, :default_value)
      if param_desc.respond_to?(:_gen_added_from_path) && !param_desc.required
        warn_optional_param_in_path(param_desc.name)
        swagger_def[:required] = true
      end
      if !swagger_def[:required] && !swagger_def.key?(:default)
        warn_optional_without_default_value(param_desc.name) unless @disable_default_value_warning
      end
      swagger_def
    end
def swagger_atomic_param ( param_desc , in_schema , name , allow_nulls ) def save_field ( entry , openapi_key , v , apipie_key = openapi_key , translate = false ) if v . key? ( apipie_key ) if translate entry [ openapi_key ] = Apipie . app . translate ( v [ apipie_key ] , @current_lang ) else entry [ openapi_key ] = v [ apipie_key ] end end end swagger_def = { } swagger_def [ :name ] = name if ! name . nil? swg_param_type = swagger_param_type ( param_desc ) swagger_def [ :type ] = swg_param_type . to_s if ( swg_param_type . is_a? SwaggerTypeWithFormat ) && ! swg_param_type . str_format . nil? swagger_def [ :format ] = swg_param_type . str_format end if swagger_def [ :type ] == "array" swagger_def [ :items ] = { type : "string" } end if swagger_def [ :type ] == "enum" swagger_def [ :type ] = "string" swagger_def [ :enum ] = param_desc . validator . values end if swagger_def [ :type ] == "object" swagger_def [ :additionalProperties ] = true warn_hash_without_internal_typespec ( param_desc . name ) end if param_desc . is_array? new_swagger_def = { items : swagger_def , type : 'array' } swagger_def = new_swagger_def if allow_nulls swagger_def [ :type ] = [ swagger_def [ :type ] , "null" ] end end if allow_nulls swagger_def [ :type ] = [ swagger_def [ :type ] , "null" ] end if ! in_schema swagger_def [ :in ] = param_desc . options . fetch ( :in , @default_value_for_param_in ) swagger_def [ :required ] = param_desc . required if param_desc . required end save_field ( swagger_def , :description , param_desc . options , :desc , true ) unless param_desc . options [ :desc ] . nil? save_field ( swagger_def , :default , param_desc . options , :default_value ) if param_desc . respond_to? ( :_gen_added_from_path ) && ! param_desc . required warn_optional_param_in_path ( param_desc . name ) swagger_def [ :required ] = true end if ! swagger_def [ :required ] && ! swagger_def . key? ( :default ) warn_optional_without_default_value ( param_desc . name ) unless @disable_default_value_warning end swagger_def end
The core routine for creating a swagger parameter definition block.
The core routine for creating a swagger parameter definition block .
# we only get here if there is no specification of properties for this object
param_desc
<not_specific>
in_schema
<not_specific>
name
<not_specific>
allow_nulls
<not_specific>