From 9b059d8eaf79dc451958c92cc42a37639f6954b2 Mon Sep 17 00:00:00 2001 From: Nicholas Tsim Date: Wed, 11 Sep 2024 01:58:44 +0100 Subject: [PATCH] EES-5494 Fix examples not rendering for some complex types --- lib/api_reference_helpers.rb | 26 +++++++++++++------------- source/schemas/template.html.md.erb | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/api_reference_helpers.rb b/lib/api_reference_helpers.rb index 6d94faa..f4cd6c8 100644 --- a/lib/api_reference_helpers.rb +++ b/lib/api_reference_helpers.rb @@ -11,7 +11,7 @@ def schema_example(schema_data, references = []) return schema_data.default end - if Utils::is_primitive_schema(schema_data) + if is_primitive_schema(schema_data) return Utils::primitive_schema_example(schema_data) end @@ -139,6 +139,18 @@ def is_required_schema_property?(schema, property) false end + # @param [Openapi3Parser::Node::Schema] schema + # @return [Boolean] + def is_complex_schema(schema) + !!(schema.all_of || schema.any_of || schema.one_of || schema.not) + end + + # @param [Openapi3Parser::Node::Schema] schema + # @return [Boolean] + def is_primitive_schema(schema) + !is_complex_schema(schema) && !schema.type.nil? && schema.type != "object" && schema.type != "array" + end + class Utils # @param [Openapi3Parser::Node::Schema] schema # @return [String, Number, Boolean] @@ -162,17 +174,5 @@ def self.primitive_schema_example(schema) raise "Invalid primitive schema type: #{schema.type}" end end - - # @param [Openapi3Parser::Node::Schema] schema - # @return [Boolean] - def self.is_complex_schema(schema) - !!(schema.all_of || schema.any_of || schema.one_of || schema.not) - end - - # @param [Openapi3Parser::Node::Schema] schema - # @return [Boolean] - def self.is_primitive_schema(schema) - !is_complex_schema(schema) && !schema.type.nil? && schema.type != "object" && schema.type != "array" - end end end diff --git a/source/schemas/template.html.md.erb b/source/schemas/template.html.md.erb index 7480b07..3b05c7d 100644 --- a/source/schemas/template.html.md.erb +++ b/source/schemas/template.html.md.erb @@ -44,7 +44,7 @@ Available options: <% end %> -<% if schema.type == "object" || schema.type == "array" %> +<% unless is_primitive_schema(schema) %> ## Example schema <% schema_json = json_pretty(schema_example(schema)) %>