Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jsi' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Jan 18, 2021
2 parents c6ff1d8 + dcb6425 commit 5a7158e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ gem 'byebug'
gem 'coveralls_reborn', '~> 0.11'
gem 'wwtd'
gem 'ur', github: 'notEthan/ur', ref: 'fa495042596eb9cec4ff361bfb764f516174558a'
gem 'jsi', github: 'notEthan/jsi', ref: '52ba91dae4a4b5f93ef7e53af4a200bbb7a6e2ff'
gem 'jsi', github: 'notEthan/jsi', ref: '9b4bd0f15f2fe8c2135ffa78a9e1af316300da3b'
11 changes: 10 additions & 1 deletion lib/scorpio/google_api_document.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
module Scorpio
module Google
discovery_rest_description_doc = ::JSON.parse(Scorpio.root.join('documents/www.googleapis.com/discovery/v1/apis/discovery/v1/rest').read)
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'])
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'],
metaschema_instance_modules: Set[
JSI::Schema,
JSI::Schema::Application::InplaceApplication,
JSI::Schema::Application::ChildApplication,
],
)

# naming these is not strictly necessary, but is nice to have.
DirectoryList = discovery_rest_description.schemas['DirectoryList'].jsi_schema_module
Expand Down
36 changes: 25 additions & 11 deletions lib/scorpio/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ class SemanticError < Error
autoload :OperationsScope, 'scorpio/openapi/operations_scope'

module V3
openapi_schema = JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))
openapi_document_schema = JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))

Document = openapi_schema.jsi_schema_module
# the schema represented by Scorpio::OpenAPI::V3::Schema will describe schemas itself, so we set it
# include on its schema module the jsi_schema_instance_modules that implement schema functionality.
openapi_v3_schema_instance_modules = Set[
JSI::Schema,
JSI::Schema::Application::InplaceApplication,
JSI::Schema::Application::ChildApplication,
]
openapi_document_schema.definitions['Schema'].jsi_schema_instance_modules = openapi_v3_schema_instance_modules
openapi_document_schema.definitions['SchemaReference'].jsi_schema_instance_modules = openapi_v3_schema_instance_modules

Document = openapi_document_schema.jsi_schema_module

# naming these is not strictly necessary, but is nice to have.
# generated: `puts JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))['definitions'].select { |k,v| ['object', nil].include?(v['type']) }.keys.map { |k| "#{k[0].upcase}#{k[1..-1]} = Document.definitions['#{k}']" }`
Expand Down Expand Up @@ -86,15 +96,21 @@ module V3
Callback = Document.definitions['Callback']
Encoding = Document.definitions['Encoding']

# the schema of Scorpio::OpenAPI::V3::Schema describes a schema itself, so we extend it
# with the module indicating that.
Schema.schema.extend(JSI::Schema::DescribesSchema)
SchemaReference.schema.extend(JSI::Schema::DescribesSchema)
raise(Bug) unless Schema < JSI::Schema
raise(Bug) unless SchemaReference < JSI::Schema
end
module V2
openapi_schema = JSI::Schema.new(::JSON.parse(Scorpio.root.join('documents/swagger.io/v2/schema.json').read))
openapi_document_schema = JSI::Schema.new(::JSON.parse(Scorpio.root.join('documents/swagger.io/v2/schema.json').read))

# the schema represented by Scorpio::OpenAPI::V2::Schema will describe schemas itself, so we set it to
# include on its schema module the jsi_schema_instance_modules that implement schema functionality.
openapi_document_schema.definitions['schema'].jsi_schema_instance_modules = Set[
JSI::Schema,
JSI::Schema::Application::InplaceApplication,
JSI::Schema::Application::ChildApplication,
]

Document = openapi_schema.jsi_schema_module
Document = openapi_document_schema.jsi_schema_module

# naming these is not strictly necessary, but is nice to have.
# generated: `puts JSI::Schema.new(::JSON.parse(Scorpio.root.join('documents/swagger.io/v2/schema.json').read))['definitions'].select { |k,v| ['object', nil].include?(v['type']) }.keys.map { |k| "#{k[0].upcase}#{k[1..-1]} = Document.definitions['#{k}']" }`
Expand Down Expand Up @@ -153,9 +169,7 @@ module V2
Enum = Document.definitions['enum']
JsonReference = Document.definitions['jsonReference']

# the schema of Scorpio::OpenAPI::V2::Schema describes a schema itself, so we extend it
# with the module indicating that.
Schema.schema.extend(JSI::Schema::DescribesSchema)
raise(Bug) unless Schema < JSI::Schema
end

begin
Expand Down

0 comments on commit 5a7158e

Please sign in to comment.