Method: Apia::OpenApi::Specification#initialize

Defined in:
lib/apia/open_api/specification.rb

#initialize(api, base_url, name, additions = {}) ⇒ Specification

Returns a new instance of Specification.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/apia/open_api/specification.rb', line 17

def initialize(api, base_url, name, additions = {})
  default_additions = { info: {}, external_docs: {}, security_schemes: {} }
  additions = default_additions.merge(additions)

  @api = api
  @base_url = base_url
  @name = name || "Core" # will be suffixed with 'Api' and used in the client generator
  @spec = {
    openapi: OPEN_API_VERSION,
    info: additions[:info],
    externalDocs: additions[:external_docs],
    servers: [],
    paths: {},
    components: {
      schemas: {}
    },
    security: [],
    tags: [],
    "x-tagGroups": []
  }

  if @spec[:externalDocs].nil? || @spec[:externalDocs].empty?
    @spec.delete(:externalDocs)
  end

  add_additional_security_schemes(additions[:security_schemes])

  # path_ids is used to keep track of all the IDs of all the paths we've generated, to avoid duplicates
  # refer to the Path object for more info
  @path_ids = []
  build_spec
end