Module: Swagger::Api

Defined in:
lib/swagger/api.rb,
lib/swagger/api/paths.rb,
lib/swagger/api/actions.rb,
lib/swagger/api/version.rb,
lib/swagger/api/components.rb,
lib/swagger/api/column_schema.rb,
lib/swagger/api/request_bodies.rb,
lib/swagger/api/operations/base.rb,
lib/swagger/api/operations/show.rb,
lib/swagger/api/component_schema.rb,
lib/swagger/api/concerns/columns.rb,
lib/swagger/api/operations/index.rb,
lib/swagger/api/operations/create.rb,
lib/swagger/api/operations/delete.rb,
lib/swagger/api/operations/update.rb

Defined Under Namespace

Modules: Concerns, Operations Classes: Actions, ColumnSchema, ComponentSchema, Components, Paths, RequestBodies

Constant Summary collapse

VERSION =
"0.1.35"

Class Method Summary collapse

Class Method Details

.configObject



30
31
32
# File 'lib/swagger/api.rb', line 30

def self.config
  @yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root.to_s}/config/swagger.yml").to_json, object_class: OpenStruct)
end

.createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/swagger/api.rb', line 14

def self.create
  @config ||= {
    openapi: '3.0.0',
    security: [{api_key: []}],
    info: info,
    servers: [{url: server_url}],
    paths: Paths.new(controllers: config.controllers).create,
    components: {
      responses: responses,
      schemas: Components.new(controllers: config.controllers).create,
      requestBodies: RequestBodies.new(controllers: config.controllers).create,
      securitySchemes: security_schemes,
    },
  }
end

.infoObject



96
97
98
99
100
101
102
# File 'lib/swagger/api.rb', line 96

def self.info
  {
    version: config.info.version,
    title: config.info.title,
    description: config.info.description,
  }
end

.jsonObject



10
11
12
# File 'lib/swagger/api.rb', line 10

def self.json
  create.to_json
end

.prettifyObject



6
7
8
# File 'lib/swagger/api.rb', line 6

def self.prettify
  JSON.pretty_generate(JSON.parse(json))
end

.responsesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/swagger/api.rb', line 44

def self.responses
  {
    NotFound: {
      description: "The specified resource was not found",
      content: {
        'application/json; charset=utf-8' => {
          schema: {
            type: 'string',
            example: 'Not Found'
          }
        }
      }
    },
    Unauthorized: {
      description: "Unauthorized",
      content: {
        'application/json; charset=utf-8' => {
          schema: {
            type: 'string',
            example: 'Not Authorized'
          }
        }
      }
    },
    BadRequest: {
      description: "Bad Request",
      content: {
        'application/json; charset=utf-8' => {
          schema: {
            example: ['The field name is invalid.', 'The id must be present'],
            type: 'array',
            items: {
              type: 'string'
            }
          }
        }
      }
    },
    Unexpected: {
      description: "Unexpected Error",
      content: {
        'application/json; charset=utf-8' => {
          schema: {
            type: 'string',
            example: 'Unexpected Error'
          }
        }
      }
    }
  }
end

.security_schemesObject



34
35
36
37
38
39
40
41
42
# File 'lib/swagger/api.rb', line 34

def self.security_schemes
  {
    api_key: {
      type: 'apiKey',
      name: 'Authorization',
      in: 'header'
    }
  }
end

.server_urlObject



104
105
106
# File 'lib/swagger/api.rb', line 104

def self.server_url
  config.servers.send(Rails.env).url
end