api-regulator 0.1.25 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bfac01d6824d8766853d5828ea9f0eddd0e72dd76fb6b97c7bf3927803f7df1
4
- data.tar.gz: 87cb03abe3c0b824fd60192cae2a2e91d856b2781a07e6db17ff6de087e6d81d
3
+ metadata.gz: a9d490065a7ecefa7103daa60c7baaa858d36baf23f5f4458713307ed3f196d8
4
+ data.tar.gz: 12fca76002d7a1dfb68318c372d8248ccd3bcb49d37db02eff42743bb721345c
5
5
  SHA512:
6
- metadata.gz: cb4c663aa47979a8199ecd58acd61676f266dd6cb03beed0158a6bc5a9060c8f5af19ce08821533627c9bce2ae6409a0be23ce820a0d11c2c242195b531d59c8
7
- data.tar.gz: d75f1bfe1f0f045868fedc9782fabb57825d3815e85572bc0be24c3f62eab5d2db868710a73206a138b8f334477792fdd2cbc92ad74646bd8d0c205e71a15fdc
6
+ metadata.gz: 4890734557bcf61f41cc049cccf85faa09e8f9d8f76534efbba9409eb22e46bc6c030bee3c900029361f3418387c0762792120aa96af03061de046b35c979c4e
7
+ data.tar.gz: cb73bb660740be6f0c1efde659db26dbf576cf009f5fbe16f19d5ad10cf763b7e5aa443f1c6dfb5743e02b221c7a48077ddf7ff98797243632208cda4fe39835
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-regulator (0.1.25)
4
+ api-regulator (0.1.26)
5
5
  activemodel (~> 8.0)
6
6
  activesupport (~> 8.0)
7
7
 
@@ -1,6 +1,7 @@
1
1
  module ApiRegulator
2
2
  class Api
3
- attr_reader :controller_class, :controller_path, :controller_name, :action_name, :description, :title, :params, :responses, :versions
3
+ attr_reader :controller_class, :controller_path, :controller_name, :action_name, :description,
4
+ :title, :params, :responses, :versions, :examples
4
5
 
5
6
  def initialize(controller_class, action_name, desc: nil, title: nil, versions: [], &block)
6
7
  @controller_class = controller_class
@@ -56,6 +57,12 @@ module ApiRegulator
56
57
  end
57
58
  end
58
59
 
60
+ def example(name, value, default: false)
61
+ @examples ||= {}
62
+ @examples[name] = { summary: "#{name} Example", value: value }
63
+ @default_example = value if default
64
+ end
65
+
59
66
  def path
60
67
  rails_route.path.spec.to_s
61
68
  .sub("(.:format)", "") # Remove optional format
@@ -75,7 +75,7 @@ module ApiRegulator
75
75
  params = api.params.select(&:body?)
76
76
  return {} if params.empty?
77
77
 
78
- {
78
+ body = {
79
79
  required: true,
80
80
  content: {
81
81
  'application/json' => {
@@ -83,6 +83,9 @@ module ApiRegulator
83
83
  }
84
84
  }
85
85
  }
86
+
87
+ body[:content]['application/json'][:examples] = api.examples unless api.examples.blank?
88
+ body
86
89
  end
87
90
 
88
91
  def expand_nested_params(params)
@@ -137,8 +140,9 @@ module ApiRegulator
137
140
  generate_param_schema(param)
138
141
  .merge({
139
142
  name: param.name,
140
- required: param.path? || param.required? || false
141
- })
143
+ required: param.path? || param.required? || false,
144
+ examples: param.examples.presence
145
+ }).compact
142
146
  end
143
147
  end
144
148
 
@@ -12,6 +12,7 @@ module ApiRegulator
12
12
  @api = options.delete(:api)
13
13
  @allow_arbitrary_keys = options.delete(:allow_arbitrary_keys) || false
14
14
  @versions = Array(options.delete(:versions)).map(&:to_sym)
15
+ @examples = options.delete(:examples) || {}
15
16
 
16
17
  @children = []
17
18
  @options = options
@@ -151,5 +152,17 @@ module ApiRegulator
151
152
  type.to_s.downcase
152
153
  end
153
154
  end
155
+
156
+ def examples
157
+ return nil if @examples.blank?
158
+
159
+ @examples.each_with_object({}) do |(key, value), formatted_examples|
160
+ formatted_key = key.to_s.parameterize.underscore
161
+ formatted_examples[formatted_key] = {
162
+ summary: key.to_s,
163
+ value: value
164
+ }
165
+ end
166
+ end
154
167
  end
155
168
  end
@@ -1,3 +1,3 @@
1
1
  module ApiRegulator
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-regulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Massanek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-07 00:00:00.000000000 Z
11
+ date: 2025-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport