-
Notifications
You must be signed in to change notification settings - Fork 507
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
Improve Generics Naming #470
Comments
This sounds like a great idea. And since we only recently fixed the generic names, then I think it would be okay to release this as a minor or patch version if the existing unit tests pass. It sounds like this would simplify the code quite a bit. If so, then it sounds like a great idea. Thank you @WoH! :) |
The unit tests do rely on specific naming, unfortunately.
Every time we check $ref for Promises, Arrays, Generics, the new name would be different, that's why. It indeed removes a considerable amount of code inside the resolver. I stumbled on a smaller potential issue I'll talk about later, but this is just about getting a feel for the preferred naming conventions we should follow. |
@WoH, how do you feel this proposal would work with code generation? I know that it’s out of tsoa’s scope to worry about someone trying to generate code from the swagger, but we have gotten complaints before (which is why that “hard assert” code is in there). So if you get a chance to try out how pipe and period work in the names when swagger editor generates C# code (for instance), that would be helpful. I will also do some experiments too. Anyway, we would be fine as long as this new naming pattern doesn’t hinder devs who like to create service libraries from swagger docs. |
I've tried very hard to avoid potential issues considering the specs (json schema, uri, openapi & swagger) but I think if we can avoid issues with the swagger codegen I'd like to do that. Will report back. |
I assumed from the comments that this was supposed to ensure we follow the RFC3986 using percent-encoded URIs (which
Do you have a link to that issue by any chance? I assume that specific codegen does not translate legal swagger/openapi3 names into valid c# names? |
I tried the OpenAPI 3 generators from here since the swagger ones are all over the place for OpenAPI 3 specs. |
I know I’m very late to be asking for an alternative approach, but maybe this would be an easy change. So it’s a small tweak on your recommendation (copies here for convenience):
I like all of that except the generic substitutions since I find the underscore to be less than readable. So I’d like to recommend an approach that has two benefits:
And to show how that would work: Another example, would be Omit (which I know that we don’t support now, but there is a bounty out there for it). So |
I thought about this when I made the proposal, but this would clash more easily. Which means we need to indicate the closing |
I have three followup questions:
|
One underscore for |
You said conditional, but you mentioned both mapped and conditional types. |
Great. So I’m aligned with your vision (I think). And the parts I don’t get, I trust and/or will help verify. So I recognize that what I’m about to say is a change of decisions, but maybe it really does make sense to change these PRs so they merge to a “v3Branch” branch? That way when we’re read to go, we just merge master back into the v3Branch branch and we’d be able to release v3. Because I want to make it easy on all of us, but I’m not sure exactly how to do that. Perhaps a long-lived branch is right idea? I’m totally open to ideas. Oh and just so I’m clear, is the type alias dependent on the generic name change PR that we’re currently discussing? (My assumption is yes and that it would also be apart of the v3Branch branch) |
I wanted to ask for a branch at some point, but it felt like I'd overstep my boundaries. That being said, I'd say it definitely makes sense if you want to cut a "big 3.0" release. |
Yes and yes. A roadmap would be helpful I think. What is the best way to do that? (I’d google it but I’m grocery shopping right now haha) And if you’re okay with changing the PR merge destination to this branch then please do so. :) |
GitHub supports this and you can add both PRs and issues to a milestone, maybe it's a good idea to make it visible to everyone so they can track our progress / find issues to help with. I don't have the permissions, but you can add a milestone and attach the issues. |
Okay, I added a few of the PRs to the new board. Please let me know if I’m missing any across the multiple columns: https://github.com/lukeautry/tsoa/projects/1?add_cards_query=is%3Aopen#column-6640263 |
Maybe this and removing boolean as a valid setting for excessProps |
The current naming for supported generic types (aka interfaces) is not very helpful.
Tsoa does some parsing around the model and the generics like
MyModel<Item[]>
becomesMyModelItemArray
in the schema. However, this use case is very narrowly defined and might lead to more name clashes down the line. Passing literals like `MyModel<'id'> is entirely unsupported only because there is no case to get the name.Any effort to fix #338 would also have to deal with this limitation.
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
See possible solution
Current Behavior
One example:
MyModel<T | U>
becomesMyModelobject
and therefore overrides any otherMyModel
declarations with an object or a union.Possible Solution
We do a lot of mostly unnecessary work when we could just use the name TypeScript gives the References (
typeReferenceWithGenerics.getText()
) and replace chars not allowed by RFC3986.I.e.
MyType<T, A | B>
should be something likeMyType_T.A|B_
.This is something that can be done in a few lines of code instead just blowing up the name finder for the type resolver.
Exemplary steps could be:
<>
with__
,
with.
[]
withArray
&
with And"
or'
The amount of escapes here is properly specified and therefore, I'd argue, pretty reasonable to implement.
https://tools.ietf.org/html/rfc3986
Another option would be to %-encode (due to easy implementation), but it would hurt readability.
Exemplary types can be en/decoded here: https://www.url-encode-decode.com/
Context (Environment)
Version of the library: any recent version
Version of NodeJS: irrelevant
Breaking change?
Depends. Yes if someone depends on the naming tsoa uses for models. However, this does fix a lot of reproducible problems with schema creation. Maybe it makes sense to ship this improvement in 3.0, but it would require a timely major version bump since the current procedure should impede any effort of confidently releasing improvements for generic types.
The text was updated successfully, but these errors were encountered: