[OpenAPI]: Add support for blueprinter root key#343
Conversation
…ations Add support for the `root:` option in Blueprinter parser, wrapping the schema under a named key when specified (e.g. `@response UserBlueprint(root: :user)`).
…Symbol keys in generated schema
b5e1f27 to
a8f4eda
Compare
|
PR is ready for review! |
| end | ||
| end | ||
|
|
||
| describe "collection" do |
There was a problem hiding this comment.
I can see parsing fails with collections and string-based root keys, e.g. Array<UserBlueprint(root: 'user')> and Array<UserBlueprint(root: "user")>.
| RUBY | ||
| end | ||
|
|
||
| it "wraps the array items schema under the specified root key" do |
There was a problem hiding this comment.
The wording seems correct, but your test looks different. The test expects a structure like [{ root_key: { ... } }], but the correct structure seems to be { root_key: [{ ... }] }.
There was a problem hiding this comment.
I thought the root key gets wrapped in array too. Didn't check the actual blueprinter output for collection, should had done that earlier😐
…t: key wrapping - Add single and double quote support to `__try_parse_collection` regex so string values (e.g. `root: 'users'`) parse correctly in collection annotations. - Symbolize view name before reflections lookup so `view: 'normal'` and`view: :normal` both resolve correctly. - Fix root: key wrapping to apply after is_collection, so the root key wraps the full array schema rather than individual items.
| @parsing_stack.add(klass.name) | ||
|
|
||
| view_name = serializer_options&.key?(:view) ? serializer_options[:view] : :default | ||
| view_name = serializer_options&.key?(:view) ? serializer_options[:view].to_sym : :default |
There was a problem hiding this comment.
Convert to Symbol to_sym as reflection api errors out with string.
| result = { "type" => "array", "items" => result } if is_collection | ||
| result | ||
|
|
||
| if serializer_options&.key?(:root) |
There was a problem hiding this comment.
the root key now wraps the fully-resolved schema (including the array wrapper if it's a collection), rather than wrapping just the inner properties before the array wrapper is applied.
| # @private | ||
| def self.__try_parse_collection(str) | ||
| if str =~ /^Array<([\w\s:\(\),]+)>$/ || str =~ /^\[([\w\s:\(\),]+)\]$/ | ||
| if str =~ /^Array<([\w\s:\(\),'\"]+)>$/ || str =~ /^\[([\w\s:\(\),'\"]+)\]$/ |
There was a problem hiding this comment.
It was due to this String "" or '' was failing as it didn't support it.
|
@rsamoilov I have made the required changes. And also added some new test cases to test different combination of |

What this PR does?
Add Support for
root keyExample
Screnshot