- ID
- 8f70e8e8-ffc2-4d2b-a0fc-c4624f2b764e
BE-7233 Add proper schema typing for discount_info expand on V3 pairings endpoint
- source :: https://hungryroot.atlassian.net/browse/BE-7233
- tags :: Hungryroot API Project
- epic :: EP-411 Eng Parking Lot
- sprint :: HR BE Sprint 105
- status :: Status - Complete
Tasks
DONE Try just adding the doc string to the extended schema
- ID
- c3fb14d9-f604-f465-739c-da987d8f6b39
Tests
[[file:../../apis/hungryroot/v3.http::GET :host/api/v3/pairings/464473/?expand=ingredients%2Ctags%2Cnutrition%2Cdiscount_info&inventory_date=2024-01-15][API call]]
#+begin_src shell
curl -X 'GET' 'http://localhost:8000/api/v3/pairings/464473/?expand=ingredients%2Ctags%2Cnutrition%2Cdiscount_info' -H 'accept: application/json'
#+end_src
Description
Problem
The discount_info expandable field on the PairingStaticListViewset
(/api/v3/pairings) endpoint is missing proper schema typing. drf-spectacular
cannot infer the response shape from the SerializerMethodField that delegates to
PairingDiscountSerializer, so the generated OpenAPI schema falls back to an
untyped object:
#+begin_src json
"discount_info": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
#+end_src
This means API consumers have no typed contract for this field -- frontend and
mobile clients cannot generate types from the schema, and the Swagger docs are
misleading.
Expected
The OpenAPI schema should reflect the actual typed response from
PairingDiscountSerializer (defined in app/rest/shared/discount_serializer.py):
#+begin_src json
"discount_info": {
"discount": null,
"discount_percentage": null,
"points_after_discount": null
}
#+end_src
With proper nullable number types so clients can generate accurate
TypeScript/Swift/Kotlin types from the spec.
Approach
Add an @extend_schema_field decorator or inline OpenApiTypes annotation to the
get_discount_info method in PairingSerializer (app/rest/v3/pairing.py) so
drf-spectacular emits the correct schema.
Files
app/rest/v3/pairing.py -- PairingSerializer.get_discount_info
app/rest/shared/discount_serializer.py -- PairingDiscountSerializer