Sha256: 14a10e105a6174631578096b9b13754ea9c129d94db97028bb80e5943146acf6

Contents?: true

Size: 650 Bytes

Versions: 13

Compression:

Stored size: 650 Bytes

Contents

module SwaggerYard
  class Type
    def self.from_type_list(types)
      new(types.first)
    end

    attr_reader :name, :source, :schema

    def initialize(string)
      @source  = string
      @schema  = TypeParser.new.json_schema(string)
      @name    = name_for(@schema)
      @name    = name_for(@schema['items']) if @name == 'array'
    end

    # TODO: have this look at resource listing?
    def ref?
      schema["$ref"]
    end

    def model_name
      ref? ? name : nil
    end

    def to_h
      schema
    end

    private
    def name_for(schema)
      schema["type"] || schema["$ref"][%r'#/definitions/(.*)', 1]
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
swagger_yard-1.1.1 lib/swagger_yard/type.rb.~master~
swagger_yard-1.1.0 lib/swagger_yard/type.rb.~master~
swagger_yard-1.0.4 lib/swagger_yard/type.rb.~master~
swagger_yard-1.0.3 lib/swagger_yard/type.rb.~master~
swagger_yard-1.0.2 lib/swagger_yard/type.rb.~master~
swagger_yard-1.0.1 lib/swagger_yard/type.rb.~master~
swagger_yard-1.0.0 lib/swagger_yard/type.rb.~master~
swagger_yard-0.4.4 lib/swagger_yard/type.rb
swagger_yard-0.4.3 lib/swagger_yard/type.rb
swagger_yard-0.4.2 lib/swagger_yard/type.rb
swagger_yard-0.4.1 lib/swagger_yard/type.rb
swagger_yard-0.4.0 lib/swagger_yard/type.rb
swagger_yard-0.3.7 lib/swagger_yard/type.rb