fix: add pokedex schema_field definitions

This commit is contained in:
indyandie 2024-03-04 00:44:24 -06:00
parent 8060b59125
commit 807fbc1869
No known key found for this signature in database
GPG key ID: FDB83C1AED3933E1
2 changed files with 81 additions and 6 deletions

View file

@ -6986,14 +6986,47 @@ components:
$ref: '#/components/schemas/PokedexName'
readOnly: true
pokemon_entries:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- entry_number
- pokemon_species
properties:
entry_number:
type: number
example: 1
pokemon_species:
type: object
required:
- name
- url
properties:
name:
type: string
example: bulbasaur
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/pokemon-species/1/
readOnly: true
region:
$ref: '#/components/schemas/RegionSummary'
version_groups:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- name
- url
properties:
name:
type: string
example: the-teal-mask
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/version-group/26/
readOnly: true
required:
- descriptions

View file

@ -5874,7 +5874,33 @@ class PokedexDetailSerializer(serializers.ModelSerializer):
"version_groups",
)
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'entry_number', 'pokemon_species' ],
'properties': {
'entry_number': {
'type': 'number',
'example': 1
},
'pokemon_species': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'bulbasaur'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/pokemon-species/1/'
}
}
}
}
}
})
def get_pokedex_entries(self, obj):
results = PokemonDexNumber.objects.filter(pokedex=obj).order_by(
"pokedex_number"
@ -5889,7 +5915,23 @@ class PokedexDetailSerializer(serializers.ModelSerializer):
return data
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'the-teal-mask'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/version-group/26/'
}
}
}
})
def get_pokedex_version_groups(self, obj):
dex_group_objects = PokedexVersionGroup.objects.filter(pokedex=obj)
dex_groups = PokedexVersionGroupSerializer(