Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenAPI Schema yaml rendering for timedelta #9007

Merged
merged 13 commits into from
Jun 17, 2023

Conversation

rnshaikh
Copy link
Contributor

@rnshaikh rnshaikh commented Jun 12, 2023

  1. fixed openapi schema yaml rendering for timedelta
  2. yaml default scalar convert timedelta into python tag !!python/object/apply:datetime.timedelta which is cant be rendered into swagger and redoc.
  3. added custom scalar which convert python tag into str

@rnshaikh rnshaikh changed the title Fix OpenAPI Schema yaml rendering for timedelta #8063 Fix OpenAPI Schema yaml rendering for timedelta Jun 12, 2023
@classmethod
def represent_timedelta(cls, dumper, data):
value = str(data.total_seconds())
return dumper.represent_scalar('tag:yaml.org,2002:str', value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you using represent_scalar from existing code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is actually the function of yaml Dumper class for overriding the tag for different datatypes or python object.
so this function gives custom representation for timedelta and first argument is dumper obj where we are adding this function

request = create_request('/')
schema = generator.get_schema(request=request)
ret = OpenAPIRenderer().render(schema)
assert b"openapi: " in ret
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain the asserts please? also it would be nice to see some additional tests if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. this test renders openapi yaml definition from an example schema which has a duration field with a default value timedelta(0) and asserts is checking for "openapi" and the duration fields default value "0.0".

I think we can add checking the" !!python/object/apply:datetime.timedelta" tag is not in response.
please let me know if you have any suggestions for cases it would be a great.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can extra tests it would be great

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added test case for rendering yaml with durationfield having minvalidator. Please check.

lnagel and others added 4 commits June 13, 2023 10:27
…#8950)

Removed the `{{ field.choices|yesno:",disabled" }}` block because this triggers the loading of full database table worth of objects just to determine whether the multi-select widget should be set as disabled or not.

Since this "disabled" marking feature is not present in the normal select field, then I propose to remove it also from the multi-select.
* Added Deprecation Warnings for CoreAPI

* Bumped removal to DRF315

* Update rest_framework/__init__.py

* Update rest_framework/filters.py

* Update rest_framework/filters.py

* Update tests/schemas/test_coreapi.py

* Update rest_framework/filters.py

* Update rest_framework/filters.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update rest_framework/pagination.py

* Update rest_framework/pagination.py

* Update rest_framework/pagination.py

* Update rest_framework/pagination.py

* Update rest_framework/schemas/coreapi.py

* Update rest_framework/schemas/coreapi.py

* Update rest_framework/schemas/coreapi.py

* Update rest_framework/schemas/coreapi.py

* Update rest_framework/schemas/coreapi.py

* Update tests/schemas/test_coreapi.py

* Update setup.cfg

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update tests/schemas/test_coreapi.py

* Update rest_framework/pagination.py

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
…es (encode#7278)

* Fix the case where if the namespace is not None and there's no match,
  NamespaceVersioning always raises NotFound even if DEFAULT_VERSION
  is set or None is in ALLOWED_VERSIONS

* Add test cases
@rnshaikh rnshaikh requested a review from auvipy June 16, 2023 17:42
@auvipy auvipy added this to the 3.15 milestone Jun 17, 2023
@auvipy auvipy added the Bug label Jun 17, 2023
@auvipy auvipy merged commit 9cfa4bd into encode:master Jun 17, 2023
@auvipy
Copy link
Member

auvipy commented Jun 17, 2023

accepted on the ground of a bug fix to a pending deprecation feature. until people migrate and we have several more release before we remove it, people will face less bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants