From 368e5d3ebfa0fd22b45688f4f8539dbb88015c30 Mon Sep 17 00:00:00 2001 From: Nicholas Tsim Date: Sat, 7 Sep 2024 13:11:35 +0100 Subject: [PATCH] EES-5494 Fix schema type not considering `allOf` during fallback --- lib/api_reference_helpers.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/api_reference_helpers.rb b/lib/api_reference_helpers.rb index 478f091..34a6022 100644 --- a/lib/api_reference_helpers.rb +++ b/lib/api_reference_helpers.rb @@ -16,7 +16,7 @@ def schema_example(schema_data, references = []) return items ? [schema_example(items)] : [] end - if schema_data.one_of + if schema_data.one_of&.any? return schema_example(schema_data.one_of[0]) end @@ -78,7 +78,7 @@ def get_schema_properties(schema) # @param [Openapi3Parser::Node::Schema] schema # @return [String] def render_schema_type(schema) - unless schema.one_of.nil? + if schema.one_of&.any? schemas = schema.one_of.map { |s| "
  • #{render_schema_type(s)}
  • " } .join @@ -116,6 +116,12 @@ def render_schema_type(schema) "array (#{render_schema_type(items)})" end else + # Make assumption that all oneOf items are same type as + # Swashbuckle theoretically shouldn't allow different types. + if schema.all_of&.any? + return render_schema_type(schema.all_of[0]) + end + schema.type || "any" end end