-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Changes from all commits
43f9bd2
98ce5bf
d168005
297f37e
e9f46ee
8333134
a16dbfd
aed7761
71f87a5
214702c
95aad32
c5613a8
474dcdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1162,6 +1162,31 @@ def test_schema_rendering_to_json(self): | |
assert b'"openapi": "' in ret | ||
assert b'"default": "0.0"' in ret | ||
|
||
def test_schema_rendering_to_yaml(self): | ||
patterns = [ | ||
path('example/', views.ExampleGenericAPIView.as_view()), | ||
] | ||
generator = SchemaGenerator(patterns=patterns) | ||
|
||
request = create_request('/') | ||
schema = generator.get_schema(request=request) | ||
ret = OpenAPIRenderer().render(schema) | ||
assert b"openapi: " in ret | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you can extra tests it would be great There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
assert b"default: '0.0'" in ret | ||
|
||
def test_schema_rendering_timedelta_to_yaml_with_validator(self): | ||
|
||
patterns = [ | ||
path('example/', views.ExampleValidatedAPIView.as_view()), | ||
] | ||
generator = SchemaGenerator(patterns=patterns) | ||
|
||
request = create_request('/') | ||
schema = generator.get_schema(request=request) | ||
ret = OpenAPIRenderer().render(schema) | ||
assert b"openapi: " in ret | ||
assert b"duration:\n type: string\n minimum: \'10.0\'\n" in ret | ||
|
||
def test_schema_with_no_paths(self): | ||
patterns = [] | ||
generator = SchemaGenerator(patterns=patterns) | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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