chore: updated schemas
This commit is contained in:
parent
b4ce0c764e
commit
73358b70cc
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -2271,7 +2271,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "torn-api"
|
||||
version = "1.1.2"
|
||||
version = "1.2.0"
|
||||
dependencies = [
|
||||
"bon",
|
||||
"bytes",
|
||||
|
@ -2291,7 +2291,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "torn-api-codegen"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"indexmap",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "torn-api-codegen"
|
||||
authors = ["Pyrit [2111649]"]
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
description = "Contains the v2 torn API model descriptions and codegen for the bindings"
|
||||
license-file = { workspace = true }
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
use heck::{ToSnakeCase, ToUpperCamelCase};
|
||||
use indexmap::IndexMap;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{ToTokens, format_ident, quote};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::Ident;
|
||||
|
||||
use crate::openapi::r#type::OpenApiType;
|
||||
|
@ -82,6 +82,7 @@ pub struct Property {
|
|||
pub required: bool,
|
||||
pub nullable: bool,
|
||||
pub r#type: PropertyType,
|
||||
pub deprecated: bool,
|
||||
}
|
||||
|
||||
impl Property {
|
||||
|
@ -105,30 +106,25 @@ impl Property {
|
|||
name,
|
||||
description,
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
one_of: Some(types),
|
||||
..
|
||||
} => match types.as_slice() {
|
||||
[
|
||||
left,
|
||||
OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
},
|
||||
] => {
|
||||
[left, OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
}] => {
|
||||
let mut inner = Self::from_schema(&name, required, left, schemas)?;
|
||||
inner.nullable = true;
|
||||
Some(inner)
|
||||
}
|
||||
[
|
||||
left @ ..,
|
||||
OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
},
|
||||
] => {
|
||||
[left @ .., OpenApiType {
|
||||
r#type: Some("null"),
|
||||
..
|
||||
}] => {
|
||||
let rest = OpenApiType {
|
||||
one_of: Some(left.to_owned()),
|
||||
..schema.clone()
|
||||
|
@ -141,9 +137,10 @@ impl Property {
|
|||
let r#enum = Enum::from_one_of(&name.to_upper_camel_case(), cases)?;
|
||||
Some(Self {
|
||||
name,
|
||||
description: None,
|
||||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Enum(r#enum),
|
||||
})
|
||||
}
|
||||
|
@ -155,9 +152,10 @@ impl Property {
|
|||
let composite = Object::from_all_of(&name.to_upper_camel_case(), types, schemas)?;
|
||||
Some(Self {
|
||||
name,
|
||||
description: None,
|
||||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Nested(Box::new(composite)),
|
||||
})
|
||||
}
|
||||
|
@ -173,6 +171,7 @@ impl Property {
|
|||
name,
|
||||
description,
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
|
@ -183,6 +182,7 @@ impl Property {
|
|||
description,
|
||||
r#type: PropertyType::Ref((*path).to_owned()),
|
||||
required,
|
||||
deprecated: schema.deprecated,
|
||||
nullable: false,
|
||||
}),
|
||||
OpenApiType {
|
||||
|
@ -197,6 +197,7 @@ impl Property {
|
|||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Array(Box::new(inner.r#type)),
|
||||
})
|
||||
}
|
||||
|
@ -217,6 +218,7 @@ impl Property {
|
|||
description,
|
||||
required,
|
||||
nullable: false,
|
||||
deprecated: schema.deprecated,
|
||||
r#type: PropertyType::Primitive(prim),
|
||||
})
|
||||
}
|
||||
|
@ -245,8 +247,17 @@ impl Property {
|
|||
ty_inner
|
||||
};
|
||||
|
||||
let deprecated = self.deprecated.then(|| {
|
||||
let note = self.description.as_ref().map(|d| quote! { note = #d });
|
||||
|
||||
quote! {
|
||||
#[deprecated(#note)]
|
||||
}
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
#desc
|
||||
#deprecated
|
||||
#serde_attr
|
||||
pub #name: #ty
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt::Write, ops::Deref};
|
||||
use std::fmt::Write;
|
||||
|
||||
use heck::{ToSnakeCase, ToUpperCamelCase};
|
||||
use indexmap::IndexMap;
|
||||
|
@ -40,7 +40,7 @@ pub struct Path {
|
|||
pub segments: Vec<PathSegment>,
|
||||
pub name: String,
|
||||
pub summary: Option<String>,
|
||||
pub description: String,
|
||||
pub description: Option<String>,
|
||||
pub parameters: Vec<PathParameter>,
|
||||
pub response: PathResponse,
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ impl Path {
|
|||
}
|
||||
|
||||
let summary = schema.get.summary.as_deref().map(ToOwned::to_owned);
|
||||
let description = schema.get.description.deref().to_owned();
|
||||
let description = schema.get.description.as_deref().map(ToOwned::to_owned);
|
||||
|
||||
let mut params = Vec::with_capacity(schema.get.parameters.len());
|
||||
for parameter in &schema.get.parameters {
|
||||
|
@ -377,7 +377,23 @@ impl Path {
|
|||
}
|
||||
};
|
||||
|
||||
let doc = match (&self.summary, &self.description) {
|
||||
(Some(summary), Some(description)) => {
|
||||
Some(format!("{summary}\n\n# Description\n{description}"))
|
||||
}
|
||||
(Some(summary), None) => Some(summary.clone()),
|
||||
(None, Some(description)) => Some(format!("# Description\n{description}")),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
let doc = doc.map(|d| {
|
||||
quote! {
|
||||
#[doc = #d]
|
||||
}
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
#doc
|
||||
pub async fn #fn_name<S>(
|
||||
self,
|
||||
#(#extra_args)*
|
||||
|
@ -487,7 +503,23 @@ impl Path {
|
|||
quote! { #(#disc_ty),* }
|
||||
};
|
||||
|
||||
let doc = match (&self.summary, &self.description) {
|
||||
(Some(summary), Some(description)) => {
|
||||
Some(format!("{summary}\n\n# Description\n{description}"))
|
||||
}
|
||||
(Some(summary), None) => Some(summary.clone()),
|
||||
(None, Some(description)) => Some(format!("# Description\n{description}")),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
let doc = doc.map(|d| {
|
||||
quote! {
|
||||
#[doc = #d]
|
||||
}
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
#doc
|
||||
pub fn #fn_name<S, I, B>(
|
||||
self,
|
||||
ids: I,
|
||||
|
|
|
@ -50,6 +50,7 @@ impl Scope {
|
|||
}
|
||||
|
||||
Some(quote! {
|
||||
#[allow(dead_code)]
|
||||
pub struct #name<E>(E)
|
||||
where
|
||||
E: crate::executor::Executor;
|
||||
|
@ -65,6 +66,7 @@ impl Scope {
|
|||
#(#functions)*
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct #bulk_name<E> where
|
||||
E: crate::executor::BulkExecutor,
|
||||
{
|
||||
|
|
|
@ -63,7 +63,7 @@ where
|
|||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct OpenApiPathBody<'a> {
|
||||
pub summary: Option<Cow<'a, str>>,
|
||||
pub description: Cow<'a, str>,
|
||||
pub description: Option<Cow<'a, str>>,
|
||||
#[serde(borrow, default)]
|
||||
pub parameters: Vec<OpenApiPathParameter<'a>>,
|
||||
#[serde(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "torn-api"
|
||||
version = "1.1.2"
|
||||
version = "1.2.0"
|
||||
edition = "2021"
|
||||
description = "Auto-generated bindings for the v2 torn api"
|
||||
license-file = { workspace = true }
|
||||
|
@ -36,7 +36,7 @@ futures = { version = "0.3", default-features = false, features = [
|
|||
tokio = { version = "1", features = ["full"] }
|
||||
|
||||
[build-dependencies]
|
||||
torn-api-codegen = { path = "../torn-api-codegen", version = "0.2.1" }
|
||||
torn-api-codegen = { path = "../torn-api-codegen", version = "0.2.3" }
|
||||
syn = { workspace = true, features = ["parsing"] }
|
||||
proc-macro2 = { workspace = true }
|
||||
prettyplease = "0.2"
|
||||
|
|
|
@ -62,14 +62,14 @@ pub trait BulkExecutor: Sized {
|
|||
fn execute<R>(
|
||||
self,
|
||||
requests: impl IntoIterator<Item = R>,
|
||||
) -> impl Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)>
|
||||
) -> impl Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)> + Unpin
|
||||
where
|
||||
R: IntoRequest;
|
||||
|
||||
fn fetch_many<R>(
|
||||
self,
|
||||
requests: impl IntoIterator<Item = R>,
|
||||
) -> impl Stream<Item = (R::Discriminant, Result<R::Response, Self::Error>)>
|
||||
) -> impl Stream<Item = (R::Discriminant, Result<R::Response, Self::Error>)> + Unpin
|
||||
where
|
||||
R: IntoRequest,
|
||||
{
|
||||
|
@ -173,7 +173,7 @@ pub trait BulkExecutorExt: BulkExecutor + Sized {
|
|||
}
|
||||
|
||||
#[cfg(feature = "scopes")]
|
||||
impl<'e, T> BulkExecutorExt for T
|
||||
impl<T> BulkExecutorExt for T
|
||||
where
|
||||
T: BulkExecutor + Sized,
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct ApiResponse {
|
|||
}
|
||||
|
||||
pub trait IntoRequest: Send {
|
||||
type Discriminant: Send;
|
||||
type Discriminant: Send + 'static;
|
||||
type Response: for<'de> serde::Deserialize<'de> + Send;
|
||||
fn into_request(self) -> (Self::Discriminant, ApiRequest);
|
||||
}
|
||||
|
|
|
@ -569,17 +569,16 @@ where
|
|||
fn execute<R>(
|
||||
self,
|
||||
requests: impl IntoIterator<Item = R>,
|
||||
) -> impl futures::Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)>
|
||||
) -> impl futures::Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)> + Unpin
|
||||
where
|
||||
R: torn_api::request::IntoRequest,
|
||||
{
|
||||
let requests: Vec<_> = requests.into_iter().map(|r| r.into_request()).collect();
|
||||
self.pool
|
||||
.execute_bulk_requests(
|
||||
self.selector.clone(),
|
||||
requests.into_iter().map(|r| r.into_request()),
|
||||
)
|
||||
.execute_bulk_requests(self.selector.clone(), requests)
|
||||
.into_stream()
|
||||
.flatten()
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,22 +639,23 @@ where
|
|||
fn execute<R>(
|
||||
self,
|
||||
requests: impl IntoIterator<Item = R>,
|
||||
) -> impl futures::Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)>
|
||||
) -> impl futures::Stream<Item = (R::Discriminant, Result<ApiResponse, Self::Error>)> + Unpin
|
||||
where
|
||||
R: torn_api::request::IntoRequest,
|
||||
{
|
||||
let requests: Vec<_> = requests.into_iter().map(|r| r.into_request()).collect();
|
||||
StreamExt::map(
|
||||
futures::stream::iter(requests).throttle(self.distance),
|
||||
move |r| {
|
||||
move |(d, request)| {
|
||||
let this = self.clone();
|
||||
async move {
|
||||
let (d, request) = r.into_request();
|
||||
let result = this.execute_request(request).await;
|
||||
(d, result)
|
||||
}
|
||||
},
|
||||
)
|
||||
.buffer_unordered(25)
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue