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 49 50 51 |
# File 'lib/scorpio/google_api_document.rb', line 31 def to_openapi # openapi does not want an id field on schemas dup_doc = jsi_node_content.reject { |k, _| k == 'id' } if dup_doc['properties'].is_a?(Hash) required_properties = [] dup_doc['properties'].each do |key, value| if value.is_a?(Hash) && value.key?('required') required_properties.push(key) if value['required'] dup_doc = dup_doc.merge({'properties' => value.reject { |vk, _| vk == 'required' }}) end end # 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 |