-
-
Notifications
You must be signed in to change notification settings - Fork 227
Don't depend on stringcase (closes #369) #375
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
Conversation
Let's reimplement what we need here so that we don't depend on stringcase anymore (see openapi-generators#369 for rationale). I've added a few test cases for stuff I've seen break along the way.
This kind of work with regexps and a large variety of use cases is always a bit fragile, so even if all the tests pass, I'd recommend that you test the branch against other openapi.yaml files you may have already a generated client to see if there isn't any weird diff. Only fixed a lot of bugs on my side. :) |
Is there a rationale for implementing our own vs relying on one of the other libraries you mentioned in #369? I'm thinking one of them might have a more expansive test suite to catch any corner-case bugs (and if they don't... they should 😂) |
Yeah, none of the two libraries passed the tests out of the box. Both needed hacks or pull-requests to make everything work together. I figured out that rather than spending time to write hacks or modify yet another project, I'd rather implement that here. It's just three functions to maintain, so I don't think it's worth a dependency, and most importantly, that would give you full control over the generated output. About full control... The e2e tests are broken as you can see, and this is due to what seems to me to be an inconsistency in the previous implementation. :) What do you think of such diffs in the generated output? -from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200
+from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200 -from .model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0
-from .model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1
+from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
+from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 |
Here are two diffs that would make things more consistent: https://gist.github.com/ramnes/611b874b878f55f5bfc4b781d48c40a1
|
FWIW, here is the diff when running the current version of the PR against sftpgo-client: ramnes/sftpgo-client@8e620d5 |
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.
A couple tweaks to make, and I think I'm going to try and preserve the previous behavior of saving leading delimiters just to reduce update friction.
openapi_python_client/utils.py
Outdated
return fix_keywords(stringcase.pascalcase(sanitize(value.replace(" ", "")))) | ||
words = split_words(sanitize(value)) | ||
words = [word.capitalize() if not word.isupper() else word for word in words] | ||
value = "".join(words) |
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.
A side-effect of this is that a leading delimiter gets stripped. So _MyClass and __MyClass both become MyClass. This may not be a problem, but it is a breaking change.
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.
Good catch. I wonder if we should stay consistent or not. What do you think?
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.
After thinking about it a bit, I think it's better to remove the leading underscores since that has the semantics in Python of being private. Nothing in the generated interfaces should be private so... this new behavior seems better.
Codecov Report
@@ Coverage Diff @@
## main #375 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 46 46
Lines 1523 1530 +7
=========================================
+ Hits 1523 1530 +7
Continue to review full report at Codecov.
|
@@ -27,5 +27,5 @@ | |||
from .model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0 | |||
from .model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1 | |||
from .test_inline_objects_json_body import TestInlineObjectsJsonBody | |||
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200 | |||
from .test_inline_objects_response200 import TestInlineObjectsResponse200 |
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.
Another issue 😞. I imagine this is why all of the existing string case libraries get it wrong... so many edge cases. I'll add a unit test for this one.
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.
Yep, that's exactly what I was talking about in my previous comment.
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.
Alright, this covers all the cases I can think of now. @ramnes will you take a look through the changes when you get a chance and make sure it looks good to you?
I think there are a few problems but I can't dig right now, please don't merge it yet. |
Alright, so #397 is the problem I saw while trying this branch in real conditions. I thought it was linked to the changes here and it's actually not, but it makes it tricky for me to smoke test this branch due to the lot of noise it introduces. |
Awesome, thanks for checking it out! I'm going to move forward with this one then and we can squash that bug separately. |
I think that one of your commits here introduced two problems: - id_=id_,
+ id=id, and - s3config: Union[Unset, S3Config] = UNSET
+ s_3_config: Union[Unset, S3Config] = UNSET |
The s_3_config thing is unfortunate but intentional... I wanted to make numbers be separate words since we often have things like |
Maybe it should only be a separate word if it doesn't follow a capital letter? |
Let's reimplement what we need here so that we don't depend on stringcase
anymore (see #369 for rationale). I've added a few test cases for stuff I've
seen break along the way.