Module: OasCore

Defined in:
lib/oas_core.rb,
lib/oas_core/utils.rb,
lib/oas_core/version.rb,
lib/oas_core/spec/tag.rb,
lib/oas_core/oas_route.rb,
lib/oas_core/spec/info.rb,
lib/oas_core/spec/paths.rb,
lib/oas_core/spec/server.rb,
lib/oas_core/spec/contact.rb,
lib/oas_core/spec/license.rb,
lib/oas_core/configuration.rb,
lib/oas_core/spec/hashable.rb,
lib/oas_core/spec/response.rb,
lib/oas_core/spec/specable.rb,
lib/oas_core/spec/operation.rb,
lib/oas_core/spec/parameter.rb,
lib/oas_core/spec/path_item.rb,
lib/oas_core/spec/reference.rb,
lib/oas_core/spec/responses.rb,
lib/oas_core/spec/components.rb,
lib/oas_core/spec/media_type.rb,
lib/oas_core/yard/example_tag.rb,
lib/oas_core/spec/request_body.rb,
lib/oas_core/yard/response_tag.rb,
lib/oas_core/spec/specification.rb,
lib/oas_core/yard/parameter_tag.rb,
lib/oas_core/yard/reference_tag.rb,
lib/oas_core/json_schema_generator.rb,
lib/oas_core/yard/oas_core_factory.rb,
lib/oas_core/yard/request_body_tag.rb,
lib/oas_core/builders/content_builder.rb,
lib/oas_core/builders/response_builder.rb,
lib/oas_core/yard/response_example_tag.rb,
lib/oas_core/builders/operation_builder.rb,
lib/oas_core/builders/parameter_builder.rb,
lib/oas_core/builders/path_item_builder.rb,
lib/oas_core/builders/responses_builder.rb,
lib/oas_core/builders/parameters_builder.rb,
lib/oas_core/yard/response_reference_tag.rb,
lib/oas_core/yard/parameter_reference_tag.rb,
lib/oas_core/builders/request_body_builder.rb,
lib/oas_core/yard/request_body_example_tag.rb,
lib/oas_core/builders/specification_builder.rb,
lib/oas_core/yard/request_body_reference_tag.rb

Defined Under Namespace

Modules: Builders, Errors, JsonSchemaGenerator, Spec, Utils, YARD Classes: Configuration, OasRoute

Constant Summary collapse

VERSION =
'1.2.0'
DEFAULT_SECURITY_SCHEMES =
{
  api_key_cookie: {
    type: 'apiKey',
    in: 'cookie',
    name: 'api_key',
    description: 'An API key that will be supplied in a named cookie.'
  },
  api_key_header: {
    type: 'apiKey',
    in: 'header',
    name: 'X-API-Key',
    description: 'An API key that will be supplied in a named header.'
  },
  api_key_query: {
    type: 'apiKey',
    in: 'query',
    name: 'apiKey',
    description: 'An API key that will be supplied in a named query parameter.'
  },
  basic: {
    type: 'http',
    scheme: 'basic',
    description: "Basic auth that takes a base64'd combination of `user:password`."
  },
  bearer: {
    type: 'http',
    scheme: 'bearer',
    description: 'A bearer token that will be supplied within an `Authorization` header as `bearer <token>`.'
  },
  bearer_jwt: {
    type: 'http',
    scheme: 'bearer',
    bearerFormat: 'JWT',
    description: 'A bearer token that will be supplied within an `Authorization` header as `bearer <token>`. In this case, the format of the token is specified as JWT.'
  },
  mutual_tls: {
    type: 'mutualTLS',
    description: 'Requires a specific mutual TLS certificate to use when making an HTTP request.'
  }
}.freeze

Class Method Summary collapse

Class Method Details

.build(oas_routes, oas_source: {}) ⇒ Object



102
103
104
105
106
# File 'lib/oas_core.rb', line 102

def build(oas_routes, oas_source: {})
  oas = Builders::SpecificationBuilder.new.with_oas_routes(oas_routes).build.to_spec

  oas_source.deeper_merge(oas, merge_hash_arrays: true, extend_existing_arrays: true)
end

.configObject



76
77
78
# File 'lib/oas_core.rb', line 76

def config
  @config ||= Configuration.new
end

.config=(config) ⇒ Object



70
71
72
73
74
# File 'lib/oas_core.rb', line 70

def config=(config)
  raise 'Configuration must be an OasCore::Configuration or its subclass' unless config.is_a?(OasCore::Configuration)

  @config = config
end

.configure_yard!Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/oas_core.rb', line 80

def configure_yard!
  ::YARD::Tags::Library.default_factory = YARD::OasCoreFactory
  yard_tags = {
    'Request body' => %i[request_body with_request_body],
    'Request body Reference' => %i[request_body_ref with_request_body_reference],
    'Request body Example' => %i[request_body_example with_request_body_example],
    'Parameter' => %i[parameter with_parameter],
    'Parameter Reference' => %i[parameter_ref with_parameter_reference],
    'Response' => %i[response with_response],
    'Response Reference' => %i[response_ref with_response_reference],
    'Response Example' => %i[response_example with_response_example],
    'Endpoint Tags' => [:tags],
    'Summary' => [:summary],
    'No Auth' => [:no_auth],
    'Auth methods' => %i[auth with_types],
    'OAS Include' => [:oas_include]
  }
  yard_tags.each do |tag_name, (method_name, handler)|
    ::YARD::Tags::Library.define_tag(tag_name, method_name, handler)
  end
end