Skip to content

Commit

Permalink
Merge 54ceae9 into c7c5663
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Spataro committed Jan 25, 2022
2 parents c7c5663 + 54ceae9 commit ede8ca3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/praxis/docs/open_api/schema_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class SchemaObject

def initialize(info:)
# info could be an attribute ... or a type?
@type = info.is_a?(Attributor::Attribute) ? info.type : info
if info.is_a?(Attributor::Attribute)
@type = info.type
@enum = info.options[:values]
@nullable = info.options[:null]
else
@type = info
end

# Mediatypes have the description method, lower types don't
@description = @type.description if @type.respond_to?(:description)
Expand Down Expand Up @@ -38,15 +44,21 @@ def dump_schema(shallow: false, allow_ref: false)
else
# Object
props = type.attributes.each_with_object({}) do |(name, definition), hash|
hash[name] = OpenApi::SchemaObject.new(info: definition).dump_schema(allow_ref: true, shallow: shallow)
schema = OpenApi::SchemaObject.new(info: definition).dump_schema(allow_ref: true, shallow: shallow)
schema[:nullable] = true if definition.options[:null]
hash[name] = schema
end
{ type: :object, properties: props } # TODO: Example?
end
else
# OpenApi::SchemaObject.new(info:target).dump_schema(allow_ref: allow_ref, shallow: shallow)
# TODO...we need to make sure we can use refs in the underlying components after the first level...
# ... maybe we need to loop over the attributes if it's an object/struct?...
type.as_json_schema(shallow: shallow, example: nil)
schema = type.as_json_schema(shallow: shallow, example: nil)
# TODO: should this sort of logic be moved into as_json_schema?
schema.merge!(enum: @enum) if @enum
schema.merge!(nullable: true) if @nullable
schema
end

# # TODO: FIXME: return a generic object type if the passed info was weird.
Expand Down

0 comments on commit ede8ca3

Please sign in to comment.