fix: add pokemon-species schema_field definitions

This commit is contained in:
indyandie 2024-03-03 20:49:15 -06:00
parent 029f663d2f
commit 0fabe2c70c
No known key found for this signature in database
GPG key ID: FDB83C1AED3933E1
2 changed files with 278 additions and 18 deletions

View file

@ -3640,8 +3640,20 @@ components:
$ref: '#/components/schemas/EvolutionTriggerName'
readOnly: true
pokemon_species:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- name
- url
properties:
name:
type: string
example: ivysaur
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/pokemon-species/2/
readOnly: true
required:
- id
@ -7561,8 +7573,20 @@ components:
$ref: '#/components/schemas/PokemonDexEntry'
readOnly: true
egg_groups:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- name
- url
properties:
name:
type: string
example: monster
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/egg-group/1/
readOnly: true
color:
$ref: '#/components/schemas/PokemonColorSummary'
@ -7577,12 +7601,58 @@ components:
generation:
$ref: '#/components/schemas/GenerationSummary'
names:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- language
- name
properties:
language:
type: object
required:
- name
- url
properties:
name:
type: string
example: en
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/language/9/
name:
type: string
example: bulbasaur
readOnly: true
pal_park_encounters:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- area
- base_score
- rate
properties:
area:
type: object
required:
- name
- url
properties:
name:
type: string
example: field
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/pal-park-area/2/
base_score:
type: number
example: 50
rate:
type: number
example: 30
readOnly: true
form_descriptions:
type: array
@ -7595,12 +7665,54 @@ components:
$ref: '#/components/schemas/PokemonSpeciesFlavorText'
readOnly: true
genera:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- genus
- language
properties:
genus:
type: string
example: Seed Pokémon
language:
type: object
required:
- name
- url
properties:
name:
type: string
example: en
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/language/9/
readOnly: true
varieties:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- is_default
- pokemon
properties:
is_default:
type: boolean
example: true
pokemon:
type: object
required:
- name
- url
properties:
name:
type: string
example: bulbasaur
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/pokemon/1/
readOnly: true
required:
- color

View file

@ -5044,7 +5044,24 @@ class EvolutionTriggerDetailSerializer(serializers.HyperlinkedModelSerializer):
model = EvolutionTrigger
fields = ("id", "name", "names", "pokemon_species")
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={
'type': 'array',
'items': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'ivysaur'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/pokemon-species/2/'
}
}
}
})
def get_species(self, obj):
evo_objects = PokemonEvolution.objects.filter(evolution_trigger=obj)
species_list = []
@ -5152,7 +5169,33 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
"varieties",
)
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'language', 'name' ],
'properties': {
'language': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'en'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/language/9/'
}
}
},
'name': {
'type': 'string',
'example': 'bulbasaur'
}
}
}
})
def get_pokemon_names(self, obj):
species_results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
species_serializer = PokemonSpeciesNameSerializer(
@ -5166,7 +5209,40 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
return data
@extend_schema_field(OpenApiTypes.OBJECT)
# {
# "genus": "Seed Pokémon",
# "language": {
# "name": "en",
# "url": "https://pokeapi.co/api/v2/language/9/"
# }
# },
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'genus', 'language' ],
'properties': {
'genus': {
'type': 'string',
'example': 'Seed Pokémon'
},
'language': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'en'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/language/9/'
}
}
}
}
}
})
def get_pokemon_genera(self, obj):
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
serializer = PokemonSpeciesNameSerializer(
@ -5182,7 +5258,23 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
return genera
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'monster'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/egg-group/1/'
}
}
}
})
def get_pokemon_egg_groups(self, obj):
results = PokemonEggGroup.objects.filter(pokemon_species=obj)
data = PokemonEggGroupSerializer(results, many=True, context=self.context).data
@ -5192,7 +5284,33 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
return groups
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'is_default', 'pokemon' ],
'properties': {
'is_default': {
'type': 'boolean',
'example': True
},
'pokemon': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'bulbasaur'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/pokemon/1/'
}
}
}
}
}
})
def get_pokemon_varieties(self, obj):
results = Pokemon.objects.filter(pokemon_species=obj)
summary_data = PokemonSummarySerializer(
@ -5212,7 +5330,37 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
return varieties
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'area', 'base_score', 'rate' ],
'properties': {
'area': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'field'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/pal-park-area/2/'
}
}
},
'base_score': {
'type': 'number',
'example': 50
},
'rate': {
'type': 'number',
'example': 30
}
}
}
})
def get_encounters(self, obj):
pal_park_objects = PalPark.objects.filter(pokemon_species=obj)
parks = PalParkSerializer(