Skip to content

Conversation

PaoloAJ
Copy link

@PaoloAJ PaoloAJ commented Oct 3, 2025

What I Changed

Added a new affecting_items field to the StatDetailSerializer that returns items (vitamins and battle items) that affect each stat. This enhancement brings the stat endpoint in line with the existing affecting_moves and affecting_natures fields, providing a complete picture of all factors that can modify a Pokémon's stats.

Files Modified:

  • pokemon_v2/serializers.py - Added get_items_that_affect() method and affecting_items field to StatDetailSerializer
  • Makefile - Added auto-detection for Python/pip commands (minor improvement)

Highlights

  • New get_items_that_affect() method (pokemon_v2/serializers.py:1594): Returns a list of items that affect a given stat
  • Two categories of items tracked:
    • Vitamins (permanent stat boosters): HP Up, Protein, Iron, Calcium, Zinc, Carbos
    • X-Items (temporary battle boosters): X Attack, X Defense, X Sp. Atk, X Sp. Def, X Speed, X Accuracy, X Evasion
  • OpenAPI schema documentation included with proper typing and examples
  • Graceful error handling: Silently skips items that don't exist in the database
  • Consistent with existing patterns: Follows the same structure as affecting_moves and affecting_natures

How to Use

API Endpoint: GET /api/v2/stat/{id}/

Example Request:
curl https://pokeapi.co/api/v2/stat/2/

Example Response (for Attack stat):
{
"id": 2,
"name": "attack",
"affecting_items": [
{
"name": "protein",
"url": "https://pokeapi.co/api/v2/item/46/"
},
{
"name": "x-attack",
"url": "https://pokeapi.co/api/v2/item/47/"
}
],
"affecting_moves": { ... },
"affecting_natures": { ... },
...
}

Significance

This change completes the stat detail endpoint by providing comprehensive information about all game mechanics that affect stats. Previously, the API only exposed moves and natures that affect stats, but items are equally important in the Pokémon games for:

  1. Team building and EV training - Vitamins are essential for stat optimization
  2. Battle strategy - X-items provide temporary boosts during battles
  3. Game completeness - Aligns with how the games present stat-modifying mechanics

This makes the PokéAPI more useful for:

  • Pokémon training calculators and team builders
  • Battle simulators that need to account for item effects
  • Educational tools teaching game mechanics
  • Complete data extraction for Pokémon-related applications

The implementation maintains backward compatibility (purely additive) and follows the existing API design patterns, making it intuitive for current API consumers to adopt.

@PaoloAJ
Copy link
Author

PaoloAJ commented Oct 3, 2025

Resubmitted PR with rebased master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant