-
Notifications
You must be signed in to change notification settings - Fork 926
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
Remove FieldInfo.childFieldInfo #4566
Conversation
Motivation: We have introduced `TypeSignature` not to parse a struct type in place when creating `DocService` but put the struct in the list of `StructInfo` and link to it using `TypeSignature` in line#422. We could have the definition of a struct in only one place so we could dedup the information. However, we have started to parse a bean(which is a struct) in place to represent a `@RequestObject` type in line#1557. To represent the type, `FieldInfo.childFieldInfo` was added and it turned out to be a bad decision. Because after that, we have lots of duplicate information on structs. Also, the way that some of the structs use a link using `TypeSignature` whereas the rest of them don't, brought us the inconsistency of parsing and reorganizing the `DocService`. Modifications: - Remove `FieldInfo.childFieldInfos`. - `FieldInfo` now has only a `TypeSignature` and uses the `TypeSignature` to link to the corresponding struct. - The nested struct is not parsed in place. - Add `REQUEST_OBJECT` `TypeSignature` for a `@RequestObject`. - `FieldInfo`'s name for a `@RequestObject` is now the parameter name. - It was `class.getSimpleName` before which doesn't represent the field information properly. Result: - Unified way to create and organize `DocService`.
7823541
to
e87613c
Compare
try { | ||
System.err.println( | ||
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(response)); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} |
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.
Revert?
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.
Oops. 😓
@@ -489,6 +472,15 @@ private static DescriptiveTypeInfo newDescriptiveTypeInfo( | |||
return descriptiveTypeInfo; | |||
} | |||
|
|||
if (typeSignature.type() == TypeSignatureType.REQUEST_OBJECT) { |
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.
RequestObjectTypeSignature
could be exposed to users through a custom DescriptiveTypeInfoProvider
. They might find it difficult to interpret TypeSignatureType.REQUEST_OBJECT
. Because AnnotatedValueResolversWrapper
is an internal class that users can't access and RequestObjectTypeSignature
is an internal API.
I guess you don't want users to allow accessing RequestObjectTypeSignature
since you located it in the internal package. If so, we should also hide REQUEST_OBJECT
from the prospect of users' view? We may set the TypeSignatureType
to TypeSignatureType.STRUCT
and extract AnnotatedValueResolversWrapper
if the type is RequestObjectTypeSignature
.
if (typeSignature.type() == TypeSignatureType.REQUEST_OBJECT) { | |
if (typeSignature instanceof RequestObjectTypeSignature) { |
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.
This is a brilliant idea. 👍
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 about the late review 😅 I really like the new flow 👍 Thanks @minwoox for the cleanup! 🙇 👍 🚀
...src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedDocServicePlugin.java
Show resolved
Hide resolved
RequestObjectTypeSignature(TypeSignatureType requestObject, String name, Class<?> type, | ||
Object annotatedValueResolvers) { | ||
super(requestObject, name, type); |
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.
RequestObjectTypeSignature(TypeSignatureType requestObject, String name, Class<?> type, | |
Object annotatedValueResolvers) { | |
super(requestObject, name, type); | |
RequestObjectTypeSignature(TypeSignatureType type, String name, Class<?> clazz, | |
Object annotatedValueResolvers) { | |
super(type, name, clazz); |
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 fixed. 😉
if (typeSignature.type() == TypeSignatureType.REQUEST_OBJECT) { | ||
if (typeSignature instanceof RequestObjectTypeSignature) { | ||
final Object annotatedValueResolvers = | ||
((RequestObjectTypeSignature) typeSignature).annotatedValueResolvers(); | ||
if (annotatedValueResolvers instanceof AnnotatedValueResolversWrapper) { |
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 we move this block before DescriptiveTypeInfo descriptiveTypeInfo = provider.newDescriptiveTypeInfo(typeDescriptor);
?
// RequestObjectTypeSignature which is internal class should not be exposed
// externally via the provider.
if (typeSignature instanceof RequestObjectTypeSignature) {
return ...
}
...
DescriptiveTypeInfo descriptiveTypeInfo = provider.newDescriptiveTypeInfo(typeDescriptor);
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.
Ah yes, we should. 😉
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! 💯💯Left a minor comment!
Remove
FieldInfo.childFieldInfo
Motivation:
We have introduced
TypeSignature
not to parse a struct type in place when creatingDocService
but put the struct in the list ofStructInfo
and link to it usingTypeSignature
in #422.We could have the definition of a struct in only one place so we could dedup the information.
However, we have started to parse a bean(which is a struct) in place to represent a
@RequestObject
type in #1557.To represent the type,
FieldInfo.childFieldInfo
was added and it turned out to be a bad decision.Because after that, we have lots of duplicate information on structs. Also, the way that some of the structs use a link using
TypeSignature
whereas the rest of them don't, brought us the inconsistency of parsing and reorganizing theDocService
.Modifications:
FieldInfo.childFieldInfos
.FieldInfo
now has only aTypeSignature
and uses theTypeSignature
to link to the corresponding struct.REQUEST_OBJECT
TypeSignature
for a@RequestObject
.FieldInfo
's name for a@RequestObject
is now the parameter name.class.getSimpleName
before which doesn't represent the field information properly.Result:
DocService
.