Closed Rdlenke closed 2 years ago
UPDATE: Turns out that the error was right in from of my eyes.
The Type
model describes past_damage_relations
as below:
pub past_damage_relations: Vec<TypeRelationsPast>
And TypeRelationsPast
is
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct TypeRelationsPast {
pub generation: NamedAPIResource<Generation>,
pub damage_relations: Vec<TypeRelations>
}
The problem is that damage_relations
is no Vec
. Here's a snippet of the results that requesting the type steel gives using postman:
"past_damage_relations": [
{
"damage_relations": { // <--- Object, not list
"double_damage_from": [
{
"name": "fighting",
"url": "https://pokeapi.co/api/v2/type/2/"
},
{
"name": "ground",
"url": "https://pokeapi.co/api/v2/type/5/"
},
{
"name": "fire",
"url": "https://pokeapi.co/api/v2/type/10/"
}
],
Simply changing TypeRelationsPast
to the struct below fixes the problem.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct TypeRelationsPast {
pub generation: NamedAPIResource<Generation>,
pub damage_relations: TypeRelations
}
Curiously, the PokéAPI documentation does describe damage_relations
in TypeRelationsPast
as a list. I'll open an issue in their repository, and hopefully the docs will be fixed soon. Meanwhile, do you want me to open a PR fixing this model?
Hey @Rdlenke ! Thanks for reaching out !
Indeed, the documentation in PokeApi seems to be outdated, you're right to open an issue on their side.
You were also right to open an issue here as well. I agree with you on the fix. You can do it if you want to or I can do it later in the day, just let me know !
Also, I am learning Rust too. Feel free to give me some feedback about the code, architecture etc etc...
I stay available if you need, and thanks again for the help !
@mlemesle I've created the PR and also created the issue on the PokeAPI repo. They've already fixed the docs website.
Thanks again for this awesome wrapper, and for the help. As I use it (and learn rust), I'll surely come up with suggestions.
I merged it! Thanks for the help there.
Feel free to contact me anytime :)
Good day @mlemesle. Nice lib you got there.
I'm learning rust and was trying to use this wrapper to make something pokémon related, but I ran into a problem. It seems that
reqwest
orserde
have some problems deserializing some pokémon types. Ex:Cargo.toml
src/main.rs
Output:
Using
skip_deserializing
I was able to remove field by field from theType
model and found that bothdamage_relations
andpast_damage_relations
are problematic, but I couldn't really understand why. Could you help?Thanks in advance!
R.L.