Sha256: 06d80346f608f897510766baed9c4f56a58f0a306c87e1ead7ea208d2a82df35

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'active_support/concern'

module OpenApi
  module ConfigDSL
    extend ActiveSupport::Concern

    class_methods do
      def open_api name, base_doc_classes:
        @api = name
        open_api_docs[name] = { base_doc_classes: base_doc_classes }
      end

      def info version:, title:, desc: '', **addition
        open_api_docs[@api][:info] = { version: version, title: title, description: desc, **addition }
      end

      def server url, desc: ''
        (open_api_docs[@api][:servers] ||= [ ]) << { url: url, description: desc }
      end

      def security_scheme scheme_name, other_info# = { }
        other_info[:description] = other_info.delete(:desc) if other_info.key?(:desc)
        (open_api_docs[@api][:securitySchemes] ||= { })[scheme_name] = other_info
      end

      def base_auth scheme_name, other_info = { }
        security_scheme scheme_name, { type: 'http', scheme: 'basic', **other_info }
      end

      def bearer_auth scheme_name, format = 'JWT', other_info = { }
        security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format, **other_info }
      end

      def api_key scheme_name, field:, in: 'header', **other_info
        _in = binding.local_variable_get(:in)
        security_scheme scheme_name, { type: 'apiKey', name: field, in: _in, **other_info }
      end

      def global_security_require scheme_name, scopes: [ ]
        (open_api_docs[@api][:global_security] ||= [ ]) << { scheme_name => scopes }
      end

      alias global_security global_security_require
      alias global_auth     global_security_require
      alias auth_scheme     security_scheme
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
zero-rails_openapi-2.2.0 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.5 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.4 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.3 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.2 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.1 lib/open_api/config_dsl.rb
zero-rails_openapi-2.1.0 lib/open_api/config_dsl.rb
zero-rails_openapi-2.0.3 lib/open_api/config_dsl.rb