fix: add pokeathlon_stat schema_field definitions

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

View file

@ -6865,7 +6865,60 @@ components:
maxLength: 100
affecting_natures:
type: object
additionalProperties: {}
required:
- decrease
- increase
properties:
decrease:
type: array
items:
type: object
required:
- max_change
- nature
properties:
max_change:
type: number
maximum: -1
example: -1
nature:
type: object
required:
- name
- url
properties:
name:
type: string
example: hardy
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/nature/1/
increase:
type: array
items:
type: object
required:
- max_change
- nature
properties:
max_change:
type: number
minimum: 1
example: 2
nature:
type: object
required:
- name
- url
properties:
name:
type: string
example: hardy
url:
type: string
format: uri
example: https://pokeapi.co/api/v2/nature/1/
readOnly: true
names:
type: array

View file

@ -5753,7 +5753,69 @@ class PokeathlonStatDetailSerializer(serializers.HyperlinkedModelSerializer):
model = PokeathlonStat
fields = ("id", "name", "affecting_natures", "names")
@extend_schema_field(OpenApiTypes.OBJECT)
@extend_schema_field(field={'type': 'object',
'required': [ 'decrease', 'increase' ],
'properties': {
'decrease': {
'type': 'array',
'items': {
'type': 'object',
'required': [ 'max_change', 'nature' ],
'properties': {
'max_change': {
'type': 'number',
'maximum': -1,
'example': -1
},
'nature': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'hardy'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/nature/1/'
}
}
}
}
}
},
'increase': {
'type': 'array',
'items': {
'type': 'object',
'required': [ 'max_change', 'nature' ],
'properties': {
'max_change': {
'type': 'number',
'minimum': 1,
'example': 2
},
'nature': {
'type': 'object',
'required': [ 'name', 'url' ],
'properties': {
'name': {
'type': 'string',
'example': 'hardy'
},
'url': {
'type': 'string',
'format': 'uri',
'example': 'https://pokeapi.co/api/v2/nature/1/'
}
}
}
}
}
}
}
})
def get_natures_that_affect(self, obj):
stat_change_objects = NaturePokeathlonStat.objects.filter(pokeathlon_stat=obj)
stat_changes = NaturePokeathlonStatSerializer(