media_types-serialization 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitignore +2 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +114 -84
- data/README.md +14 -1
- data/lib/media_types/problem.rb +7 -4
- data/lib/media_types/serialization/serialization_dsl.rb +19 -1
- data/lib/media_types/serialization/serializers/api_viewer.rb +22 -19
- data/lib/media_types/serialization/serializers/common_css.rb +24 -24
- data/lib/media_types/serialization/serializers/input_validation_error_serializer.rb +18 -14
- data/lib/media_types/serialization/serializers/problem_serializer.rb +15 -4
- data/lib/media_types/serialization/version.rb +2 -1
- data/lib/media_types/serialization.rb +8 -4
- data/media_types-serialization.gemspec +4 -4
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '096826bd7e4a4be4fcd147fec07f26d05aec0101b8651ae63ed376a7a2388077'
|
4
|
+
data.tar.gz: 2f783986be7ca3eff779e10a2ace5338d9ab7dbb755334ae79d01d7b422a77c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0b58cdb8eb8e4f8c0c8ad73cc607673768cba38399cf9c804db16a54198b3fe0799a18c641e7c05d10e03c2936fc96a416b80ff51ff4bd5e6d570b10a47e712
|
7
|
+
data.tar.gz: e82051321d55df89abe34c6d43e62a0158245c4fb9ae60060fc3e939df854626b3014285f2ac277f7632f6c3cd099ef349265bdfffbf7b7b226f76287bb53147
|
data/.github/workflows/ci.yml
CHANGED
@@ -17,12 +17,12 @@ jobs:
|
|
17
17
|
|
18
18
|
strategy:
|
19
19
|
matrix:
|
20
|
-
ruby-version: [
|
20
|
+
ruby-version: ["3.1", "3.0", "2.7"]
|
21
21
|
|
22
22
|
steps:
|
23
23
|
- uses: actions/checkout@v1
|
24
24
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
25
|
-
uses:
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
26
|
with:
|
27
27
|
ruby-version: ${{ matrix.ruby-version }}
|
28
28
|
- name: Build and test with Rake
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,128 +1,158 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
media_types-serialization (1.
|
5
|
-
actionpack (>=
|
6
|
-
activesupport (>=
|
7
|
-
media_types (>= 2.
|
4
|
+
media_types-serialization (1.4.0)
|
5
|
+
actionpack (>= 6.0.0)
|
6
|
+
activesupport (>= 6.0.0)
|
7
|
+
media_types (>= 2.2.0, < 3.0.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actioncable (
|
13
|
-
actionpack (=
|
12
|
+
actioncable (6.1.7.3)
|
13
|
+
actionpack (= 6.1.7.3)
|
14
|
+
activesupport (= 6.1.7.3)
|
14
15
|
nio4r (~> 2.0)
|
15
16
|
websocket-driver (>= 0.6.1)
|
16
|
-
|
17
|
-
actionpack (=
|
18
|
-
|
19
|
-
|
17
|
+
actionmailbox (6.1.7.3)
|
18
|
+
actionpack (= 6.1.7.3)
|
19
|
+
activejob (= 6.1.7.3)
|
20
|
+
activerecord (= 6.1.7.3)
|
21
|
+
activestorage (= 6.1.7.3)
|
22
|
+
activesupport (= 6.1.7.3)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.1.7.3)
|
25
|
+
actionpack (= 6.1.7.3)
|
26
|
+
actionview (= 6.1.7.3)
|
27
|
+
activejob (= 6.1.7.3)
|
28
|
+
activesupport (= 6.1.7.3)
|
20
29
|
mail (~> 2.5, >= 2.5.4)
|
21
30
|
rails-dom-testing (~> 2.0)
|
22
|
-
actionpack (
|
23
|
-
actionview (=
|
24
|
-
activesupport (=
|
25
|
-
rack (~> 2.0, >= 2.0.
|
31
|
+
actionpack (6.1.7.3)
|
32
|
+
actionview (= 6.1.7.3)
|
33
|
+
activesupport (= 6.1.7.3)
|
34
|
+
rack (~> 2.0, >= 2.0.9)
|
26
35
|
rack-test (>= 0.6.3)
|
27
36
|
rails-dom-testing (~> 2.0)
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
29
|
-
|
30
|
-
|
37
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
+
actiontext (6.1.7.3)
|
39
|
+
actionpack (= 6.1.7.3)
|
40
|
+
activerecord (= 6.1.7.3)
|
41
|
+
activestorage (= 6.1.7.3)
|
42
|
+
activesupport (= 6.1.7.3)
|
43
|
+
nokogiri (>= 1.8.5)
|
44
|
+
actionview (6.1.7.3)
|
45
|
+
activesupport (= 6.1.7.3)
|
31
46
|
builder (~> 3.1)
|
32
47
|
erubi (~> 1.4)
|
33
48
|
rails-dom-testing (~> 2.0)
|
34
|
-
rails-html-sanitizer (~> 1.
|
35
|
-
activejob (
|
36
|
-
activesupport (=
|
49
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
+
activejob (6.1.7.3)
|
51
|
+
activesupport (= 6.1.7.3)
|
37
52
|
globalid (>= 0.3.6)
|
38
|
-
activemodel (
|
39
|
-
activesupport (=
|
40
|
-
activerecord (
|
41
|
-
activemodel (=
|
42
|
-
activesupport (=
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
activerecord (=
|
47
|
-
|
48
|
-
|
53
|
+
activemodel (6.1.7.3)
|
54
|
+
activesupport (= 6.1.7.3)
|
55
|
+
activerecord (6.1.7.3)
|
56
|
+
activemodel (= 6.1.7.3)
|
57
|
+
activesupport (= 6.1.7.3)
|
58
|
+
activestorage (6.1.7.3)
|
59
|
+
actionpack (= 6.1.7.3)
|
60
|
+
activejob (= 6.1.7.3)
|
61
|
+
activerecord (= 6.1.7.3)
|
62
|
+
activesupport (= 6.1.7.3)
|
63
|
+
marcel (~> 1.0)
|
64
|
+
mini_mime (>= 1.1.0)
|
65
|
+
activesupport (6.1.7.3)
|
49
66
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
|
-
i18n (>=
|
51
|
-
minitest (
|
52
|
-
tzinfo (~>
|
53
|
-
|
67
|
+
i18n (>= 1.6, < 2)
|
68
|
+
minitest (>= 5.1)
|
69
|
+
tzinfo (~> 2.0)
|
70
|
+
zeitwerk (~> 2.3)
|
54
71
|
awesome_print (1.9.2)
|
55
72
|
builder (3.2.4)
|
56
|
-
concurrent-ruby (1.
|
73
|
+
concurrent-ruby (1.2.2)
|
57
74
|
crass (1.0.6)
|
58
|
-
|
59
|
-
|
75
|
+
date (3.3.3)
|
76
|
+
erubi (1.12.0)
|
77
|
+
globalid (1.1.0)
|
60
78
|
activesupport (>= 5.0)
|
61
|
-
i18n (1.
|
79
|
+
i18n (1.12.0)
|
62
80
|
concurrent-ruby (~> 1.0)
|
63
|
-
loofah (2.
|
81
|
+
loofah (2.19.1)
|
64
82
|
crass (~> 1.0.2)
|
65
83
|
nokogiri (>= 1.5.9)
|
66
|
-
mail (2.
|
84
|
+
mail (2.8.1)
|
67
85
|
mini_mime (>= 0.1.1)
|
68
|
-
|
69
|
-
|
86
|
+
net-imap
|
87
|
+
net-pop
|
88
|
+
net-smtp
|
89
|
+
marcel (1.0.2)
|
90
|
+
media_types (2.2.0)
|
70
91
|
method_source (1.0.0)
|
71
|
-
mini_mime (1.1.
|
72
|
-
minitest (5.
|
92
|
+
mini_mime (1.1.2)
|
93
|
+
minitest (5.18.0)
|
94
|
+
net-imap (0.3.4)
|
95
|
+
date
|
96
|
+
net-protocol
|
97
|
+
net-pop (0.1.2)
|
98
|
+
net-protocol
|
99
|
+
net-protocol (0.2.1)
|
100
|
+
timeout
|
101
|
+
net-smtp (0.3.3)
|
102
|
+
net-protocol
|
73
103
|
nio4r (2.5.8)
|
74
|
-
nokogiri (1.
|
104
|
+
nokogiri (1.14.2-x64-mingw32)
|
75
105
|
racc (~> 1.4)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
actionview (=
|
88
|
-
activejob (=
|
89
|
-
activemodel (=
|
90
|
-
activerecord (=
|
91
|
-
activestorage (=
|
92
|
-
activesupport (=
|
93
|
-
bundler (>= 1.
|
94
|
-
railties (=
|
106
|
+
oj (3.14.2)
|
107
|
+
racc (1.6.2)
|
108
|
+
rack (2.2.6.4)
|
109
|
+
rack-test (2.1.0)
|
110
|
+
rack (>= 1.3)
|
111
|
+
rails (6.1.7.3)
|
112
|
+
actioncable (= 6.1.7.3)
|
113
|
+
actionmailbox (= 6.1.7.3)
|
114
|
+
actionmailer (= 6.1.7.3)
|
115
|
+
actionpack (= 6.1.7.3)
|
116
|
+
actiontext (= 6.1.7.3)
|
117
|
+
actionview (= 6.1.7.3)
|
118
|
+
activejob (= 6.1.7.3)
|
119
|
+
activemodel (= 6.1.7.3)
|
120
|
+
activerecord (= 6.1.7.3)
|
121
|
+
activestorage (= 6.1.7.3)
|
122
|
+
activesupport (= 6.1.7.3)
|
123
|
+
bundler (>= 1.15.0)
|
124
|
+
railties (= 6.1.7.3)
|
95
125
|
sprockets-rails (>= 2.0.0)
|
96
126
|
rails-dom-testing (2.0.3)
|
97
127
|
activesupport (>= 4.2.0)
|
98
128
|
nokogiri (>= 1.6)
|
99
|
-
rails-html-sanitizer (1.
|
100
|
-
loofah (~> 2.
|
101
|
-
railties (
|
102
|
-
actionpack (=
|
103
|
-
activesupport (=
|
129
|
+
rails-html-sanitizer (1.5.0)
|
130
|
+
loofah (~> 2.19, >= 2.19.1)
|
131
|
+
railties (6.1.7.3)
|
132
|
+
actionpack (= 6.1.7.3)
|
133
|
+
activesupport (= 6.1.7.3)
|
104
134
|
method_source
|
105
|
-
rake (>=
|
106
|
-
thor (
|
135
|
+
rake (>= 12.2)
|
136
|
+
thor (~> 1.0)
|
107
137
|
rake (13.0.6)
|
108
|
-
sprockets (4.0
|
138
|
+
sprockets (4.2.0)
|
109
139
|
concurrent-ruby (~> 1.0)
|
110
|
-
rack (
|
111
|
-
sprockets-rails (3.
|
112
|
-
actionpack (>=
|
113
|
-
activesupport (>=
|
140
|
+
rack (>= 2.2.4, < 4)
|
141
|
+
sprockets-rails (3.4.2)
|
142
|
+
actionpack (>= 5.2)
|
143
|
+
activesupport (>= 5.2)
|
114
144
|
sprockets (>= 3.0.0)
|
115
|
-
thor (1.1
|
116
|
-
|
117
|
-
tzinfo (
|
118
|
-
|
145
|
+
thor (1.2.1)
|
146
|
+
timeout (0.3.2)
|
147
|
+
tzinfo (2.0.6)
|
148
|
+
concurrent-ruby (~> 1.0)
|
119
149
|
websocket-driver (0.7.5)
|
120
150
|
websocket-extensions (>= 0.1.0)
|
121
151
|
websocket-extensions (0.1.5)
|
152
|
+
zeitwerk (2.6.7)
|
122
153
|
|
123
154
|
PLATFORMS
|
124
155
|
x64-mingw32
|
125
|
-
x86_64-linux
|
126
156
|
|
127
157
|
DEPENDENCIES
|
128
158
|
awesome_print
|
@@ -130,8 +160,8 @@ DEPENDENCIES
|
|
130
160
|
media_types-serialization!
|
131
161
|
minitest (~> 5.0)
|
132
162
|
oj
|
133
|
-
rails (~>
|
163
|
+
rails (~> 6.0)
|
134
164
|
rake (~> 13.0)
|
135
165
|
|
136
166
|
BUNDLED WITH
|
137
|
-
2.
|
167
|
+
2.1.4
|
data/README.md
CHANGED
@@ -887,7 +887,15 @@ Can be used to render a view.
|
|
887
887
|
You can set local variables in the view by assigning a hash to the `assigns:` parameter.
|
888
888
|
Returns a `string`
|
889
889
|
|
890
|
-
> When possible, prefer `output_raw` with
|
890
|
+
> When possible, prefer `output_raw` with context.render_to_string(params)`
|
891
|
+
|
892
|
+
#### `redirect_to(url, context, **options)`
|
893
|
+
|
894
|
+
This redirects the user to the specified url when this serializer is rendered. The output of the serializer is still shown in the API viewer.
|
895
|
+
|
896
|
+
#### `suppress_render do |result|`
|
897
|
+
|
898
|
+
Replaces the render at the end of `render_media` and substitutes it with the contents of the block.
|
891
899
|
|
892
900
|
### Controller definition
|
893
901
|
|
@@ -916,6 +924,11 @@ Outputs the specified description as help information.
|
|
916
924
|
|
917
925
|
Accepts the same filters as `before_action`.
|
918
926
|
|
927
|
+
#### `output_error(klazz, serializers = []) do`
|
928
|
+
|
929
|
+
Wraps the controller method in a `rescue_from` and presents the users with a `text/html` or `application/problem+json` representation of the error.
|
930
|
+
The `text/html` response can be overridden by supplying an additional serializer in the `serializers` array. It will use the nil view for the given serializers.
|
931
|
+
|
919
932
|
#### `allow_input_serializer( serializer, views: nil, **filters )`
|
920
933
|
|
921
934
|
Configure the controller to allow the client to send bodies with a `Content-Type` that can be deserialized using the specified serializer.
|
data/lib/media_types/problem.rb
CHANGED
@@ -4,7 +4,6 @@ require 'erb'
|
|
4
4
|
|
5
5
|
module MediaTypes
|
6
6
|
class Problem
|
7
|
-
|
8
7
|
def initialize(error)
|
9
8
|
self.error = error
|
10
9
|
self.translations = {}
|
@@ -17,7 +16,7 @@ module MediaTypes
|
|
17
16
|
def type
|
18
17
|
return custom_type unless custom_type.nil?
|
19
18
|
|
20
|
-
"https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util
|
19
|
+
"https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(error.class.name)}"
|
21
20
|
end
|
22
21
|
|
23
22
|
def url(href)
|
@@ -31,13 +30,17 @@ module MediaTypes
|
|
31
30
|
|
32
31
|
def override_detail(detail, lang:)
|
33
32
|
raise 'Unable to override detail message without having a title in the same language.' unless translations[lang]
|
33
|
+
|
34
34
|
translations[lang][:detail] = detail
|
35
35
|
end
|
36
36
|
|
37
37
|
def attribute(name, value)
|
38
38
|
str_name = name.to_s
|
39
39
|
|
40
|
-
|
40
|
+
unless str_name =~ /^[a-zA-Z][a-zA-Z0-9_]{2,}$/
|
41
|
+
raise "Unable to add an attribute with name '#{str_name}'. Name should start with a letter, consist of the " \
|
42
|
+
'letters A-Z, a-z, 0-9 or _ and be at least 3 characters long.'
|
43
|
+
end
|
41
44
|
|
42
45
|
custom_attributes[str_name] = value
|
43
46
|
end
|
@@ -54,7 +57,7 @@ module MediaTypes
|
|
54
57
|
inner = error.cause
|
55
58
|
return nil if inner.nil?
|
56
59
|
|
57
|
-
"https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util
|
60
|
+
"https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(inner.class.name)}"
|
58
61
|
end
|
59
62
|
|
60
63
|
def languages
|
@@ -11,10 +11,11 @@ module MediaTypes
|
|
11
11
|
@serialization_links = links
|
12
12
|
@serialization_context = context
|
13
13
|
@serialization_vary = vary
|
14
|
+
@serialization_custom_render = nil
|
14
15
|
super(serializer)
|
15
16
|
end
|
16
17
|
|
17
|
-
attr_accessor :serialization_dsl_result
|
18
|
+
attr_accessor :serialization_dsl_result, :serialization_custom_render
|
18
19
|
|
19
20
|
def attribute(key, value = {}, &block)
|
20
21
|
unless block.nil?
|
@@ -112,6 +113,23 @@ module MediaTypes
|
|
112
113
|
|
113
114
|
context.serialization_dsl_result
|
114
115
|
end
|
116
|
+
|
117
|
+
def redirect_to(url, context, **options)
|
118
|
+
suppress_render do |result|
|
119
|
+
context.redirect_to(
|
120
|
+
url,
|
121
|
+
**options
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
"Redirecting to: #{url}"
|
126
|
+
end
|
127
|
+
|
128
|
+
def suppress_render(&block)
|
129
|
+
@serialization_custom_render = block || lambda { |result| }
|
130
|
+
|
131
|
+
serialization_dsl_result
|
132
|
+
end
|
115
133
|
end
|
116
134
|
end
|
117
135
|
end
|
@@ -16,7 +16,7 @@ module MediaTypes
|
|
16
16
|
return uri unless viewer.host == current_host
|
17
17
|
|
18
18
|
query_parts = viewer.query&.split('&') || []
|
19
|
-
query_parts = query_parts.
|
19
|
+
query_parts = query_parts.reject { |p| p.starts_with?('api_viewer=') }
|
20
20
|
query_parts.append("api_viewer=#{type}")
|
21
21
|
viewer.query = query_parts.join('&')
|
22
22
|
viewer.to_s
|
@@ -45,42 +45,45 @@ module MediaTypes
|
|
45
45
|
result = {
|
46
46
|
identifier: identifier,
|
47
47
|
href: viewerify(context.request.original_url, context.request.host, type: identifier),
|
48
|
-
selected: identifier == original_identifier
|
48
|
+
selected: identifier == original_identifier
|
49
49
|
}
|
50
50
|
result[:href] = '#output' if identifier == original_identifier
|
51
51
|
|
52
52
|
result
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
map { |l| CGI
|
58
|
-
map
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
escaped_output = original_output
|
56
|
+
&.split("\n")
|
57
|
+
&.map { |l| CGI.escapeHTML(l).gsub(/ (?= )/, ' ') }
|
58
|
+
&.map do |l|
|
59
|
+
l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
|
60
|
+
converted = m
|
61
|
+
invalid = false
|
62
|
+
begin
|
63
|
+
converted = viewerify(m, context.request.host)
|
64
|
+
rescue URI::InvalidURIError
|
65
|
+
invalid = true
|
66
|
+
end
|
67
|
+
style = ''
|
68
|
+
style = ' style="color: red"' if invalid
|
69
|
+
"<a#{style} href=\"#{converted}\">#{m}</a>"
|
65
70
|
end
|
66
|
-
|
67
|
-
|
68
|
-
"<a#{style} href=\"#{converted}\">#{m}</a>"
|
69
|
-
end) }.
|
70
|
-
join("<br>\n")
|
71
|
-
|
71
|
+
end
|
72
|
+
&.join("<br>\n")
|
72
73
|
|
73
74
|
input = OpenStruct.new(
|
74
75
|
original_identifier: original_identifier,
|
75
76
|
escaped_output: escaped_output,
|
76
77
|
api_fied_links: api_fied_links,
|
77
78
|
media_types: media_types,
|
78
|
-
css: CommonCSS.css
|
79
|
+
css: CommonCSS.css
|
79
80
|
)
|
80
81
|
|
81
82
|
template = ERB.new <<-TEMPLATE
|
82
83
|
<html lang="en">
|
83
84
|
<head>
|
85
|
+
<meta content="width=device-width, initial-scale=1" name="viewport">
|
86
|
+
|
84
87
|
<title>API Viewer [<%= CGI::escapeHTML(original_identifier) %>]</title>
|
85
88
|
<style>
|
86
89
|
<%= css.split("\n").join("\n ") %>
|
@@ -15,28 +15,28 @@ module MediaTypes
|
|
15
15
|
self.logo_media_type = 'image/svg+xml'
|
16
16
|
self.logo_width = 8
|
17
17
|
self.logo_data = <<-HERE
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
18
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 114 93">
|
19
|
+
<title>Delft Solutions</title>
|
20
|
+
|
21
|
+
<filter id="dropshadow">
|
22
|
+
<feGaussianBlur in="SourceAlpha" stdDeviation="1"></feGaussianBlur> <!-- stdDeviation is how much to blur -->
|
23
|
+
<feOffset dx="2" dy="1" result="offsetblur"></feOffset> <!-- how much to offset -->
|
24
|
+
<feComponentTransfer>
|
25
|
+
<feFuncA type="linear" slope="0.5"></feFuncA> <!-- slope is the opacity of the shadow -->
|
26
|
+
</feComponentTransfer>
|
27
|
+
<feMerge>
|
28
|
+
<feMergeNode></feMergeNode> <!-- this contains the offset blurred image -->
|
29
|
+
<feMergeNode in="SourceGraphic"></feMergeNode> <!-- this contains the element that the filter is applied to -->
|
30
|
+
</feMerge>
|
31
|
+
</filter>
|
32
|
+
|
33
|
+
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
34
|
+
<g fill="#FFFFFF" fill-rule="nonzero">
|
35
|
+
|
36
|
+
<path d="M81.5784638,1.07718279e-13 C82.7664738,1.07718279e-13 83.8032488,0.734079641 84.4157016,1.75205281 L109.531129,43.5095713 C110.813908,45.6417099 110.657922,48.2974919 109.15835,50.2831454 L80.6973102,87.9923196 C80.0557678,88.7870619 79.0855103,89.3973447 78.0602378,89.3973447 L42.8594985,89.3973447 L14.6289023,43.5796094 L38.1043811,13.5281311 L47.8307983,13.5281311 L25.7347121,43.6175319 L48.0361926,79.9158441 L75.0253918,79.9158441 L101.326814,46.2820182 L73.5454136,1.07718279e-13 L81.5784638,1.07718279e-13 Z M68.8174965,0.000338312914 L96.4191607,45.9808751 L73.2382461,75.6684695 L61.4283598,75.6684695 L84.975762,45.385564 L63.4142078,9.46643441 L36.1380842,9.46643441 L9.60299852,43.3032035 L35.9112712,85.3931029 L38.1241857,89.3191214 L29.1498474,89.3973434 C27.9592604,89.4075947 26.8506993,88.7919375 26.2302294,87.7757572 L0.893096605,46.2796422 C-0.418595034,44.1314075 -0.274907213,41.3978442 1.25477457,39.3989643 L30.388821,1.32865425 L30.4563519,1.24328222 C31.0981823,0.458113729 32.0600455,0.000338312914 33.0779839,0.000338312914 L68.8174965,0.000338312914 Z" id="logo-mark-colour"></path>
|
37
|
+
</g>
|
38
|
+
</g>
|
39
|
+
</svg>
|
40
40
|
HERE
|
41
41
|
|
42
42
|
def self.logo_url
|
@@ -78,7 +78,7 @@ module MediaTypes
|
|
78
78
|
a:hover {
|
79
79
|
color: #5E7EFF;
|
80
80
|
}
|
81
|
-
|
81
|
+
|
82
82
|
#logo {
|
83
83
|
width: <%= logo_width %>em;
|
84
84
|
height: 6em;
|
@@ -160,7 +160,7 @@ module MediaTypes
|
|
160
160
|
TEMPLATE
|
161
161
|
template = ERB.new custom_css unless custom_css.nil?
|
162
162
|
|
163
|
-
template.result(binding
|
163
|
+
template.result(binding)
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -11,21 +11,24 @@ module MediaTypes
|
|
11
11
|
unvalidated 'text/html'
|
12
12
|
|
13
13
|
def self.escape_text(text)
|
14
|
-
text
|
15
|
-
|
16
|
-
map { |l| (l.gsub(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
text
|
15
|
+
.split("\n")
|
16
|
+
.map { |l| CGI.escapeHTML(l).gsub(/ (?= )/, ' ') }
|
17
|
+
.map do |l|
|
18
|
+
l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
|
19
|
+
converted = m
|
20
|
+
invalid = false
|
21
|
+
begin
|
22
|
+
converted = viewerify(m, context.request.host)
|
23
|
+
rescue URI::InvalidURIError
|
24
|
+
invalid = true
|
25
|
+
end
|
26
|
+
style = ''
|
27
|
+
style = ' style="color: red"' if invalid
|
28
|
+
"<a#{style} href=\"#{converted}\">#{m}</a>"
|
23
29
|
end
|
24
|
-
|
25
|
-
|
26
|
-
"<a#{style} href=\"#{converted}\">#{m}</a>"
|
27
|
-
end) }.
|
28
|
-
join("<br>\n")
|
30
|
+
end
|
31
|
+
.join("<br>\n")
|
29
32
|
end
|
30
33
|
|
31
34
|
output_raw do |obj, version, context|
|
@@ -46,6 +49,7 @@ module MediaTypes
|
|
46
49
|
template = ERB.new <<-TEMPLATE
|
47
50
|
<html lang="en">
|
48
51
|
<head>
|
52
|
+
<meta content="width=device-width, initial-scale=1" name="viewport">
|
49
53
|
<title>Invalid input detected</title>
|
50
54
|
<style>
|
51
55
|
<%= css.split("\n").join("\n ") %>
|
@@ -15,7 +15,9 @@ module MediaTypes
|
|
15
15
|
output do |problem, _, context|
|
16
16
|
raise 'No translations defined, add at least one title' unless problem.translations.keys.any?
|
17
17
|
|
18
|
-
accept_language_header = Utils::AcceptLanguageHeader.new(
|
18
|
+
accept_language_header = Utils::AcceptLanguageHeader.new(
|
19
|
+
context.request.get_header(HEADER_ACCEPT_LANGUAGE) || ''
|
20
|
+
)
|
19
21
|
translation_entry = accept_language_header.map do |locale|
|
20
22
|
problem.translations.keys.find do |l|
|
21
23
|
l.start_with? locale.locale
|
@@ -30,6 +32,9 @@ module MediaTypes
|
|
30
32
|
attribute key, value
|
31
33
|
end
|
32
34
|
|
35
|
+
hidden do
|
36
|
+
link :type, href: problem.type
|
37
|
+
end
|
33
38
|
attribute :type, problem.type
|
34
39
|
attribute :title, title unless title.nil?
|
35
40
|
attribute :detail, detail unless detail.nil?
|
@@ -40,13 +45,19 @@ module MediaTypes
|
|
40
45
|
output_alias 'application/problem+json'
|
41
46
|
|
42
47
|
output_raw view: :html do |problem, _, context|
|
43
|
-
accept_language_header = Utils::AcceptLanguageHeader.new(
|
48
|
+
accept_language_header = Utils::AcceptLanguageHeader.new(
|
49
|
+
context.request.get_header(HEADER_ACCEPT_LANGUAGE) || ''
|
50
|
+
)
|
44
51
|
translation_entry = accept_language_header.map do |locale|
|
45
52
|
problem.translations.keys.find do |l|
|
46
53
|
l.starts_with? locale.locale
|
47
54
|
end
|
48
55
|
end.compact.first || problem.translations.keys.first
|
49
56
|
translation = problem.translations[translation_entry]
|
57
|
+
|
58
|
+
hidden do
|
59
|
+
link :type, href: problem.type
|
60
|
+
end
|
50
61
|
|
51
62
|
title = translation[:title]
|
52
63
|
detail = translation[:detail] || problem.error.message
|
@@ -57,12 +68,13 @@ module MediaTypes
|
|
57
68
|
title: title,
|
58
69
|
detail: detail,
|
59
70
|
help_url: problem.type,
|
60
|
-
css: CommonCSS.css
|
71
|
+
css: CommonCSS.css
|
61
72
|
)
|
62
73
|
|
63
74
|
template = ERB.new <<-TEMPLATE
|
64
75
|
<html lang="en">
|
65
76
|
<head>
|
77
|
+
<meta content="width=device-width, initial-scale=1" name="viewport">
|
66
78
|
<title>Error - <%= CGI::escapeHTML(title) %></title>
|
67
79
|
<style>
|
68
80
|
<%= css.split("\n").join("\n ") %>
|
@@ -93,7 +105,6 @@ module MediaTypes
|
|
93
105
|
enable_wildcards
|
94
106
|
|
95
107
|
output_alias_optional 'text/html', view: :html
|
96
|
-
|
97
108
|
end
|
98
109
|
end
|
99
110
|
end
|
@@ -321,7 +321,7 @@ module MediaTypes
|
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
324
|
-
def output_error(klazz)
|
324
|
+
def output_error(klazz, serializers: [])
|
325
325
|
rescue_from klazz do |error|
|
326
326
|
problem = Problem.new(error)
|
327
327
|
instance_exec { yield problem, error, self } if block_given?
|
@@ -331,7 +331,7 @@ module MediaTypes
|
|
331
331
|
|
332
332
|
render_media(
|
333
333
|
problem,
|
334
|
-
serializers: [registrations],
|
334
|
+
serializers: [registrations] + serializers.map { |s| s.outputs_for(views: [nil])},
|
335
335
|
status: problem.response_status_code
|
336
336
|
)
|
337
337
|
end
|
@@ -663,9 +663,13 @@ module MediaTypes
|
|
663
663
|
return
|
664
664
|
end
|
665
665
|
|
666
|
-
|
666
|
+
if context.serialization_custom_render.nil?
|
667
|
+
render body: result, **options
|
667
668
|
|
668
|
-
|
669
|
+
response.content_type = registrations.identifier_for(identifier)
|
670
|
+
else
|
671
|
+
context.serialization_custom_render.call(result)
|
672
|
+
end
|
669
673
|
end
|
670
674
|
end
|
671
675
|
end
|
@@ -35,13 +35,13 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
-
spec.add_dependency 'actionpack', '>=
|
39
|
-
spec.add_dependency 'activesupport', '>=
|
40
|
-
spec.add_dependency 'media_types', '>= 2.
|
38
|
+
spec.add_dependency 'actionpack', '>= 6.0.0'
|
39
|
+
spec.add_dependency 'activesupport', '>= 6.0.0'
|
40
|
+
spec.add_dependency 'media_types', '>= 2.2.0', '< 3.0.0'
|
41
41
|
|
42
42
|
spec.add_development_dependency 'awesome_print'
|
43
43
|
spec.add_development_dependency 'bundler'
|
44
|
-
spec.add_development_dependency 'rails', '~>
|
44
|
+
spec.add_development_dependency 'rails', '~> 6.0'
|
45
45
|
spec.add_development_dependency 'rake', '~> 13.0'
|
46
46
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
47
47
|
spec.add_development_dependency 'oj'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_types-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -17,35 +17,35 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 6.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 6.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 6.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 6.0.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: media_types
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
48
|
+
version: 2.2.0
|
49
49
|
- - "<"
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: 3.0.0
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.
|
58
|
+
version: 2.2.0
|
59
59
|
- - "<"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.0.0
|
@@ -93,14 +93,14 @@ dependencies:
|
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '6.0'
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '6.0'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: rake
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|