media_types-serialization 1.3.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +32 -32
  3. data/.github/workflows/publish-bookworm.yml +33 -0
  4. data/.github/workflows/publish-sid.yml +33 -0
  5. data/.gitignore +22 -12
  6. data/.idea/.rakeTasks +7 -7
  7. data/.idea/dictionaries/Derk_Jan.xml +6 -6
  8. data/.idea/encodings.xml +3 -3
  9. data/.idea/inspectionProfiles/Project_Default.xml +5 -5
  10. data/.idea/media_types-serialization.iml +76 -76
  11. data/.idea/misc.xml +6 -6
  12. data/.idea/modules.xml +7 -7
  13. data/.idea/runConfigurations/test.xml +19 -19
  14. data/.idea/vcs.xml +5 -5
  15. data/CHANGELOG.md +190 -178
  16. data/CODE_OF_CONDUCT.md +74 -74
  17. data/Gemfile +4 -4
  18. data/LICENSE.txt +21 -21
  19. data/README.md +1048 -1035
  20. data/Rakefile +10 -10
  21. data/bin/console +14 -14
  22. data/bin/setup +8 -8
  23. data/lib/media_types/problem.rb +67 -67
  24. data/lib/media_types/serialization/base.rb +269 -216
  25. data/lib/media_types/serialization/error.rb +193 -193
  26. data/lib/media_types/serialization/fake_validator.rb +53 -53
  27. data/lib/media_types/serialization/serialization_dsl.rb +135 -117
  28. data/lib/media_types/serialization/serialization_registration.rb +245 -245
  29. data/lib/media_types/serialization/serializers/api_viewer.rb +383 -136
  30. data/lib/media_types/serialization/serializers/common_css.rb +212 -168
  31. data/lib/media_types/serialization/serializers/endpoint_description_serializer.rb +80 -80
  32. data/lib/media_types/serialization/serializers/fallback_not_acceptable_serializer.rb +85 -85
  33. data/lib/media_types/serialization/serializers/fallback_unsupported_media_type_serializer.rb +58 -58
  34. data/lib/media_types/serialization/serializers/input_validation_error_serializer.rb +93 -93
  35. data/lib/media_types/serialization/serializers/problem_serializer.rb +111 -104
  36. data/lib/media_types/serialization/utils/accept_header.rb +77 -77
  37. data/lib/media_types/serialization/utils/accept_language_header.rb +82 -82
  38. data/lib/media_types/serialization/version.rb +7 -7
  39. data/lib/media_types/serialization.rb +682 -671
  40. data/media_types-serialization.gemspec +48 -48
  41. metadata +17 -16
  42. data/Gemfile.lock +0 -137
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "media_types/serialization"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "media_types/serialization"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,67 +1,67 @@
1
- # frozen_string_literal: true
2
-
3
- require 'erb'
4
-
5
- module MediaTypes
6
- class Problem
7
- def initialize(error)
8
- self.error = error
9
- self.translations = {}
10
- self.custom_attributes = {}
11
- self.response_status_code = 400
12
- end
13
-
14
- attr_accessor :error, :translations, :custom_type, :custom_attributes, :response_status_code
15
-
16
- def type
17
- return custom_type unless custom_type.nil?
18
-
19
- "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(error.class.name)}"
20
- end
21
-
22
- def url(href)
23
- self.custom_type = href
24
- end
25
-
26
- def title(title, lang:)
27
- translations[lang] ||= {}
28
- translations[lang][:title] = title
29
- end
30
-
31
- def override_detail(detail, lang:)
32
- raise 'Unable to override detail message without having a title in the same language.' unless translations[lang]
33
-
34
- translations[lang][:detail] = detail
35
- end
36
-
37
- def attribute(name, value)
38
- str_name = name.to_s
39
-
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
44
-
45
- custom_attributes[str_name] = value
46
- end
47
-
48
- def status_code(code)
49
- code = Rack::Utils::SYMBOL_TO_STATUS_CODE[code] if code.is_a? Symbol
50
-
51
- self.response_status_code = code
52
- end
53
-
54
- def instance
55
- return nil unless custom_type.nil?
56
-
57
- inner = error.cause
58
- return nil if inner.nil?
59
-
60
- "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(inner.class.name)}"
61
- end
62
-
63
- def languages
64
- translations.keys
65
- end
66
- end
67
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module MediaTypes
6
+ class Problem
7
+ def initialize(error)
8
+ self.error = error
9
+ self.translations = {}
10
+ self.custom_attributes = {}
11
+ self.response_status_code = 400
12
+ end
13
+
14
+ attr_accessor :error, :translations, :custom_type, :custom_attributes, :response_status_code
15
+
16
+ def type
17
+ return custom_type unless custom_type.nil?
18
+
19
+ "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(error.class.name)}"
20
+ end
21
+
22
+ def url(href)
23
+ self.custom_type = href
24
+ end
25
+
26
+ def title(title, lang:)
27
+ translations[lang] ||= {}
28
+ translations[lang][:title] = title
29
+ end
30
+
31
+ def override_detail(detail, lang:)
32
+ raise 'Unable to override detail message without having a title in the same language.' unless translations[lang]
33
+
34
+ translations[lang][:detail] = detail
35
+ end
36
+
37
+ def attribute(name, value)
38
+ str_name = name.to_s
39
+
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
44
+
45
+ custom_attributes[str_name] = value
46
+ end
47
+
48
+ def status_code(code)
49
+ code = Rack::Utils::SYMBOL_TO_STATUS_CODE[code] if code.is_a? Symbol
50
+
51
+ self.response_status_code = code
52
+ end
53
+
54
+ def instance
55
+ return nil unless custom_type.nil?
56
+
57
+ inner = error.cause
58
+ return nil if inner.nil?
59
+
60
+ "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(inner.class.name)}"
61
+ end
62
+
63
+ def languages
64
+ translations.keys
65
+ end
66
+ end
67
+ end