Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jsi_schema_module' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Jul 2, 2020
2 parents bff68b9 + 95f1ab7 commit 93957b6
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 148 deletions.
25 changes: 16 additions & 9 deletions lib/scorpio/google_api_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ module Google
discovery_rest_description = JSI::MetaschemaNode.new(discovery_rest_description_doc, metaschema_root_ptr: JSI::JSON::Pointer['schemas']['JsonSchema'], root_schema_ptr: JSI::JSON::Pointer['schemas']['RestDescription'])

# naming these is not strictly necessary, but is nice to have.
DirectoryList = JSI.class_for_schema(discovery_rest_description['schemas']['DirectoryList'])
JsonSchema = JSI.class_for_schema(discovery_rest_description['schemas']['JsonSchema'])
RestDescription = JSI.class_for_schema(discovery_rest_description['schemas']['RestDescription'])
RestMethod = JSI.class_for_schema(discovery_rest_description['schemas']['RestMethod'])
RestResource = JSI.class_for_schema(discovery_rest_description['schemas']['RestResource'])
RestMethodRequest = JSI.class_for_schema(discovery_rest_description['schemas']['RestMethod']['properties']['request'])
RestMethodResponse = JSI.class_for_schema(discovery_rest_description['schemas']['RestMethod']['properties']['response'])
DirectoryList = discovery_rest_description.schemas['DirectoryList'].jsi_schema_module
JsonSchema = discovery_rest_description.schemas['JsonSchema'].jsi_schema_module
RestDescription = discovery_rest_description.schemas['RestDescription'].jsi_schema_module
RestMethod = discovery_rest_description.schemas['RestMethod'].jsi_schema_module
RestResource = discovery_rest_description.schemas['RestResource'].jsi_schema_module

module RestDescription
Resources = properties['resources']
end

module RestMethod
Request = properties['request']
Response = properties['response']
end

# 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?
module SchemaLike
Expand All @@ -33,9 +40,9 @@ def to_openapi
dup_doc
end
end
[JsonSchema, RestMethodRequest, RestMethodResponse].each { |klass| klass.send(:include, SchemaLike) }
[JsonSchema, RestMethod::Request, RestMethod::Response].each { |m| m.send(:include, SchemaLike) }

class RestDescription
module RestDescription
def to_openapi_document(options = {})
Scorpio::OpenAPI::Document.from_instance(to_openapi_hash(options))
end
Expand Down
Loading

0 comments on commit 93957b6

Please sign in to comment.