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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scorpio/google_api_document.rb', line 20 def to_openapi dup_doc = ::JSON.parse(::JSON.generate(instance.content)) # 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 |