Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
467 changes: 412 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions generator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Client {
self.credentials = credentials.into();
}

fn credentials(&self, authentication: crate::auth::AuthenticationConstraint) -> Option<&crate::auth::Credentials> {
fn get_credentials(&self, authentication: crate::auth::AuthenticationConstraint) -> Option<&crate::auth::Credentials> {
match (authentication, self.credentials.as_ref()) {
(crate::auth::AuthenticationConstraint::Unconstrained, creds) => creds,
(crate::auth::AuthenticationConstraint::JWT, creds @ Some(&crate::auth::Credentials::JWT(_))) => creds,
Expand All @@ -162,7 +162,7 @@ impl Client {
) -> ClientResult<(reqwest::Url, Option<String>)> {
let mut parsed_url = uri.parse::<reqwest::Url>()?;

match self.credentials(authentication) {
match self.get_credentials(authentication) {
Some(&crate::auth::Credentials::Client(ref id, ref secret)) => {
parsed_url.query_pairs_mut()
.append_pair("client_id", id)
Expand Down
271 changes: 223 additions & 48 deletions generator/src/main.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions generator/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ pub fn generate_docs_github(
//! use base64::{{Engine, engine::general_purpose::STANDARD}};
//!
//! let app_id_str = env::var("GH_APP_ID").unwrap();
//! let app_id = app_id_str.parse::<u64>().unwrap();
//! let app_id = app_id_str.parse::<i64>().unwrap();
//!
//! let app_installation_id_str = env::var("GH_INSTALLATION_ID").unwrap();
//! let app_installation_id = app_installation_id_str.parse::<u64>().unwrap();
//! let app_installation_id = app_installation_id_str.parse::<i64>().unwrap();
//!
//! let encoded_private_key = env::var("GH_PRIVATE_KEY").unwrap();
//! let private_key = STANDARD.decode(encoded_private_key).unwrap();
Expand Down
16 changes: 13 additions & 3 deletions generator/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashSet};

use anyhow::{bail, Result};
use inflector::cases::snakecase::to_snake_case;
Expand All @@ -21,10 +21,19 @@ pub fn generate_types(ts: &mut TypeSpace, proper_name: &str) -> Result<String> {
a(" use serde::{Serialize, Deserialize};");
a("");

let mut emitted_names: HashSet<String> = HashSet::new();

for te in ts.clone().id_to_entry.values() {
if let Some(sn) = te.name.as_deref() {
let sn = struct_name(sn);

// Warn about duplicate type names, but keep going
if emitted_names.contains(&sn) {
eprintln!("[warn] skipping duplicate type name: {}", sn);
continue;
}
emitted_names.insert(sn.clone());

match &te.details {
TypeDetails::Enum(vals, schema_data) => {
let mut desc = "".to_string();
Expand Down Expand Up @@ -80,7 +89,7 @@ pub fn generate_types(ts: &mut TypeSpace, proper_name: &str) -> Result<String> {
|| sn == "PagesHttpsCertificate"
|| sn == "ErrorDetails"
|| sn == "EnvelopeDefinition"
|| (sn == "Event" && proper_name != "Stripe")
|| (sn == "Event" && proper_name != "Stripe" && proper_name != "GitHub")
|| sn == "User"
|| sn == "Group"
|| sn == "CalendarResource"
Expand All @@ -97,7 +106,6 @@ pub fn generate_types(ts: &mut TypeSpace, proper_name: &str) -> Result<String> {
|| sn == "DescriptionlessJobOptionsDataType"
|| sn == "SubmitJobOptions"
|| sn == "SubmitJobOptionsData"
|| sn == "MinimalRepository"
|| sn == "WorkflowRun"
|| sn == "CheckAnnotation"
{
Expand Down Expand Up @@ -149,6 +157,7 @@ pub fn generate_types(ts: &mut TypeSpace, proper_name: &str) -> Result<String> {
|| prop == "enum"
|| prop == "const"
|| prop == "use"
|| prop == "async"
{
prop = format!("{}_", name);
} else if name == "$ref" {
Expand Down Expand Up @@ -283,6 +292,7 @@ pub fn generate_types(ts: &mut TypeSpace, proper_name: &str) -> Result<String> {
|| prop == "enum"
|| prop == "const"
|| prop == "use"
|| prop == "async"
{
prop = format!("{}_", prop);
}
Expand Down
17 changes: 14 additions & 3 deletions generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ pub enum MediaType {
Json,
/// Return json in preview form
Preview(&'static str),
/// Return json with media parameter
Param(&'static str),
}

impl Default for MediaType {
Expand All @@ -720,7 +722,8 @@ impl std::fmt::Display for MediaType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
MediaType::Json => write!(f, "application/vnd.github.v3+json"),
MediaType::Preview(codename) => write!(f, "application/vnd.github.{}-preview+json", codename)
MediaType::Preview(codename) => write!(f, "application/vnd.github.{}-preview+json", codename),
MediaType::Param(codename) => write!(f, "application/vnd.github.v3.{}+json", codename),
}
}
}
Expand All @@ -735,7 +738,14 @@ impl From<MediaType> for mime::Mime {
.unwrap_or_else(|_| {
panic!("could not parse media type for preview {}", codename)
})
}
},
MediaType::Param(codename) => {
format!("application/vnd.github.v3.{}+json", codename)
.parse()
.unwrap_or_else(|_| {
panic!("could not parse media type for {}", codename)
})
},
}
}
}
Expand All @@ -748,7 +758,8 @@ mod github_tests {
fn test_hyperx_qitem_compat() {
let tests = [
(MediaType::Json, "application/vnd.github.v3+json"),
(MediaType::Preview("test-value"), "application/vnd.github.test-value-preview+json")
(MediaType::Preview("test-value"), "application/vnd.github.test-value-preview+json"),
(MediaType::Param("test-value"), "application/vnd.github.v3.test-value-preview+json"),
];

for (media_type, header) in tests {
Expand Down
2 changes: 1 addition & 1 deletion github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async-recursion = "^1.0"
chrono = { version = "0.4.38", default-features = false, features = ["alloc", "serde"] }
dirs = { version = "^3.0.2", optional = true }
http = "1"
jsonwebtoken = "9"
jsonwebtoken = { version = "10", features = ["rust_crypto"] }
log = { version = "^0.4", features = ["serde"] }
mime = "0.3"
openssl = { version = "0.10", default-features = false, optional = true }
Expand Down
6 changes: 3 additions & 3 deletions github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GitHub's v3 REST API.

| name | url |
|----|----|
| Support | <https://support.github.com/contact?tags=rest-api> |
| Support | <https://support.github.com/contact?tags=dotcom-rest-api> |

### License

Expand Down Expand Up @@ -121,10 +121,10 @@ use octorust::http_cache::FileBasedCache;
use base64::{Engine, engine::general_purpose::STANDARD};

let app_id_str = env::var("GH_APP_ID").unwrap();
let app_id = app_id_str.parse::<u64>().unwrap();
let app_id = app_id_str.parse::<i64>().unwrap();

let app_installation_id_str = env::var("GH_INSTALLATION_ID").unwrap();
let app_installation_id = app_installation_id_str.parse::<u64>().unwrap();
let app_installation_id = app_installation_id_str.parse::<i64>().unwrap();

let encoded_private_key = env::var("GH_PRIVATE_KEY").unwrap();
let private_key = STANDARD.decode(encoded_private_key).unwrap();
Expand Down
Loading