schemaless_rest_api 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schemaless_rest_api/entities.rb +3 -0
- data/lib/schemaless_rest_api/mongo_client.rb +1 -0
- data/lib/schemaless_rest_api/rest.ico +0 -0
- data/lib/schemaless_rest_api/rest_server.rb +21 -12
- data/lib/schemaless_rest_api/swagger_builder.rb +3 -3
- data/lib/schemaless_rest_api/version.rb +1 -1
- data/lib/schemaless_rest_api.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f42e7bccaab28e6dc750c4351e18500689d1fb13a72bda6d0f1417cc5cef630
|
4
|
+
data.tar.gz: d47a29830a56c986c04bdc92c0c07758efcbe197de71a0183552af628ee66dc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 366cd2cf898fc3cca3ba5b90d29d44fa08e43b5a0a8154eec309c21d9a7012a8c2498912818f2251e664bf2568bfdbcead72ac59e6d837f6a844fd43b64b2a07
|
7
|
+
data.tar.gz: 65cfacda5630298c9e50165b3a2a5420ecf6965347f32f92226afcb6137716207732377714d9b59d7bdda228e5aacc6f23adb39a97ea0be062bc269804b61568
|
Binary file
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require "sinatra"
|
4
4
|
require "puma"
|
5
5
|
require "route_downcaser"
|
6
|
+
require "prometheus/middleware/collector"
|
7
|
+
require "prometheus/middleware/exporter"
|
6
8
|
require_relative "server_utils"
|
7
9
|
|
8
10
|
# Server with endpoints generated based on Entities with CRUD operations for them
|
@@ -11,32 +13,39 @@ class RestServer < Sinatra::Base
|
|
11
13
|
enable :logging if ENV["debug"] == "true"
|
12
14
|
set :bind, "0.0.0.0"
|
13
15
|
use RouteDowncaser::DowncaseRouteMiddleware
|
16
|
+
use Prometheus::Middleware::Collector
|
17
|
+
use Prometheus::Middleware::Exporter
|
14
18
|
helpers ServerUtils
|
15
19
|
|
16
20
|
before do
|
17
|
-
@request_id = SecureRandom.uuid
|
18
|
-
headers["X-
|
21
|
+
@request_id = SecureRandom.uuid
|
22
|
+
headers["X-Correlation-Id"] = @request_id
|
19
23
|
headers["Access-Control-Allow-Origin"] = "*"
|
20
|
-
log({ msg: "Request"}) if
|
24
|
+
log({ msg: "Request" }) if request.fullpath != ""
|
21
25
|
end
|
22
26
|
|
23
|
-
after do
|
24
|
-
log({ msg: "Response", status: response.status }) if
|
27
|
+
after do
|
28
|
+
log({ msg: "Response", status: response.status }) if request.fullpath != ""
|
25
29
|
end
|
26
30
|
|
27
|
-
|
31
|
+
get "/favicon.ico" do
|
32
|
+
send_file File.join(__dir__, "rest.ico")
|
33
|
+
end
|
34
|
+
|
35
|
+
SWAGGER_FILES = %w[index.css swagger.html swagger-initializer.js swagger-ui-bundle.js swagger-ui-standalone-preset.js
|
36
|
+
swagger-ui.css]
|
28
37
|
|
29
38
|
SWAGGER_FILES.each do |filename|
|
30
39
|
get "/#{filename.gsub(".html", "")}" do
|
31
|
-
if filename.end_with?
|
40
|
+
if filename.end_with? ".json"
|
32
41
|
content_type :json
|
33
|
-
elsif filename.end_with?
|
42
|
+
elsif filename.end_with? ".css"
|
34
43
|
content_type :css
|
35
|
-
elsif filename.end_with?
|
44
|
+
elsif filename.end_with? ".js"
|
36
45
|
content_type :js
|
37
46
|
end
|
38
47
|
|
39
|
-
File.read("
|
48
|
+
File.read(File.join(__dir__, "swagger", filename))
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
@@ -55,7 +64,7 @@ class RestServer < Sinatra::Base
|
|
55
64
|
|
56
65
|
get "/" do
|
57
66
|
summary = { models: Entities.models.keys.to_s,
|
58
|
-
docs_url: "<a href
|
67
|
+
docs_url: "<a href='#{ENV["base_path"]}/swagger'>Swagger docs</a>" }
|
59
68
|
summary[:db] = MongoClient.client.summary.to_s if ENV["mongodb"]
|
60
69
|
JSON.generate(summary)
|
61
70
|
rescue StandardError => e
|
@@ -79,7 +88,7 @@ class RestServer < Sinatra::Base
|
|
79
88
|
else
|
80
89
|
Entities.models[model][id] = data
|
81
90
|
end
|
82
|
-
log({msg: "Created #{id}"})
|
91
|
+
log({ msg: "Created #{id}" })
|
83
92
|
[201, JSON.generate({ id: id })]
|
84
93
|
end
|
85
94
|
|
@@ -13,7 +13,7 @@ class SwaggerBuilder
|
|
13
13
|
doc["info"] = build_info(models)
|
14
14
|
doc["host"] = host_with_port
|
15
15
|
doc["schemes"] = "http"
|
16
|
-
doc["basePath"] = "
|
16
|
+
doc["basePath"] = "/#{ENV["base_path"]}"
|
17
17
|
doc["paths"] = generate_paths_for models
|
18
18
|
JSON.generate(doc)
|
19
19
|
end
|
@@ -57,7 +57,7 @@ class SwaggerBuilder
|
|
57
57
|
}
|
58
58
|
},
|
59
59
|
get: {
|
60
|
-
parameters: [
|
60
|
+
parameters: [
|
61
61
|
{
|
62
62
|
name: "params",
|
63
63
|
description: "Any key can be used to filter #{model} by",
|
@@ -94,7 +94,7 @@ class SwaggerBuilder
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def paths_at_id(model)
|
97
|
-
{
|
97
|
+
{
|
98
98
|
get: {
|
99
99
|
description: "Data of #{model} at passed id",
|
100
100
|
parameters: id_params(model),
|
data/lib/schemaless_rest_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemaless_rest_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: prometheus-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: puma
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,7 @@ files:
|
|
122
136
|
- lib/schemaless_rest_api.rb
|
123
137
|
- lib/schemaless_rest_api/entities.rb
|
124
138
|
- lib/schemaless_rest_api/mongo_client.rb
|
139
|
+
- lib/schemaless_rest_api/rest.ico
|
125
140
|
- lib/schemaless_rest_api/rest_server.rb
|
126
141
|
- lib/schemaless_rest_api/server_utils.rb
|
127
142
|
- lib/schemaless_rest_api/swagger/index.css
|