class Apicraft::Middlewares::Introspector
Apicraft Middleware to handle API Introspection.
def call(env)
def call(env) return @app.call(env) unless config.introspection request = ActionDispatch::Request.new(env) return @app.call(env) unless introspect?(request) schema = Apicraft::Openapi::Contract.find_by_operation( request.method, request.path_info )&.operation( request.method, request.path_info )&.raw_schema return @app.call(env) if schema.blank? [ 200, { 'Content-Type': "application/json" }, [schema.to_json] ] end
def initialize(app)
def initialize(app) @app = app end
def introspect?(request)
def introspect?(request) request.headers[config.headers[:introspect]].present? end