From 38f67d047305663eb91f1607858aee712a7a3c28 Mon Sep 17 00:00:00 2001 From: indyandie <1058837+Indyandie@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:58:22 -0600 Subject: [PATCH] fix: add `pokemon_shape` schema_field definitions --- openapi.yml | 41 +++++++++++++++++++++++--- pokemon_v2/serializers.py | 62 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/openapi.yml b/openapi.yml index dc0df517..b0a6b4c8 100644 --- a/openapi.yml +++ b/openapi.yml @@ -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 diff --git a/pokemon_v2/serializers.py b/pokemon_v2/serializers.py index edc1fff7..596a6827 100644 --- a/pokemon_v2/serializers.py +++ b/pokemon_v2/serializers.py @@ -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(