Class: OpenApi::Specification

Inherits:
Object
  • Object
show all
Includes:
EquatableAsContent
Defined in:
lib/open_api/specification.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Constructor Details

#initialize(openapi:, info:, servers: nil, paths:, components: nil, security: nil, tags: nil, external_docs: nil) ⇒ Specification

Returns a new instance of Specification.



8
9
10
11
12
13
14
15
16
# File 'lib/open_api/specification.rb', line 8

def initialize(openapi:, info:, servers: nil, paths:, components: nil, security: nil, tags: nil, external_docs: nil)
  self.openapi = openapi
  self.info = info
  self.paths = paths
  self.components = components
  self.security = security
  self.tags = tags
  self.external_docs = external_docs
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def components
  @components
end

#external_docsObject

Returns the value of attribute external_docs.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def external_docs
  @external_docs
end

#infoObject

Returns the value of attribute info.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def info
  @info
end

#openapiObject

Returns the value of attribute openapi.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def openapi
  @openapi
end

#pathsObject

Returns the value of attribute paths.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def paths
  @paths
end

#securityObject

Returns the value of attribute security.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def security
  @security
end

#serversObject

Returns the value of attribute servers.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def servers
  @servers
end

#tagsObject

Returns the value of attribute tags.



6
7
8
# File 'lib/open_api/specification.rb', line 6

def tags
  @tags
end

Class Method Details

.load(hash) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/open_api/specification.rb', line 30

def self.load(hash)
  return unless hash

  new(
    openapi: hash["openapi"].to_s,
    info: Info.load(hash["info"]),
    paths: Paths.load(hash["paths"]),
    components: Components.load(hash["components"]),
    security: hash["security"]&.map { |requirement_hash| SecurityRequirement.load(requirement_hash) },
    tags: hash["tags"]&.map { |tag_hash| Tag.load(tag_hash) },
    external_docs: ExternalDocumentation.load(hash["externalDocs"]),
  )
end

Instance Method Details

#serializable_hashObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/open_api/specification.rb', line 18

def serializable_hash
  {
    "openapi" => openapi.to_s,
    "info" => info.serializable_hash,
    "paths" => paths.serializable_hash,
    "components" => components&.serializable_hash,
    "security" => security&.map(&:serializable_hash),
    "tags" => tags&.map(&:serializable_hash),
    "externalDocs" => external_docs&.serializable_hash,
  }.compact
end