-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger_helper.rb
195 lines (191 loc) · 6.04 KB
/
swagger_helper.rb
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# frozen_string_literal: true
require "rails_helper"
RSpec.configure do |config|
# Specify a root folder where Swagger JSON files are generated
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need
# to ensure that it's configured to serve Swagger from the same folder
config.swagger_root = Rails.root.join("swagger").to_s
# Define one or more Swagger documents and provide global metadata for each one
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
# be generated at the provided relative path under swagger_root
# By default, the operations defined in spec files are added to the first
# document below. You can override this behavior by adding a swagger_doc tag to the
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
config.swagger_docs = {
"v1/swagger.yaml" => {
openapi: "3.0.1",
info: {
title: "API V1",
version: "v1",
},
basePath: "/api/v1",
servers: [
{
url: "http://{defaultHost}",
variables: {
defaultHost: {
default: "localhost:3000/api/v1",
},
},
},
],
components: {
securitySchemes: {
jwt: {
type: :apiKey,
description: "Bearer ey....",
name: "Authorization",
in: :header,
},
},
schemas: {
error_object: {
type: :object,
properties: {
error: {
type: :string,
description: "Message",
},
},
},
errors_object: {
type: :object,
properties: {
errors: { "$ref" => "#/components/schemas/errors_map" },
},
},
errors_map: {
type: :object,
additionalProperties: {
type: "array",
items: { type: "string" },
},
},
login: {
type: :object,
properties: {
session: { "$ref" => "#/components/schemas/user_field" },
},
required: ["session"],
},
new_user: {
type: :object,
properties: {
user: { "$ref" => "#/components/schemas/user_field" },
},
required: %w[user],
},
user_field: {
type: :object,
properties: {
email: {
type: :string,
description: "Email",
example: "[email protected]",
},
password: {
type: :string,
description: "Password",
example: "Password1234",
},
},
required: %w[email password],
},
user: {
type: :object,
properties: {
id: {
type: :integer,
description: "ID",
},
email: {
type: :string,
description: "Email",
example: "[email protected]",
},
created_at: {
type: :string,
format: :date,
},
updated_at: {
type: :string,
format: :date,
},
},
},
account: {
type: :object,
properties: {
id: { type: :integer },
title: { type: :string, description: "account title and searchable" },
iban: { type: :string, description: "iban number and searchable" },
amount: { type: :decimal, description: "Currenrly hold account balance" },
overdraft_limit: { type: :decimal, description: "overdraft_limit allowed" },
transactions: {
type: :array,
items: { "$ref" => "#/components/schemas/transaction" },
},
},
},
transaction: {
type: :object,
properties: {
id: { type: :integer },
amount: { type: :decimal },
transaction_type: { type: :string, description: "could be deposit or withdraw" },
description: { type: :string },
},
},
new_deposit: {
type: :object,
properties: {
deposit: {
type: :object,
properties: {
amount: { type: :decimal, description: "has to be greater than zero" },
description: { type: :string },
},
},
required: %w[amount],
},
required: %w[deposit],
},
new_withdraw: {
type: :object,
properties: {
withdraw: {
type: :object,
properties: {
amount: { type: :number, description: "has to be greater than zero" },
description: { type: :string },
},
},
required: %w[amount],
},
required: %w[withdraw],
},
new_account: {
type: :object,
properties: {
account: {
type: :object,
properties: {
amount: { type: :number, description: "has to be greater than zero" },
title: { type: :string },
iban: { type: :string },
},
},
required: %w[amount title iban],
},
required: %w[account],
},
},
},
},
}
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'.
# The swagger_docs configuration option has the filename including format in
# the key, this may want to be changed to avoid putting yaml in json files.
# Defaults to json. Accepts ':json' and ':yaml'.
config.swagger_format = :json
end