fix: add pokemon_shape schema_field definitions

This commit is contained in:
indyandie 2024-03-03 14:58:22 -06:00
parent fe9c1fa98d
commit 38f67d0473
No known key found for this signature in database
GPG key ID: FDB83C1AED3933E1
2 changed files with 97 additions and 6 deletions

View file

@ -7171,12 +7171,45 @@ components:
type: string
maxLength: 100
awesome_names:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- awesome_name
- language
properties:
awesome_name:
type: string
example: Pomaceous
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
names:
type: object
additionalProperties: {}
type: array
items:
type: object
required:
- url
- name
properties:
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/language/9/
name:
type: string
example: Ball
readOnly: true
pokemon_species:
type: array

View file

@ -4018,7 +4018,23 @@ class PokemonShapeDetailSerializer(serializers.ModelSerializer):
model = PokemonShape
fields = ("id", "name", "awesome_names", "names", "pokemon_species")
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'url', 'name' ],
'properties': {
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/language/9/'
},
'name': {
'type': 'string',
'example': 'Ball'
}
}
}
})
def get_shape_names(self, obj):
results = PokemonShapeName.objects.filter(pokemon_shape_id=obj)
serializer = PokemonShapeNameSerializer(
@ -4031,7 +4047,49 @@ class PokemonShapeDetailSerializer(serializers.ModelSerializer):
return data
@extend_schema_field(OpenApiTypes.OBJECT)
# "awesome_names": [
# {
# "awesome_name": "Pomacé",
# "language": {
# "name": "fr",
# "url": "https://pokeapi.co/api/v2/language/5/"
# }
# },
# {
# "awesome_name": "Pomaceous",
# "language": {
# "name": "en",
# "url": "https://pokeapi.co/api/v2/language/9/"
# }
# }
# ],
@extend_schema_field(field={'type': 'array',
'items': {
'type': 'object',
'required': [ 'awesome_name', 'language' ],
'properties': {
'awesome_name': {
'type': 'string',
'example': 'Pomaceous'
},
'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_shape_awesome_names(self, obj):
results = PokemonShapeName.objects.filter(pokemon_shape_id=obj)
serializer = PokemonShapeNameSerializer(