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.7"
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
29
30
31
|
# File 'lib/swagger/api.rb', line 29
def self.config
@yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root.to_s}/config/swagger.yml").to_json, object_class: OpenStruct)
end
|
.create ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/swagger/api.rb', line 13
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
|
.info ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/swagger/api.rb', line 95
def self.info
{
version: config.info.version,
title: config.info.title,
description: config.info.description,
}
end
|
.json ⇒ Object
9
10
11
|
# File 'lib/swagger/api.rb', line 9
def self.json
create.to_json
end
|
.prettify ⇒ Object
5
6
7
|
# File 'lib/swagger/api.rb', line 5
def self.prettify
JSON.pretty_generate(JSON.parse(json))
end
|
.responses ⇒ Object
43
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
|
# File 'lib/swagger/api.rb', line 43
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_schemes ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/swagger/api.rb', line 33
def self.security_schemes
{
api_key: {
type: 'apiKey',
name: 'Authorization',
in: 'header'
}
}
end
|
.server_url ⇒ Object
103
104
105
|
# File 'lib/swagger/api.rb', line 103
def self.server_url
config.servers.send(Rails.env).url
end
|