This is sort of a proposal / feature request.
I wanted to see proper examples for those urls instead of https://example.com so I came up with this:
class NestedHyperlinkedRelatedFieldExtension(OpenApiSerializerFieldExtension):
target_class = 'rest_framework_nested.relations.NestedHyperlinkedRelatedField'
priority = 1
def map_serializer_field(
self,
auto_schema: 'AutoSchema',
direction: Direction) -> _SchemaType:
ret = auto_schema._map_serializer_field(
self.target, direction, bypass_extensions=True)
ret['examples'] = [
'https://example.com' +
self.target.reverse(
self.target.view_name,
[1] * (len(self.target.parent_lookup_kwargs) + 1))]
return ret
Is there a way to have the url schema and hostname not be static? (I don't mind really, so this is good enough for me.)
Would this maybe be considered for inclusion in a future version of drf-spectacular?
Best regards
Friedel
This is sort of a proposal / feature request.
I wanted to see proper examples for those urls instead of
https://example.comso I came up with this:Is there a way to have the url schema and hostname not be static? (I don't mind really, so this is good enough for me.)
Would this maybe be considered for inclusion in a future version of drf-spectacular?
Best regards
Friedel