diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index e03b866b..e3c1b1cc 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -526,8 +526,8 @@ def safe_ref(schema: _SchemaType) -> _SchemaType: def append_meta(schema: _SchemaType, meta: _SchemaType) -> _SchemaType: if spectacular_settings.OAS_VERSION.startswith('3.1'): - schema = copy.deepcopy(schema) - meta = copy.deepcopy(meta) + schema = schema.copy() + meta = meta.copy() schema_nullable = meta.pop('nullable', None) meta_nullable = schema.pop('nullable', None) diff --git a/tests/test_extend_schema.py b/tests/test_extend_schema.py index 3dfedcf5..9a561b9d 100644 --- a/tests/test_extend_schema.py +++ b/tests/test_extend_schema.py @@ -248,10 +248,13 @@ class XSerializer(serializers.Serializer): def view_func(request, format=None): pass # pragma: no cover - assert_schema( - generate_schema('x', view_function=view_func), - 'tests/test_extend_schema_field_with_dict_oas_3_1.yml' - ) + schema = generate_schema('x', view_function=view_func) + + assert schema['components']['schemas']['X']['properties'] == { + 'field1': {'readOnly': True, 'type': ['string', 'null']}, + 'field2': {'readOnly': True, 'type': ['string', 'null']}, + 'field3': {'readOnly': True, 'type': ['string', 'null']} + } def test_layered_extend_schema_on_view_and_method_with_meta(no_warnings): diff --git a/tests/test_extend_schema_field_with_dict_oas_3_1.yml b/tests/test_extend_schema_field_with_dict_oas_3_1.yml deleted file mode 100644 index ae8d8395..00000000 --- a/tests/test_extend_schema_field_with_dict_oas_3_1.yml +++ /dev/null @@ -1,64 +0,0 @@ -openapi: 3.1.0 -info: - title: '' - version: 0.0.0 -paths: - /x: - post: - operationId: x_create - tags: - - x - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/X' - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/X' - multipart/form-data: - schema: - $ref: '#/components/schemas/X' - security: - - cookieAuth: [] - - basicAuth: [] - - {} - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/X' - description: '' -components: - schemas: - X: - type: object - properties: - field1: - type: - - string - - 'null' - readOnly: true - field2: - type: - - string - - 'null' - readOnly: true - field3: - type: - - string - - 'null' - readOnly: true - required: - - field1 - - field2 - - field3 - securitySchemes: - basicAuth: - type: http - scheme: basic - cookieAuth: - type: apiKey - in: cookie - name: sessionid