From da528547d12ad843b1b68baeb256b3b986bb320a Mon Sep 17 00:00:00 2001 From: Taleh Zaliyev Date: Thu, 4 Dec 2025 13:50:51 +0300 Subject: [PATCH] [BAC-640] Move $ref in allOf for Entities when nullable it will help to generate proper schema --- lib/active_model/entity/schemas/json.rb | 2 ++ spec/active_model/entity/schemas/json_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_model/entity/schemas/json.rb b/lib/active_model/entity/schemas/json.rb index c6dc7cf..b4af63e 100644 --- a/lib/active_model/entity/schemas/json.rb +++ b/lib/active_model/entity/schemas/json.rb @@ -72,6 +72,8 @@ def json_schema_attribute_for(type, inline: false) end def make_schema_nullable!(options) + options[:allOf] = ["$ref": options.delete(:$ref)] if options[:$ref].present? + options[:nullable] = true end diff --git a/spec/active_model/entity/schemas/json_spec.rb b/spec/active_model/entity/schemas/json_spec.rb index b037e98..f9a8121 100644 --- a/spec/active_model/entity/schemas/json_spec.rb +++ b/spec/active_model/entity/schemas/json_spec.rb @@ -54,8 +54,8 @@ class Person "fieldString" => { type: :string }, "fieldTime" => { type: :string }, "fieldRole" => { :$ref => "#/components/schemas/SchemasTest.Role" }, - "fieldNullableRole" => { :$ref => "#/components/schemas/SchemasTest.Role", nullable: true }, - "fieldNullableNotRequiredRole" => { :$ref => "#/components/schemas/SchemasTest.Role", nullable: true }, + "fieldNullableRole" => { allOf: [:$ref => "#/components/schemas/SchemasTest.Role"], nullable: true }, + "fieldNullableNotRequiredRole" => { allOf: [:$ref => "#/components/schemas/SchemasTest.Role"], nullable: true }, "fieldRoles" => { items: { :$ref => "#/components/schemas/SchemasTest.Role" }, type: :array }, "fieldIntegers" => { items: { type: :number }, type: :array }, "fieldNullableString" => { type: :string, nullable: true },