Sha256: 2bfe24616b1aa87da52c101f0112c1fe892789e82ef3f4e7391ddd276adab82b

Contents?: true

Size: 788 Bytes

Versions: 7

Compression:

Stored size: 788 Bytes

Contents

require "swagger/rack"

module Sinatra
  module Swagger
    module SwaggerLinked
      def swagger(filepath)
        set :swagger, ::Swagger::Base.from_file(filepath)
      end

      def self.registered(app)
        app.helpers Helpers
      end

      module Helpers
        def swagger_spec
          raise "No swagger file loaded" unless settings.swagger
          settings.swagger.request_spec(env: env)
        end

        def schema_from_spec_at(path)
          schema = swagger_spec[:spec]
          path.split("/").each do |key|
            schema = schema[YAML.load(key)]
            return if schema.nil?
          end
          schema['definitions'] = settings.swagger['definitions'] if settings.swagger['definitions']
          schema
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sinatra-swagger-0.4.2 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.4.1 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.4.0 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.3.1 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.2.2 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.2.1 lib/sinatra/swagger/swagger_linked.rb
sinatra-swagger-0.2.0 lib/sinatra/swagger/swagger_linked.rb