Skip to content
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
225 changes: 194 additions & 31 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
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