Skip to content

Commit

Permalink
0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Oct 9, 2024
1 parent c513ad7 commit 59a8eef
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# SOFTWARE.
[package]
name = "fakehub"
version = "0.0.0"
version = "0.0.9"
edition = "2021"
license = "MIT"
description = """
Expand All @@ -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.9", 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 }
Expand Down
15 changes: 15 additions & 0 deletions github-mirror/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "github-mirror"
version = "0.0.9"
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"] }
51 changes: 51 additions & 0 deletions github-mirror/src/apis/configuration.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
pub client: reqwest::Client,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
pub api_key: Option<ApiKey>,
}

pub type BasicAuth = (String, Option<String>);

#[derive(Debug, Clone)]
pub struct ApiKey {
pub prefix: Option<String>,
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,
}
}
}
53 changes: 53 additions & 0 deletions github-mirror/src/apis/meta_api.rs
Original file line number Diff line number Diff line change
@@ -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<models::MetaRoot200Response, Error<MetaSlashRootError>> {
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<MetaSlashRootError> = 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))
}
}

95 changes: 95 additions & 0 deletions github-mirror/src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use std::error;
use std::fmt;

#[derive(Debug, Clone)]
pub struct ResponseContent<T> {
pub status: reqwest::StatusCode,
pub content: String,
pub entity: Option<T>,
}

#[derive(Debug)]
pub enum Error<T> {
Reqwest(reqwest::Error),
Serde(serde_json::Error),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
}

impl <T> fmt::Display for Error<T> {
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 <T: fmt::Debug> error::Error for Error<T> {
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 <T> From<reqwest::Error> for Error<T> {
fn from(e: reqwest::Error) -> Self {
Error::Reqwest(e)
}
}

impl <T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}

impl <T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}

pub fn urlencode<T: AsRef<str>>(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;
11 changes: 11 additions & 0 deletions github-mirror/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
123 changes: 123 additions & 0 deletions github-mirror/src/models/meta_root_200_response.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
#[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<String>,
#[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,
}
}
}

2 changes: 2 additions & 0 deletions github-mirror/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod meta_root_200_response;
pub use self::meta_root_200_response::MetaRoot200Response;
4 changes: 2 additions & 2 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# SOFTWARE.
[package]
name = "fakehub-server"
version = "0.0.0"
version = "0.0.9"
edition = "2021"
license = "MIT"
description = """
Expand All @@ -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.9" }
anyhow = "1.0.86"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
Expand Down

0 comments on commit 59a8eef

Please sign in to comment.