Skip to content

Commit

Permalink
Do not generate form parameters for read_only serializer fields
Browse files Browse the repository at this point in the history
Fixes #261.
  • Loading branch information
axnsan12 committed Dec 19, 2018
1 parent eeb1bba commit c5d4e6c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/drf_yasg/inspectors/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_request_parameters(self, serializer, in_):
)
for key, value
in fields.items()
if not getattr(value, 'read_only', False)
]

return self.add_manual_parameters(serializer, parameters)
Expand Down
2 changes: 1 addition & 1 deletion src/drf_yasg/inspectors/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from rest_framework.schemas import AutoSchema
from rest_framework.status import is_success

from .base import ViewInspector
from .. import openapi
from ..errors import SwaggerGenerationError
from ..utils import (
filter_none, force_real_str, force_serializer_instance, get_consumes, get_produces, guess_response_status,
is_list_view, merge_params, no_body, param_list_to_odict
)
from .base import ViewInspector

log = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions testproj/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Meta:


class ImageUploadSerializer(serializers.Serializer):
image_id = serializers.UUIDField(read_only=True)
what_am_i_doing = serializers.RegexField(
regex=r"^69$",
help_text="test",
Expand Down
4 changes: 4 additions & 0 deletions tests/reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ definitions:
- image_styles
type: object
properties:
image_id:
type: string
format: uuid
readOnly: true
what_am_i_doing:
description: test
type: string
Expand Down

0 comments on commit c5d4e6c

Please sign in to comment.