-
-
Notifications
You must be signed in to change notification settings - Fork 227
fix!: Normalize generated module names to allow more tags [#428]. Thanks @iamnoah! #448
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!: Normalize generated module names to allow more tags [#428]. Thanks @iamnoah! #448
Conversation
Codecov Report
@@ Coverage Diff @@
## main #448 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 1563 1562 -1
=========================================
- Hits 1563 1562 -1
Continue to review full report at Codecov.
|
@forest-benchling if you get a chance can you take a look at this? Fairly simple changes but a lot of code is touched. |
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.
@@ -19,3 +20,7 @@ def default(cls) -> Type[DefaultEndpoints]: | |||
@classmethod | |||
def parameters(cls) -> Type[ParametersEndpoints]: | |||
return ParametersEndpoints | |||
|
|||
@classmethod | |||
def tag1(cls) -> Type[Tag1Endpoints]: |
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.
from ... import Config | ||
from ...utils import fix_keywords, fix_reserved_words, sanitize, snake_case | ||
|
||
_PythonIdentifier = NewType("_PythonIdentifier", str) |
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.
Should this be underscored if it's being used by a bunch of other modules?
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.
I believe it's only being used directly by one other module. The _
is really there to indicate that you shouldn't be constructing this class directly, but only by using the sanitization method. Best I could come up with for trying to enforce sanitization with types 🤷.
Although now that I'm thinking about it, maybe using a custom __init__
would be better... 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.
Nice, cool solution you ended up with.
_PythonIdentifier = NewType("_PythonIdentifier", str) | ||
|
||
|
||
def to_valid_python_identifier(*, value: str, prefix: str) -> _PythonIdentifier: |
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.
Why was this moved out of utils
with all the other case conversion logic? Seems clearer to be there, IMO.
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.
To keep the private constructor as private as possible, since the type is used directly here.
@@ -41,7 +42,7 @@ def from_data( | |||
operation: Optional[oai.Operation] = getattr(path_data, method) | |||
if operation is None: | |||
continue | |||
tag = utils.snake_case((operation.tags or ["default"])[0]) | |||
tag = to_valid_python_identifier(value=(operation.tags or ["default"])[0], prefix="tag") |
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.
Would it be too much work to make "tag"
configurable, like field prefix?
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.
I think it'd be pretty easy to add in a future PR if anyone wants it.
6bdd232
to
a761eff
Compare
FYI @forest-benchling I did end up changing it to a public class with a custom |
This PR is motivated to fix #428 but as part of that fix there are a few other changes: