-
Notifications
You must be signed in to change notification settings - Fork 954
Support Thrift TypeDef in DocService #4628
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
Motivation: https://thrift.apache.org/docs/idl#typedef Modifications: Result:
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! 🙇♂️
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.
Looks good! Left a minor question 🙏
if (!fieldValueMetaData.isTypedef() && !hasTypeDef(fieldValueMetaData)) { | ||
return toTypeSignature(fieldValueMetaData); | ||
} | ||
|
||
try { | ||
final Field field = parentType.getField(fieldMetaData.fieldName); | ||
return toTypeSignature(field.getGenericType()); | ||
} catch (NoSuchFieldException e) { | ||
// Ignore exception. | ||
} | ||
return TypeSignature.ofUnresolved(firstNonNull(fieldValueMetaData.getTypedefName(), "unknown")); |
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.
Question) Is it possible to just use java reflection and clean up the old logic?
I ask because if a typedef is somewhere nested inside the struct, we will use generics instead of thrift objects to traverse the object tree anyways
if (!fieldValueMetaData.isTypedef() && !hasTypeDef(fieldValueMetaData)) { | |
return toTypeSignature(fieldValueMetaData); | |
} | |
try { | |
final Field field = parentType.getField(fieldMetaData.fieldName); | |
return toTypeSignature(field.getGenericType()); | |
} catch (NoSuchFieldException e) { | |
// Ignore exception. | |
} | |
return TypeSignature.ofUnresolved(firstNonNull(fieldValueMetaData.getTypedefName(), "unknown")); | |
try { | |
final Field field = parentType.getField(fieldMetaData.fieldName); | |
return toTypeSignature(field.getGenericType()); | |
} catch (NoSuchFieldException e) { | |
// Ignore exception. | |
} | |
return TypeSignature.ofUnresolved(firstNonNull(fieldValueMetaData.getTypedefName(), "unknown")); |
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.
if a typedef is somewhere nested inside the struct, we will use generics instead of thrift objects to traverse the object tree anyways
Yes, exactly. That's why I added hasTypeDef
method.
I left the old logic because there are not so many people who use type def with Armeria(type def doesn't do anything with Java).
In that case, I thought using explicit metadata instead of using implicit reflection is better.
But not so strong on this because we can integrate the logic into one if we just use reflection.
So please let me know if you think it's better to use just reflection for all cases.
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.
My original concern was that if we have to troubleshoot anything, we would have to guess which code path was used.
Having said this, I'm also fine to go ahead with the fix and clean up later if necessary.
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.
type def doesn't do anything with Java
I think I've seen some usage with typedef to abstract logic within the thrift idl (especially if the idl becomes very long and complex)
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 got your concern. If so, what if I extract them as a method and add documentation for that? It will make it clear?
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 I've seen some usage with typedef to abstract logic within the thrift idl
Oops, I didn't know about it. 😓
So are they using DocService with the type definition?
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.
Sorry for merging the PR in the middle of the discussion.
Personally, I prefer to use expose the original type because a type alias may be used to share a type in multiple structures but DocService
shows one structure at a time.
We may improve DocService
to display both type information and alias properly somehow.
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.
We may improve DocService to display both type information and alias properly somehow.
Indeed. 😊
final Field field = parentType.getField(fieldMetaData.fieldName); | ||
return toTypeSignature(field.getGenericType()); | ||
} catch (NoSuchFieldException e) { | ||
// Ignore exception. |
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.
Question) Is there a particular exception that we wanted to ignore? If not, I wonder if debugging would help with troubleshooting potential issues
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 thought NoSuchFieldException
won't be raised and just added the catch clause because it's a checked exception.
So you mean we need to at least leave a debug log?
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 I see, I guess there's no need to leave a log if we're sure this won't happen 😅
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.
Thanks for the fix @minwoox ! 🙇 👍 🙇
Motivation:

Currently, we don't resolve the Thrift typedef fields correctly.
Modifications:
Field.getGenericType()
.i8
instead ofbyte
for Thrift 0.12+ to remove the warning.Result: