Skip to content

Commit

Permalink
fix: SerializedPKRelatedField schema now use nested serializer or res…
Browse files Browse the repository at this point in the history
…ponse
  • Loading branch information
Smixi authored and jeremystretch committed May 17, 2024
1 parent 97a3757 commit 79b9ef7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions netbox/core/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,14 @@ def _generate_description(self):
if '{id}' in self.path:
return f"{self.method.capitalize()} a {model_name} object."
return f"{self.method.capitalize()} a list of {model_name} objects."


class FixSerializedPKRelatedField(OpenApiSerializerFieldExtension):
target_class = 'netbox.api.fields.SerializedPKRelatedField'

def map_serializer_field(self, auto_schema, direction):
if direction == "response":
component = auto_schema.resolve_serializer(self.target.serializer, direction)
return component.ref if component else None
else:
return build_basic_type(OpenApiTypes.INT)

0 comments on commit 79b9ef7

Please sign in to comment.