Skip to content

Commit

Permalink
EES-5494 Fix examples not rendering for some complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsim committed Sep 11, 2024
1 parent dd656e5 commit 9b059d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/api_reference_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion source/schemas/template.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Available options:
</table>
<% end %>

<% if schema.type == "object" || schema.type == "array" %>
<% unless is_primitive_schema(schema) %>
## Example schema

<% schema_json = json_pretty(schema_example(schema)) %>
Expand Down

0 comments on commit 9b059d8

Please sign in to comment.