Skip to content

Commit

Permalink
EES-5494 Use default values for examples if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsim committed Sep 10, 2024
1 parent 97b1f2f commit fa4d1d5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/api_reference_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def schema_example(schema_data, references = [])
return schema_data.example
end

if schema_data.default
return schema_data.default
end

if Utils::is_primitive_schema(schema_data)
return Utils::primitive_schema_example(schema_data)
end
Expand Down Expand Up @@ -122,6 +126,14 @@ class Utils
# @param [Openapi3Parser::Node::Schema] schema
# @return [String, Number, Boolean]
def self.primitive_schema_example(schema)
if schema.example
return schema.example
end

if schema.default
return schema.default
end

case schema.type
when "string"
schema.format ? "string(#{schema.format})" : "string"
Expand Down

0 comments on commit fa4d1d5

Please sign in to comment.