Skip to content

Commit

Permalink
Include nullability in OpenAPI metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
xeger committed Jan 25, 2022
1 parent f57362f commit 54ceae9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/praxis/docs/open_api/schema_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(info:)
if info.is_a?(Attributor::Attribute)
@type = info.type
@enum = info.options[:values]
@nullable = info.options[:null]
else
@type = info
end
Expand Down Expand Up @@ -43,7 +44,9 @@ 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
Expand All @@ -54,6 +57,7 @@ def dump_schema(shallow: false, allow_ref: false)
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

Expand Down

0 comments on commit 54ceae9

Please sign in to comment.