-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
599 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from sys import stdout | ||
|
||
|
||
def custom_postprocessing_hook(result, generator, request, public): | ||
""" | ||
DRF Spectacular adds default = [] to the item inside an array on PrimaryKeyRelatedField fields with many=True like | ||
`onderwerp_ids = serializers.PrimaryKeyRelatedField( | ||
many=True, | ||
write_only=True, | ||
queryset=Onderwerp.objects.all(), | ||
source="onderwerpen", | ||
)` | ||
(src/open_producten/producttypen/serializers/producttype.py) | ||
""" | ||
|
||
schemas = result.get("components", {}).get("schemas", {}) | ||
|
||
for schema_key, schema in schemas.items(): | ||
properties = schema.get("properties", {}) | ||
|
||
for prop_key, prop in properties.items(): | ||
if prop_key.endswith("_ids"): | ||
stdout.write(f"removed default=[] from {schema_key}.{prop_key}\n") | ||
items = prop.get("items", {}) | ||
items.pop("default", None) | ||
items.pop("writeOnly", None) | ||
|
||
return result |
Oops, something went wrong.