Module: Scorpio::Google::SchemaLike
- Defined in:
- lib/scorpio/google_api_document.rb
Overview
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?
Instance Method Summary collapse
Instance Method Details
#to_openapi ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/scorpio/google_api_document.rb', line 31 def to_openapi dup_doc = JSI::Util.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 |