Class: OasRails::Spec::Specification

Inherits:
Object
  • Object
show all
Includes:
Specable
Defined in:
lib/oas_rails/spec/specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Specable

#as_json, #to_spec

Constructor Details

#initializeSpecification

Initializes a new Specification object. Clears the cache if running in the development environment.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/oas_rails/spec/specification.rb', line 11

def initialize
  clear_cache unless Rails.env.production?

  @components = Components.new(self)
  @info = OasRails.config.info
  @openapi = '3.1.0'
  @servers = OasRails.config.servers
  @tags = OasRails.config.tags
  @external_docs = {}
  @paths = Spec::Paths.new(self)
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def components
  @components
end

#external_docsObject

Returns the value of attribute external_docs.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def external_docs
  @external_docs
end

#infoObject

Returns the value of attribute info.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def info
  @info
end

#openapiObject

Returns the value of attribute openapi.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def openapi
  @openapi
end

#pathsObject

Returns the value of attribute paths.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def paths
  @paths
end

#serversObject

Returns the value of attribute servers.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def servers
  @servers
end

#tagsObject

Returns the value of attribute tags.



7
8
9
# File 'lib/oas_rails/spec/specification.rb', line 7

def tags
  @tags
end

Instance Method Details

#build(route_extractor: Extractors::RouteExtractor) ⇒ Object



23
24
25
26
27
# File 'lib/oas_rails/spec/specification.rb', line 23

def build(route_extractor: Extractors::RouteExtractor)
  route_extractor.host_paths.each do |path|
    @paths.add_path(path)
  end
end

#clear_cachevoid

This method returns an undefined value.

Clears the cache for MethodSource and RouteExtractor.



32
33
34
35
# File 'lib/oas_rails/spec/specification.rb', line 32

def clear_cache
  MethodSource.clear_cache
  Extractors::RouteExtractor.clear_cache
end

#oas_fieldsObject



37
38
39
# File 'lib/oas_rails/spec/specification.rb', line 37

def oas_fields
  [:openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs]
end

#securityObject

Create the Security Requirement Object.



43
44
45
46
47
# File 'lib/oas_rails/spec/specification.rb', line 43

def security
  return [] unless OasRails.config.authenticate_all_routes_by_default

  OasRails.config.security_schemas.map { |key, _| { key => [] } }
end