# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. # typed: true # frozen_string_literal: true require 'faraday' require 'faraday/multipart' require 'sorbet-runtime' module OpenApiSDK extend T::Sig class Schemas extend T::Sig # REST APIs for managing Schema entities sig { params(sdk_config: SDKConfiguration).void } def initialize(sdk_config) @sdk_configuration = sdk_config end sig { params(api_id: ::String, version_id: ::String).returns(::OpenApiSDK::Operations::GetSchemaResponse) } def get_latest(api_id, version_id) # get_latest - Get information about the latest schema. # Returns information about the last uploaded schema for a particular API version. # This won't include the schema itself, that can be retrieved via the downloadSchema operation. request = ::OpenApiSDK::Operations::GetSchemaRequest.new( api_id: api_id, version_id: version_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::GetSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::GetSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Schema) res.schema = out end elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String, request_body: ::OpenApiSDK::Operations::RegisterSchemaRequestBody).returns(::OpenApiSDK::Operations::RegisterSchemaResponse) } def post(api_id, version_id, request_body) # post - Register a schema. # Allows uploading a schema for a particular API version. # This will be used to populate ApiEndpoints and used as a base for any schema generation if present. request = ::OpenApiSDK::Operations::RegisterSchemaRequest.new( api_id: api_id, version_id: version_id, request_body: request_body ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::RegisterSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema', request, @sdk_configuration.globals ) headers = {} req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :multipart) headers['content-type'] = req_content_type raise StandardError, 'request body is required' if data.nil? && form.nil? headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.post(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? if form req.body = Utils.encode_form(form) elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded') req.body = URI.encode_www_form(data) else req.body = data end end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::RegisterSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String).returns(::OpenApiSDK::Operations::DownloadSchemaResponse) } def download(api_id, version_id) # download - Download the latest schema for a particular apiID. request = ::OpenApiSDK::Operations::DownloadSchemaRequest.new( api_id: api_id, version_id: version_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::DownloadSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/download', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json;q=1, application/x-yaml;q=0' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::DownloadSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 res.two_xx_application_json_schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json') res.two_xx_application_x_yaml_schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml') elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String, base_revision_id: ::String, target_revision_id: ::String).returns(::OpenApiSDK::Operations::GetSchemaDiffResponse) } def get_diff(api_id, version_id, base_revision_id, target_revision_id) # get_diff - Get a diff of two schema revisions for an Api. request = ::OpenApiSDK::Operations::GetSchemaDiffRequest.new( api_id: api_id, version_id: version_id, base_revision_id: base_revision_id, target_revision_id: target_revision_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::GetSchemaDiffRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{baseRevisionID}/diff/{targetRevisionID}', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::GetSchemaDiffResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::SchemaDiff) res.schema_diff = out end elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String, revision_id: ::String).returns(::OpenApiSDK::Operations::DeleteSchemaResponse) } def delete(api_id, version_id, revision_id) # delete - Delete a particular schema revision for an Api. request = ::OpenApiSDK::Operations::DeleteSchemaRequest.new( api_id: api_id, version_id: version_id, revision_id: revision_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::DeleteSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.delete(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::DeleteSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String, revision_id: ::String).returns(::OpenApiSDK::Operations::GetSchemaRevisionResponse) } def get_revision(api_id, version_id, revision_id) # get_revision - Get information about a particular schema revision for an Api. # Returns information about the last uploaded schema for a particular schema revision. # This won't include the schema itself, that can be retrieved via the downloadSchema operation. request = ::OpenApiSDK::Operations::GetSchemaRevisionRequest.new( api_id: api_id, version_id: version_id, revision_id: revision_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::GetSchemaRevisionRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::GetSchemaRevisionResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Schema) res.schema = out end elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String, revision_id: ::String).returns(::OpenApiSDK::Operations::DownloadSchemaRevisionResponse) } def download_revision(api_id, version_id, revision_id) # download_revision - Download a particular schema revision for an Api. request = ::OpenApiSDK::Operations::DownloadSchemaRevisionRequest.new( api_id: api_id, version_id: version_id, revision_id: revision_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::DownloadSchemaRevisionRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}/download', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json;q=1, application/x-yaml;q=0' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::DownloadSchemaRevisionResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 res.two_xx_application_json_schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json') res.two_xx_application_x_yaml_schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml') elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end sig { params(api_id: ::String, version_id: ::String).returns(::OpenApiSDK::Operations::GetSchemasResponse) } def get(api_id, version_id) # get - Get information about all schemas associated with a particular apiID. # Returns information the schemas associated with a particular apiID. # This won't include the schemas themselves, they can be retrieved via the downloadSchema operation. request = ::OpenApiSDK::Operations::GetSchemasRequest.new( api_id: api_id, version_id: version_id ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( ::OpenApiSDK::Operations::GetSchemasRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schemas', request, @sdk_configuration.globals ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = @sdk_configuration.user_agent r = @sdk_configuration.client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = ::OpenApiSDK::Operations::GetSchemasResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status >= 200 && r.status < 300 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, T::Array[::OpenApiSDK::Shared::Schema]) res.schemata = out end elsif r.status >= 400 && r.status < 500 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::Error) res.error = out end end res end end end