You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using the build_examples_list function, the name of each example is converted to camelcase. The converted value then becomes the key for that specific example.
To be precise, the conversion to camelCase is implemented through the inflection library, and since the second argument is not passed to the camelize function, it converts the first letter of each word, including the first one, to uppercase, which results in PascalCase.
However, when using a special character as the first character in the example name, unexpected results occurred.
To Reproduce
>>> from inflection import camelize
>>> camelize("-example_string", True)
>>> "-exampleString"
The first time I encountered this issue was when I override the descending order example for Django's ordering query string using extend_schema.
@extend_schema_view(
list=extend_schema(
parameters=[
...
OpenApiParameter(
name="ordering",
...
examples=[
OpenApiExample(
"post_count",
description="Ascending order based on the number of posts.",
value="post_count",
),
OpenApiExample(
"-post_count",
description="Descending order based on the number of posts.",
value="-post_count",
),
],
),
],
...
)
)
class CategoryViewSet(ListModelMixin, GenericViewSet):
In the case of post_count, it is converted to PostCount using the camelize function. However, -post_count is returned as -postCount instead of the expected -PostCount.
Actually, I'm not sure how the conversion to PascalCase should work when special characters are included in the string.
Expected behavior
As explained in the "To Reproduce" section, I expected that when using a string like "{special_character}hello_world", it would be converted to "{special_character}HelloWorld".
The text was updated successfully, but these errors were encountered:
There is one thing I'm curious about. Why drf_spectacular perform the following normalization on the example names? 🧐 normalized_name = inflection.camelize(example.name.replace(' ', '_'))
If it doesn't relate to the displayed part, I feel that the normalization process might not be necessary.
Describe the bug
Using the build_examples_list function, the name of each example is converted to camelcase. The converted value then becomes the key for that specific example.
To be precise, the conversion to camelCase is implemented through the inflection library, and since the second argument is not passed to the camelize function, it converts the first letter of each word, including the first one, to uppercase, which results in PascalCase.
However, when using a special character as the first character in the example name, unexpected results occurred.
To Reproduce
The first time I encountered this issue was when I override the descending order example for Django's ordering query string using extend_schema.
In the case of post_count, it is converted to PostCount using the camelize function. However, -post_count is returned as -postCount instead of the expected -PostCount.
Actually, I'm not sure how the conversion to PascalCase should work when special characters are included in the string.
Expected behavior
As explained in the "To Reproduce" section, I expected that when using a string like "{special_character}hello_world", it would be converted to "{special_character}HelloWorld".
The text was updated successfully, but these errors were encountered: