Skip to content
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

Merged
merged 6 commits into from
Dec 15, 2022
Merged

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented Dec 9, 2022

Remove FieldInfo.childFieldInfo
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 #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 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.

@minwoox minwoox added this to the 1.21.0 milestone Dec 9, 2022
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`.
@minwoox minwoox force-pushed the remove_childFieldInfos branch from 7823541 to e87613c Compare December 9, 2022 06:10
Comment on lines 221 to 226
try {
System.err.println(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(response));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Suggested change
if (typeSignature.type() == TypeSignatureType.REQUEST_OBJECT) {
if (typeSignature instanceof RequestObjectTypeSignature) {

Copy link
Contributor Author

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. 👍

Copy link
Contributor

@jrhee17 jrhee17 left a 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! 🙇 👍 🚀

Comment on lines 27 to 29
RequestObjectTypeSignature(TypeSignatureType requestObject, String name, Class<?> type,
Object annotatedValueResolvers) {
super(requestObject, name, type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fixed. 😉

Comment on lines 475 to 479
if (typeSignature.type() == TypeSignatureType.REQUEST_OBJECT) {
if (typeSignature instanceof RequestObjectTypeSignature) {
final Object annotatedValueResolvers =
((RequestObjectTypeSignature) typeSignature).annotatedValueResolvers();
if (annotatedValueResolvers instanceof AnnotatedValueResolversWrapper) {
Copy link
Contributor

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, we should. 😉

Copy link
Contributor

@ikhoon ikhoon left a 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!

@ikhoon ikhoon merged commit 6b7b1b0 into line:master Dec 15, 2022
@minwoox minwoox deleted the remove_childFieldInfos branch December 15, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants