fix(codegen): fixed nested all_of

This commit is contained in:
pyrite 2025-12-03 13:55:15 +01:00
parent 2e60e0a24f
commit 06c766b7ec
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
7 changed files with 265 additions and 81 deletions

6
Cargo.lock generated
View file

@ -2257,7 +2257,7 @@ dependencies = [
[[package]] [[package]]
name = "torn-api" name = "torn-api"
version = "4.7.0" version = "5.0.2"
dependencies = [ dependencies = [
"bon", "bon",
"bytes", "bytes",
@ -2279,7 +2279,7 @@ dependencies = [
[[package]] [[package]]
name = "torn-api-codegen" name = "torn-api-codegen"
version = "0.8.0" version = "0.8.1"
dependencies = [ dependencies = [
"heck", "heck",
"indexmap", "indexmap",
@ -2292,7 +2292,7 @@ dependencies = [
[[package]] [[package]]
name = "torn-key-pool" name = "torn-key-pool"
version = "2.0.0" version = "2.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"futures", "futures",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "torn-api-codegen" name = "torn-api-codegen"
authors = ["Pyrit [2111649]"] authors = ["Pyrit [2111649]"]
version = "0.8.0" version = "0.8.1"
edition = "2021" edition = "2021"
description = "Contains the v2 torn API model descriptions and codegen for the bindings" description = "Contains the v2 torn API model descriptions and codegen for the bindings"
license = { workspace = true } license = { workspace = true }

View file

@ -473,7 +473,11 @@ impl Object {
} else { } else {
r#type r#type
}; };
let obj = Self::from_schema_object(name, r#type, schemas, warnings.child("variant")); let obj = if let Some(types) = &r#type.all_of {
Self::from_all_of(name, types, schemas, warnings.child("variant"))
} else {
Self::from_schema_object(name, r#type, schemas, warnings.child("variant"))
};
result.description = result.description.or(obj.description); result.description = result.description.or(obj.description);
result.properties.extend(obj.properties); result.properties.extend(obj.properties);

View file

@ -1,6 +1,6 @@
[package] [package]
name = "torn-api" name = "torn-api"
version = "4.7.0" version = "5.0.2"
edition = "2021" edition = "2021"
description = "Auto-generated bindings for the v2 torn api" description = "Auto-generated bindings for the v2 torn api"
license = { workspace = true } license = { workspace = true }
@ -43,7 +43,7 @@ strum = { version = "0.27.1", features = ["derive"], optional = true }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
[build-dependencies] [build-dependencies]
torn-api-codegen = { path = "../torn-api-codegen", version = "0.8" } torn-api-codegen = { path = "../torn-api-codegen", version = "0.8.1" }
syn = { workspace = true, features = ["parsing"] } syn = { workspace = true, features = ["parsing"] }
proc-macro2 = { workspace = true } proc-macro2 = { workspace = true }
prettyplease = "0.2" prettyplease = "0.2"

View file

@ -3,7 +3,7 @@
"info": { "info": {
"title": "Torn API", "title": "Torn API",
"description": "\n * The development of Torn's API v2 is still ongoing.\n * If selections remain unaltered, they will default to the API v1 version.\n * Unlike API v1, API v2 accepts both selections and IDs as path and query parameters.\n * If any discrepancies or errors are found, please submit a [bug report](https://www.torn.com/forums.php#/p=forums&f=19&b=0&a=0) on the Torn Forums.\n * In case you're using bots to check for changes on openapi.json file, make sure to specificy a custom user-agent header - CloudFlare sometimes prevents requests from default user-agents.", "description": "\n * The development of Torn's API v2 is still ongoing.\n * If selections remain unaltered, they will default to the API v1 version.\n * Unlike API v1, API v2 accepts both selections and IDs as path and query parameters.\n * If any discrepancies or errors are found, please submit a [bug report](https://www.torn.com/forums.php#/p=forums&f=19&b=0&a=0) on the Torn Forums.\n * In case you're using bots to check for changes on openapi.json file, make sure to specificy a custom user-agent header - CloudFlare sometimes prevents requests from default user-agents.",
"version": "4.6.0" "version": "5.0.2"
}, },
"servers": [ "servers": [
{ {
@ -422,7 +422,7 @@
"tags": [ "tags": [
"User" "User"
], ],
"summary": "Get your competition's event start time", "summary": "Get your calendar events start time",
"description": "Requires minimal access key. <br>Only available to yourself.", "description": "Requires minimal access key. <br>Only available to yourself.",
"operationId": "4cc4cc6fa3764f9732db9589e91d7739", "operationId": "4cc4cc6fa3764f9732db9589e91d7739",
"parameters": [ "parameters": [
@ -795,6 +795,45 @@
"x-stability": "Stable" "x-stability": "Stable"
} }
}, },
"/user/equipment": {
"get": {
"tags": [
"User"
],
"summary": "Get your equipment & clothing",
"description": "Requires minimal access key.",
"operationId": "273c3a96077332793a1b6ffe21c10218",
"parameters": [
{
"$ref": "#/components/parameters/ApiTimestamp"
},
{
"$ref": "#/components/parameters/ApiComment"
},
{
"$ref": "#/components/parameters/ApiKeyMinimal"
}
],
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserEquipmentResponse"
}
}
}
}
},
"security": [
{
"api_key": []
}
],
"x-stability": "Unstable"
}
},
"/user/events": { "/user/events": {
"get": { "get": {
"tags": [ "tags": [
@ -933,46 +972,6 @@
"x-stability": "Stable" "x-stability": "Stable"
} }
}, },
"/user/factionbalance": {
"get": {
"tags": [
"User"
],
"summary": "Deprecated. Use user/money instead",
"description": "Will be removed on 1st of December 2025. Requires limited access key. <br>",
"operationId": "b7ebbeea51dc2ef56c3ed5fd9d94e680",
"parameters": [
{
"$ref": "#/components/parameters/ApiTimestamp"
},
{
"$ref": "#/components/parameters/ApiComment"
},
{
"$ref": "#/components/parameters/ApiKeyLimited"
}
],
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserFactionBalanceResponse"
}
}
}
}
},
"deprecated": true,
"security": [
{
"api_key": []
}
],
"x-stability": "Deprecated"
}
},
"/user/forumfeed": { "/user/forumfeed": {
"get": { "get": {
"tags": [ "tags": [
@ -3427,6 +3426,12 @@
{ {
"$ref": "#/components/schemas/UserForumFriendsResponse" "$ref": "#/components/schemas/UserForumFriendsResponse"
}, },
{
"$ref": "#/components/schemas/UserPropertyResponse"
},
{
"$ref": "#/components/schemas/ReportsResponse"
},
{ {
"$ref": "#/components/schemas/UserHofResponse" "$ref": "#/components/schemas/UserHofResponse"
}, },
@ -3490,6 +3495,9 @@
{ {
"$ref": "#/components/schemas/UserListResponse" "$ref": "#/components/schemas/UserListResponse"
}, },
{
"$ref": "#/components/schemas/UserEquipmentResponse"
},
{ {
"$ref": "#/components/schemas/UserMissionsResponse" "$ref": "#/components/schemas/UserMissionsResponse"
}, },
@ -8358,6 +8366,54 @@
"x-stability": "Stable" "x-stability": "Stable"
} }
}, },
"/torn/{id}/itemdetails": {
"get": {
"tags": [
"Torn"
],
"summary": "Get information about a specific item",
"description": "Requires public key.",
"operationId": "bb6524988f52a1e75729c05a825b91c8",
"parameters": [
{
"name": "id",
"in": "path",
"description": "Item uid",
"required": true,
"schema": {
"$ref": "#/components/schemas/ItemUid"
}
},
{
"$ref": "#/components/parameters/ApiTimestamp"
},
{
"$ref": "#/components/parameters/ApiComment"
},
{
"$ref": "#/components/parameters/ApiKeyPublic"
}
],
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TornItemDetailsResponse"
}
}
}
}
},
"security": [
{
"api_key": []
}
],
"x-stability": "Unstable"
}
},
"/torn/itemmods": { "/torn/itemmods": {
"get": { "get": {
"tags": [ "tags": [
@ -9060,6 +9116,9 @@
{ {
"$ref": "#/components/schemas/TornCrimeId" "$ref": "#/components/schemas/TornCrimeId"
}, },
{
"$ref": "#/components/schemas/ItemUid"
},
{ {
"type": "array", "type": "array",
"items": { "items": {
@ -9185,9 +9244,15 @@
{ {
"$ref": "#/components/schemas/TornMeritsResponse" "$ref": "#/components/schemas/TornMeritsResponse"
}, },
{
"$ref": "#/components/schemas/TornOrganizedCrimeResponse"
},
{ {
"$ref": "#/components/schemas/TornHonorsResponse" "$ref": "#/components/schemas/TornHonorsResponse"
}, },
{
"$ref": "#/components/schemas/TornItemDetailsResponse"
},
{ {
"$ref": "#/components/schemas/TornMedalsResponse" "$ref": "#/components/schemas/TornMedalsResponse"
}, },
@ -13753,7 +13818,6 @@
"Newsletter Sending", "Newsletter Sending",
"Announcement Changes", "Announcement Changes",
"Description Changes", "Description Changes",
"Organised Crimes",
"Utility Item Loaning", "Utility Item Loaning",
"Consumable Item Usage" "Consumable Item Usage"
] ]
@ -15813,6 +15877,69 @@
} }
] ]
}, },
"UserEquipment": {
"allOf": [
{
"$ref": "#/components/schemas/TornItemDetails"
},
{
"required": [
"slot"
],
"properties": {
"slot": {
"type": "integer",
"format": "int32"
}
},
"type": "object"
}
]
},
"UserClothing": {
"required": [
"id",
"name",
"uid",
"type"
],
"properties": {
"id": {
"$ref": "#/components/schemas/ItemId"
},
"name": {
"type": "string"
},
"uid": {
"$ref": "#/components/schemas/ItemUid"
},
"type": {
"$ref": "#/components/schemas/TornItemTypeEnum"
}
},
"type": "object"
},
"UserEquipmentResponse": {
"required": [
"equipment",
"clothing"
],
"properties": {
"equipment": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserEquipment"
}
},
"clothing": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserClothing"
}
}
},
"type": "object"
},
"UserDiscordResponse": { "UserDiscordResponse": {
"required": [ "required": [
"discord" "discord"
@ -16321,11 +16448,7 @@
"UserBar": { "UserBar": {
"required": [ "required": [
"current", "current",
"maximum", "maximum"
"increment",
"interval",
"tick_time",
"full_time"
], ],
"properties": { "properties": {
"current": { "current": {
@ -16335,22 +16458,6 @@
"maximum": { "maximum": {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
},
"increment": {
"type": "integer",
"format": "int32"
},
"interval": {
"type": "integer",
"format": "int32"
},
"tick_time": {
"type": "integer",
"format": "int32"
},
"full_time": {
"type": "integer",
"format": "int32"
} }
}, },
"type": "object" "type": "object"
@ -16648,6 +16755,33 @@
}, },
"type": "object" "type": "object"
}, },
"UserCompetitionElimination": {
"required": [
"name",
"score",
"total"
],
"properties": {
"name": {
"type": "string",
"enum": [
"Elimination"
]
},
"score": {
"type": "integer",
"format": "int32"
},
"team": {
"type": "string"
},
"attacks": {
"type": "integer",
"format": "int32"
}
},
"type": "object"
},
"UserCompetitionRps": { "UserCompetitionRps": {
"required": [ "required": [
"name", "name",
@ -16699,6 +16833,9 @@
}, },
{ {
"$ref": "#/components/schemas/UserCompetitionRps" "$ref": "#/components/schemas/UserCompetitionRps"
},
{
"$ref": "#/components/schemas/UserCompetitionElimination"
} }
] ]
} }
@ -19374,7 +19511,7 @@
"UserSelectionName": { "UserSelectionName": {
"oneOf": [ "oneOf": [
{ {
"description": "The following selections will fallback to API v1 and may change at any time: 'bazaar','criminalrecord','display','equipment','gym','inventory','networth','perks','stocks'.", "description": "The following selections will fallback to API v1 and may change at any time: 'bazaar','criminalrecord','display','gym','inventory','networth','perks','stocks'.",
"type": "string", "type": "string",
"enum": [ "enum": [
"ammo", "ammo",
@ -19390,6 +19527,7 @@
"crimes", "crimes",
"discord", "discord",
"enlistedcars", "enlistedcars",
"equipment",
"events", "events",
"faction", "faction",
"factionbalance", "factionbalance",
@ -19436,7 +19574,6 @@
"criminalrecord", "criminalrecord",
"display", "display",
"education", "education",
"equipment",
"gym", "gym",
"inventory", "inventory",
"networth", "networth",
@ -23926,11 +24063,6 @@
} }
] ]
}, },
"travel_type": {
"description": "This field is replaced by the 'plane_image_type' field and will be removed on October 1st 2025.",
"type": "string",
"deprecated": true
},
"plane_image_type": { "plane_image_type": {
"$ref": "#/components/schemas/UserPlaneImageTypeEnum", "$ref": "#/components/schemas/UserPlaneImageTypeEnum",
"description": "This field is populated only if the state is 'Traveling'." "description": "This field is populated only if the state is 'Traveling'."
@ -27871,6 +28003,54 @@
}, },
"type": "object" "type": "object"
}, },
"TornItemDetails": {
"allOf": [
{
"$ref": "#/components/schemas/ItemMarketListingItemDetails"
},
{
"required": [
"id",
"name",
"type",
"sub_type"
],
"properties": {
"id": {
"$ref": "#/components/schemas/ItemId"
},
"name": {
"type": "string"
},
"type": {
"$ref": "#/components/schemas/TornItemTypeEnum"
},
"sub_type": {
"oneOf": [
{
"$ref": "#/components/schemas/TornItemWeaponTypeEnum"
},
{
"type": "null"
}
]
}
},
"type": "object"
}
]
},
"TornItemDetailsResponse": {
"required": [
"itemdetails"
],
"properties": {
"itemdetails": {
"$ref": "#/components/schemas/TornItemDetails"
}
},
"type": "object"
},
"TornMerit": { "TornMerit": {
"required": [ "required": [
"id", "id",

View file

@ -777,7 +777,7 @@ pub(super) mod test {
async fn user_factionbalance() { async fn user_factionbalance() {
let client = test_client().await; let client = test_client().await;
client.user().factionbalance(|b| b).await.unwrap(); client.user().money(|b| b).await.unwrap();
} }
#[tokio::test] #[tokio::test]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "torn-key-pool" name = "torn-key-pool"
version = "2.0.0" version = "2.1.0"
edition = "2021" edition = "2021"
authors = ["Pyrit [2111649]"] authors = ["Pyrit [2111649]"]
license = { workspace = true } license = { workspace = true }
@ -14,7 +14,7 @@ postgres = ["dep:sqlx", "dep:chrono", "dep:indoc"]
tokio-runtime = ["dep:tokio", "dep:rand", "dep:tokio-stream"] tokio-runtime = ["dep:tokio", "dep:rand", "dep:tokio-stream"]
[dependencies] [dependencies]
torn-api = { path = "../torn-api", default-features = false, version = "4.1.1" } torn-api = { path = "../torn-api", default-features = false, version = "5.0.2" }
thiserror = "2" thiserror = "2"
sqlx = { version = "0.8", features = [ sqlx = { version = "0.8", features = [