diff --git a/cli/Cargo.toml b/cli/Cargo.toml index bddf98e8..5952067a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -21,7 +21,7 @@ # SOFTWARE. [package] name = "fakehub" -version = "0.0.0" +version = "0.0.10" edition = "2021" license = "MIT" description = """ @@ -39,7 +39,7 @@ workspace = true assert_cmd = "2.0.14" [dependencies] -fakehub-server = { path = "../server", version = "0.0.0" } +fakehub-server = { path = "../server", version = "0.0.10", features = ["mirror_release"] } anyhow = "1.0.86" clap = { version = "4.5.7", optional = true, features = ["derive", "string"] } clap_complete = { version = "4.5.1", optional = true } diff --git a/github-mirror/Cargo.toml b/github-mirror/Cargo.toml new file mode 100644 index 00000000..3bb52227 --- /dev/null +++ b/github-mirror/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "github-mirror" +version = "0.0.10" +authors = ["OpenAPI Generator team and contributors"] +description = "GitHub's v3 REST API." +license = "MIT" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +uuid = { version = "^1.8", features = ["serde", "v4"] } +reqwest = { version = "^0.12", features = ["json", "multipart"] } diff --git a/github-mirror/src/apis/configuration.rs b/github-mirror/src/apis/configuration.rs new file mode 100644 index 00000000..3b8bd2e4 --- /dev/null +++ b/github-mirror/src/apis/configuration.rs @@ -0,0 +1,51 @@ +/* + * GitHub v3 REST API + * + * GitHub's v3 REST API. + * + * The version of the OpenAPI document: 1.1.4 + * + * Generated by: https://openapi-generator.tech + */ + + + +#[derive(Debug, Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, +} + +pub type BasicAuth = (String, Option); + +#[derive(Debug, Clone)] +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "https://api.github.com".to_owned(), + user_agent: Some("OpenAPI-Generator/1.1.4/rust".to_owned()), + client: reqwest::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/github-mirror/src/apis/meta_api.rs b/github-mirror/src/apis/meta_api.rs new file mode 100644 index 00000000..54dbee23 --- /dev/null +++ b/github-mirror/src/apis/meta_api.rs @@ -0,0 +1,53 @@ +/* + * GitHub v3 REST API + * + * GitHub's v3 REST API. + * + * The version of the OpenAPI document: 1.1.4 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; +use serde::{Deserialize, Serialize}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration}; + + +/// struct for typed errors of method [`meta_slash_root`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum MetaSlashRootError { + UnknownValue(serde_json::Value), +} + + +/// Get Hypermedia links to resources accessible in GitHub's REST API +pub async fn meta_slash_root(configuration: &configuration::Configuration, ) -> Result> { + let local_var_configuration = configuration; + + let local_var_client = &local_var_configuration.client; + + let local_var_uri_str = format!("{}/", local_var_configuration.base_path); + let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + + if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { + local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + } + + let local_var_req = local_var_req_builder.build()?; + let local_var_resp = local_var_client.execute(local_var_req).await?; + + let local_var_status = local_var_resp.status(); + let local_var_content = local_var_resp.text().await?; + + if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + serde_json::from_str(&local_var_content).map_err(Error::from) + } else { + let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + Err(Error::ResponseError(local_var_error)) + } +} + diff --git a/github-mirror/src/apis/mod.rs b/github-mirror/src/apis/mod.rs new file mode 100644 index 00000000..36995d74 --- /dev/null +++ b/github-mirror/src/apis/mod.rs @@ -0,0 +1,95 @@ +use std::error; +use std::fmt; + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + }) + } +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +pub mod meta_api; + +pub mod configuration; diff --git a/github-mirror/src/lib.rs b/github-mirror/src/lib.rs new file mode 100644 index 00000000..e1520628 --- /dev/null +++ b/github-mirror/src/lib.rs @@ -0,0 +1,11 @@ +#![allow(unused_imports)] +#![allow(clippy::too_many_arguments)] + +extern crate serde_repr; +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; + +pub mod apis; +pub mod models; diff --git a/github-mirror/src/models/meta_root_200_response.rs b/github-mirror/src/models/meta_root_200_response.rs new file mode 100644 index 00000000..8c340455 --- /dev/null +++ b/github-mirror/src/models/meta_root_200_response.rs @@ -0,0 +1,123 @@ +/* + * GitHub v3 REST API + * + * GitHub's v3 REST API. + * + * The version of the OpenAPI document: 1.1.4 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct MetaRoot200Response { + #[serde(rename = "current_user_url")] + pub current_user_url: String, + #[serde(rename = "current_user_authorizations_html_url")] + pub current_user_authorizations_html_url: String, + #[serde(rename = "authorizations_url")] + pub authorizations_url: String, + #[serde(rename = "code_search_url")] + pub code_search_url: String, + #[serde(rename = "commit_search_url")] + pub commit_search_url: String, + #[serde(rename = "emails_url")] + pub emails_url: String, + #[serde(rename = "emojis_url")] + pub emojis_url: String, + #[serde(rename = "events_url")] + pub events_url: String, + #[serde(rename = "feeds_url")] + pub feeds_url: String, + #[serde(rename = "followers_url")] + pub followers_url: String, + #[serde(rename = "following_url")] + pub following_url: String, + #[serde(rename = "gists_url")] + pub gists_url: String, + #[serde(rename = "hub_url", skip_serializing_if = "Option::is_none")] + pub hub_url: Option, + #[serde(rename = "issue_search_url")] + pub issue_search_url: String, + #[serde(rename = "issues_url")] + pub issues_url: String, + #[serde(rename = "keys_url")] + pub keys_url: String, + #[serde(rename = "label_search_url")] + pub label_search_url: String, + #[serde(rename = "notifications_url")] + pub notifications_url: String, + #[serde(rename = "organization_url")] + pub organization_url: String, + #[serde(rename = "organization_repositories_url")] + pub organization_repositories_url: String, + #[serde(rename = "organization_teams_url")] + pub organization_teams_url: String, + #[serde(rename = "public_gists_url")] + pub public_gists_url: String, + #[serde(rename = "rate_limit_url")] + pub rate_limit_url: String, + #[serde(rename = "repository_url")] + pub repository_url: String, + #[serde(rename = "repository_search_url")] + pub repository_search_url: String, + #[serde(rename = "current_user_repositories_url")] + pub current_user_repositories_url: String, + #[serde(rename = "starred_url")] + pub starred_url: String, + #[serde(rename = "starred_gists_url")] + pub starred_gists_url: String, + #[serde(rename = "topic_search_url", skip_serializing_if = "Option::is_none")] + pub topic_search_url: Option, + #[serde(rename = "user_url")] + pub user_url: String, + #[serde(rename = "user_organizations_url")] + pub user_organizations_url: String, + #[serde(rename = "user_repositories_url")] + pub user_repositories_url: String, + #[serde(rename = "user_search_url")] + pub user_search_url: String, +} + +impl MetaRoot200Response { + pub fn new(current_user_url: String, current_user_authorizations_html_url: String, authorizations_url: String, code_search_url: String, commit_search_url: String, emails_url: String, emojis_url: String, events_url: String, feeds_url: String, followers_url: String, following_url: String, gists_url: String, issue_search_url: String, issues_url: String, keys_url: String, label_search_url: String, notifications_url: String, organization_url: String, organization_repositories_url: String, organization_teams_url: String, public_gists_url: String, rate_limit_url: String, repository_url: String, repository_search_url: String, current_user_repositories_url: String, starred_url: String, starred_gists_url: String, user_url: String, user_organizations_url: String, user_repositories_url: String, user_search_url: String) -> MetaRoot200Response { + MetaRoot200Response { + current_user_url, + current_user_authorizations_html_url, + authorizations_url, + code_search_url, + commit_search_url, + emails_url, + emojis_url, + events_url, + feeds_url, + followers_url, + following_url, + gists_url, + hub_url: None, + issue_search_url, + issues_url, + keys_url, + label_search_url, + notifications_url, + organization_url, + organization_repositories_url, + organization_teams_url, + public_gists_url, + rate_limit_url, + repository_url, + repository_search_url, + current_user_repositories_url, + starred_url, + starred_gists_url, + topic_search_url: None, + user_url, + user_organizations_url, + user_repositories_url, + user_search_url, + } + } +} + diff --git a/github-mirror/src/models/mod.rs b/github-mirror/src/models/mod.rs new file mode 100644 index 00000000..117036b4 --- /dev/null +++ b/github-mirror/src/models/mod.rs @@ -0,0 +1,2 @@ +pub mod meta_root_200_response; +pub use self::meta_root_200_response::MetaRoot200Response; diff --git a/server/Cargo.toml b/server/Cargo.toml index 0e860488..81440afe 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -21,7 +21,7 @@ # SOFTWARE. [package] name = "fakehub-server" -version = "0.0.0" +version = "0.0.10" edition = "2021" license = "MIT" description = """ @@ -38,7 +38,7 @@ path = "src/lib.rs" workspace = true [dependencies] -openapi = { path = "../github-mirror", version = "1.1.4" } +github-mirror = { path = "../github-mirror", version = "0.0.10" } anyhow = "1.0.86" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117"