swagger-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/swagger/api.rb +109 -4
- data/lib/swagger/api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16f8848d68d8e83e8d88c3e6bbf3974c79c1f85149ebe59b7e208ab22b78524d
|
4
|
+
data.tar.gz: f55a8a8a95c9097ba09b0312eb61dd4eb0aa10f508e70fcfbfaab619ef0ca2f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fabfda39fd77b0302505de767de179db91cdcb88f5b45d2423021284499b8acc04430ce4fb314443e0a742f60c8642438199eb438bad1234cad4e41f7d0752d
|
7
|
+
data.tar.gz: 8dd7a9ac27ed97a88303dac2d2cc49a52c368f34e2c8eac6fd8bed07f32b3d00367ac186c5a4e05fa73e3056930512eaf0edb0e7f1e299e00af5ea13e5059a7c
|
data/lib/swagger/api.rb
CHANGED
@@ -1,7 +1,112 @@
|
|
1
|
-
require "swagger/api/version"
|
2
|
-
|
3
1
|
module Swagger
|
4
|
-
|
5
|
-
|
2
|
+
class Api
|
3
|
+
include ActiveAttr::Model
|
4
|
+
include ActiveModel::Validations
|
5
|
+
attribute :openapi, type: String, default: '3.0.0'
|
6
|
+
attribute :servers, default: []
|
7
|
+
attribute :info, type: Object
|
8
|
+
attribute :security, default: [{api_key: []}]
|
9
|
+
attribute :paths, default: []
|
10
|
+
attribute :components, default: {}
|
11
|
+
|
12
|
+
def self.prettify
|
13
|
+
JSON.pretty_generate(JSON.parse(json))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.json
|
17
|
+
create.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create
|
21
|
+
@config ||= Swagger::Api.new(
|
22
|
+
info: info,
|
23
|
+
servers: [{url: server_url}],
|
24
|
+
paths: Paths.new(controllers: config.controllers).create,
|
25
|
+
components: {
|
26
|
+
responses: responses,
|
27
|
+
schemas: Components.new(controllers: config.controllers).create,
|
28
|
+
requestBodies: Swagger::RequestBodies.new(controllers: config.controllers).create,
|
29
|
+
securitySchemes: security_schemes,
|
30
|
+
},
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.config
|
35
|
+
@yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root.to_s}/config/swagger.yml").to_json, object_class: OpenStruct)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.security_schemes
|
39
|
+
{
|
40
|
+
api_key: {
|
41
|
+
type: 'apiKey',
|
42
|
+
name: 'Authorization',
|
43
|
+
in: 'header'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.responses
|
49
|
+
{
|
50
|
+
NotFound: {
|
51
|
+
description: "The specified resource was not found",
|
52
|
+
content: {
|
53
|
+
'application/json; charset=utf-8' => {
|
54
|
+
schema: {
|
55
|
+
type: 'string',
|
56
|
+
example: 'Not Found'
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
},
|
61
|
+
Unauthorized: {
|
62
|
+
description: "Unauthorized",
|
63
|
+
content: {
|
64
|
+
'application/json; charset=utf-8' => {
|
65
|
+
schema: {
|
66
|
+
type: 'string',
|
67
|
+
example: 'Not Authorized'
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
},
|
72
|
+
BadRequest: {
|
73
|
+
description: "Bad Request",
|
74
|
+
content: {
|
75
|
+
'application/json; charset=utf-8' => {
|
76
|
+
schema: {
|
77
|
+
example: ['The field name is invalid.', 'The id must be present'],
|
78
|
+
type: 'array',
|
79
|
+
items: {
|
80
|
+
type: 'string'
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
},
|
86
|
+
Unexpected: {
|
87
|
+
description: "Unexpected Error",
|
88
|
+
content: {
|
89
|
+
'application/json; charset=utf-8' => {
|
90
|
+
schema: {
|
91
|
+
type: 'string',
|
92
|
+
example: 'Unexpected Error'
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.info
|
101
|
+
{
|
102
|
+
version: config.info.version,
|
103
|
+
title: config.info.title,
|
104
|
+
description: config.info.description,
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.server_url
|
109
|
+
config.servers.send(Rails.env).url
|
110
|
+
end
|
6
111
|
end
|
7
112
|
end
|
data/lib/swagger/api/version.rb
CHANGED