module Scorpio::Google::SchemaLike
google does a weird thing where it defines a schema with a $ref property where a json-schema is to be used in the document (method request and response fields), instead of just setting the schema to be the json-schema schema. we'll share a module across those schema classes that really represent schemas. is this confusingly meta enough?
Public Instance Methods
to_openapi()
click to toggle source
# File lib/scorpio/google_api_document.rb, line 24 def to_openapi dup_doc = JSI::Typelike.as_json(self) # openapi does not want an id field on schemas dup_doc.delete('id') if dup_doc['properties'].is_a?(Hash) required_properties = dup_doc['properties'].select do |key, value| value.is_a?(Hash) ? value.delete('required') : nil end.keys # put required before properties unless required_properties.empty? dup_doc = dup_doc.map do |k, v| base = k == 'properties' ? {'required' => required_properties } : {} base.merge({k => v}) end.inject({}, &:update) end end dup_doc end