mlemesle / rustemon

A wrapper library for PokeApi, written in Rust
MIT License
28 stars 10 forks source link

Unable to get evolution chain #3

Closed shall-code closed 2 years ago

shall-code commented 2 years ago

Hi, I encountered an issue when trying to use the evolution chain endpoint. Looks like there is a problem with the json deserialization.

Example:

let evolution_chain = rustemon::blocking::evolution::evolution_chain::get_by_id(2);
match evolution_chain {
    Ok(e) => println!("{:#?}", e),
    Err(err) => println!("An error occurred : {}", err),
}

Result: An error occurred : error decoding response body: invalid length 0, expected struct EvolutionDetail with 18 elements at line 1 column 57

Taking a look at the actual json output from https://pokeapi.co/api/v2/evolution-chain/2 we can see it starts with {"baby_trigger_item":null,"chain":{"evolution_details":[],"evolves_to"... so it is having a problem with the empty brackets value [].

Possible fix? The evolution_details field in the ChainLink struct at src/model/evolution.rs#L26 is declared with the type Option<EvolutionDetail> and maybe it should be Option<Vec<EvolutionDetail>> instead?

mlemesle commented 2 years ago

Hello @shall-code !

Thanks for reaching out ! You're right about the problem, and you're right as well about the fix !

If you're interested, I can let you do the fix and create a pull request. If not, I can do it myself.

Please let me know if you want to do it or not.

shall-code commented 2 years ago

PR submitted! I was able to use the endpoint successfully after recompiling with this change and running the example above again. It's been fun working with this library so far, thanks for making it!

mlemesle commented 2 years ago

Hey !

Thanks to you, version 1.0.1 is now live ! Nice work on this one and thanks for the contribution !

No problem for the library, was fun to create. I'm glad you're enjoying it