-
Notifications
You must be signed in to change notification settings - Fork 420
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
Simplify code gen lib interface #2169
Conversation
Motivation: When reviewing APIs I noticed a few inconsistencies and some abstractions which are more complicated than they need to be. We should simplify this before we commit to a stable API. Modifications: - Replace the 'Name' type with a more concrete 'ServiceName' and 'MethodName'. They carry approximately equivalent information but the information is expressed in terms of what the names are used for (i.e. a function vs. what the expected format of the name is, e.g. lowercase). This makes it easier for users to understand how the names will be used and leaves room for more customisation in the future. - The service descriptor used two names: a namespace name and a service name. These have now been compressed into a single object (not all namespace name values were used). The namespace name was never used in isolation so this was adding unnecessary complexity. - The top-level 'SourceGenerator' type has been renamed 'CodeGenerator'. This is consistent with being a 'CodeGen' module and having a 'CodeGenerationRequest'. - The closures for returning code snippets to create a serializer/deserializer were renamed to make their user clearer. - Accidental public API was removed. Result: Slightly smaller and more consistent API.
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.
LGTM but one small comment
let identifier = namespace.base.isEmpty ? name.base : namespace.base + "." + name.base | ||
|
||
let upper = | ||
namespace.generatedUpperCase.isEmpty | ||
? name.generatedUpperCase | ||
: namespace.generatedUpperCase + "_" + name.generatedUpperCase | ||
|
||
let lower = |
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.
Nit, but can we rename these variable names to identifyingName
, typeName
and propertyName
?
Before looking at the tests, I was very confused about the names and what each was supposed to be 😅 (e.g. it's called lower but we use name.generatedUpperCase
, etc).
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.
Oh yes, of course. I'm not sure why I used upper and lower here
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.
btw, WDYT of identifyingName
? I'm not 100% happy with it but wasn't sure about alternatives.
Motivation:
When reviewing APIs I noticed a few inconsistencies and some abstractions which are more complicated than they need to be. We should simplify this before we commit to a stable API.
Modifications:
Result:
Slightly smaller and more consistent API.