# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. # typed: true # frozen_string_literal: true require 'faraday' require 'faraday/multipart' require 'sorbet-runtime' module SpeakeasyClientSDK extend T::Sig class Schemas # REST APIs for managing Schema entities extend T::Sig sig { params(sdk_config: SDKConfiguration).void } def initialize(sdk_config) @sdk_configuration = sdk_config end sig { params(request: Operations::DeleteSchemaRequest).returns(Utils::FieldAugmented) } def delete_schema(request) # delete_schema - Delete a particular schema revision for an Api. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::DeleteSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}', request ) headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::DeleteSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::DownloadSchemaRequest).returns(Utils::FieldAugmented) } def download_schema(request) # download_schema - Download the latest schema for a particular apiID. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::DownloadSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/download', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0.7, application/x-yaml;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::DownloadSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json') res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml') else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::DownloadSchemaRevisionRequest).returns(Utils::FieldAugmented) } def download_schema_revision(request) # download_schema_revision - Download a particular schema revision for an Api. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::DownloadSchemaRevisionRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}/download', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0.7, application/x-yaml;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::DownloadSchemaRevisionResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/json') res.schema = r.env.response_body if Utils.match_content_type(content_type, 'application/x-yaml') else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::GetSchemaRequest).returns(Utils::FieldAugmented) } def get_schema(request) # get_schema - 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. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::GetSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::GetSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Schema) res.schema = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::GetSchemaDiffRequest).returns(Utils::FieldAugmented) } def get_schema_diff(request) # get_schema_diff - Get a diff of two schema revisions for an Api. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::GetSchemaDiffRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{baseRevisionID}/diff/{targetRevisionID}', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::GetSchemaDiffResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::SchemaDiff) res.schema_diff = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::GetSchemaRevisionRequest).returns(Utils::FieldAugmented) } def get_schema_revision(request) # get_schema_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. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::GetSchemaRevisionRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema/{revisionID}', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::GetSchemaRevisionResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Schema) res.schema = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::GetSchemasRequest).returns(Utils::FieldAugmented) } def get_schemas(request) # get_schemas - 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. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::GetSchemasRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schemas', request ) headers = {} headers['Accept'] = 'application/json;q=1, application/json;q=0' headers['user-agent'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::GetSchemasResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, T::Array[Shared::Schema]) res.schemata = out end else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end sig { params(request: Operations::RegisterSchemaRequest).returns(Utils::FieldAugmented) } def register_schema(request) # register_schema - 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. url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Operations::RegisterSchemaRequest, base_url, '/v1/apis/{apiID}/version/{versionID}/schema', request ) 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'] = "speakeasy-sdk/#{@sdk_configuration.language} #{@sdk_configuration.sdk_version} #{@sdk_configuration.gen_version} #{@sdk_configuration.openapi_doc_version}" 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 = Operations::RegisterSchemaResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end end end