Class: Docit::SchemaGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/docit/schema_generator.rb

Overview

Converts the Registry of operations and Configuration into an OpenAPI 3.0.3 spec hash.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generateObject



6
7
8
# File 'lib/docit/schema_generator.rb', line 6

def self.generate
  new.generate
end

Instance Method Details

#generateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/docit/schema_generator.rb', line 10

def generate
  config = Docit.configuration

  spec = {
    openapi: "3.0.3",
    info: {
      title: config.title,
      version: config.version,
      description: config.description
    },
    paths: build_paths,
    components: {
      securitySchemes: config.security_schemes
    }
  }

  tag_defs = config.tags
  spec[:tags] = tag_defs if tag_defs.any?

  server_defs = config.servers
  spec[:servers] = server_defs if server_defs.any?

  schemas = build_component_schemas
  spec[:components][:schemas] = schemas if schemas.any?

  spec
end