Skip to content

Improve numberOfUsages calculation #10

Open
@neiser

Description

@neiser

Currently, the numberOfUsages parameter for ReferenceDeciderForType is calculated by the number of setters which are going to consume the referenced item. This is a good estimate, but in general not correct for any case: For example, consider a Schema which is multiply used by identical ApiResponses, but in turn this ApiResponse is also referenced itself. Then the actual usage of that schema is 1, as the Schema is only used by one ApiResponse, but the number of setters is not merged in AbstractReferencedItemStorage, as the referencing of ApiResponses happens later than the referencing of Schemas.

Have a look at AbstractReferencedItemStorage method for a starting idea:

    @Nullable
    private Object findSetterTarget(Consumer<T> setter) {
        Field[] declaredFields = setter.getClass().getDeclaredFields();
        if (declaredFields.length == 1) {
            Field declaredField = declaredFields[0];
            declaredField.setAccessible(true);
            try {
                return declaredField.get(setter);
            } catch (IllegalAccessException e) {
                // this should not happen, as we've made it accessible...
                return null;
            }
        }
        return null;
    }

This is a hard issue, but you can learn a lot about how referencing of items is done internally in this library.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions