[WIP] [OpenAPI]: Fix blueprinter registry key normalization#340
[WIP] [OpenAPI]: Fix blueprinter registry key normalization#340Abishekcs wants to merge 3 commits into
Conversation
…ith view options
Before this, the schema registry only used the class name as the key.So if the same blueprint showed up twice with different views (once as a plain resource, once as an association with view: :extended), both wrote to the same spot and one would overwrite the other.
For example:
class ProjectBlueprint < Blueprinter::Base
fields :name
view :normal do
association :users, blueprint: UserBlueprint
end
end
class UserBlueprint < Blueprinter::Base
fields :email
association :projects, blueprint: ProjectBlueprint
view :extended do
association :all_projects, blueprint: ProjectBlueprint, view: :normal
end
end
Parsing UserBlueprint(view: :extended) reaches ProjectBlueprint twice: once via "projects" (default view, no association back to UserBlueprint), and once via "all_projects" (view: :normal, which does associate back to UserBlueprint, closing the circular reference). Previously both writes shared the registry key "ProjectBlueprint", so the placeholder written for the circular view could be overwritten by the unrelated write from the other view.
Now the key includes the view, defaulting to :default when none is given. Also passes the view options down into build_schema and extract_associations, so an association declared with view: :something actually builds and registers against that view instead of always falling back to :default.
|
This PR adds support for associations that explicitly specify a |
|
@rsamoilov should we support explicitly specifying a association :all_projects, blueprint: ProjectBlueprint, view: :normal |
|
In case we decide to support it. Then we have to handle the case where in Example: class ProjectBlueprint < Blueprinter::Base
fields :name
view :normal do
association :users, blueprint: UserBlueprint, view: :extra_information
end
end
class UserBlueprint < Blueprinter::Base
fields :email
view :extended do
association :all_projects, blueprint: ProjectBlueprint, view: :normal
end
view :extra_information do
field :address
end
end |
I'd say yes. |
WIP
What this PR does ?
Fix circular reference handling when blueprints
associationare parsed under different views This PR fixes a bug in how the OpenAPI schema registry handles circular references between Blueprinter classes. Before this, the schema registry only used the class name as the key. So a blueprint referenced under one view could get its registry entry overwritten (or its circular-reference placeholder silently vanished) by a write for the same class under a different view.For example:
Parsing
UserBlueprint(view: :extended)reachesProjectBlueprinttwice: once viaprojects(default view, no association back toUserBlueprint), and once viaall_projects(view: :normal, which does associate back to UserBlueprint, closing the circular reference). Previously both writes shared the registry keyProjectBlueprint, so the placeholder written for the circular view could be overwritten by the unrelated write from the other view.Now the key includes the view, defaulting to
:defaultwhen none is given. So an association declared withview: :somethingactually builds and registers against that view instead of always falling back to:default.