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

BackingStore fixes for Java #3643

Closed
wants to merge 10 commits into from
Closed

Conversation

ramsessanchez
Copy link
Contributor

@ramsessanchez ramsessanchez commented Nov 2, 2023

  • getAdditionalData method body when backingStore is enabled is fixed
 //Current
    public Map<String, Object> getAdditionalData() {
        Map<String, Object> value = this.BackingStore");
 //Fix
    public Map<String, Object> getAdditionalData() {
        Map<String, Object> value = this.BackingStore.get("additionalData");
  • SetBackingStore method body is fixed.
  • Annotations for setBackingStore parameter is added.
 //Current
    public void setBackingStore(final BackingStore value) {
        this.getBackingStore().set("BackingStore", value);
    }
 //Fix
    public void setBackingStore(@jakarta.annotation.Nonnull final BackingStore value) {
        Objects.requireNonNull(value);
        this.BackingStore = value;
    }
  • serialize method would not write additional data when backing store was enabled due to it's reliance on the additional data property which is not present when backing store is enabled. Now it will write based on whether there is a method with an AccessedProperty of kind additionalData.
 //Current
    public void serialize(@jakarta.annotation.Nonnull final SerializationWriter writer) {
        Objects.requireNonNull(writer);
        writer.writeStringValue("x", this.getX());
    }
 //Fix
    public void serialize(@jakarta.annotation.Nonnull final SerializationWriter writer) {
        Objects.requireNonNull(writer);
        writer.writeStringValue("x", this.getX());
        writer.writeAdditionalData(this.getAdditionalData());
    }

-Import statements for additionalDataHolder and enumSet were previously based on class properties, when backing store is enabled these properties are not generated so the import statements are missing.
Instead, the import statements are now based on the AccessedProperty of the methods present in the class.

@ramsessanchez ramsessanchez requested a review from a team as a code owner November 2, 2023 21:49
@andrueastman
Copy link
Member

@ramsessanchez I notice in the generation at microsoftgraph/msgraph-sdk-java#1600 there are still failures for the nullability annotations for contentType parameter added in requestbuilders. Any chance we can fix that first?

CHANGELOG.md Outdated
@@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed a bug where query parameter enum reusable types would be trimmed. [#3637](https://github.com/microsoft/kiota/issues/3637)
- Fixes bug where import statements for additionalDataHolder and enumSet are missing when BackingStore is enabled in java. [#3643](https://github.com/microsoft/kiota/pull/3643)
Copy link
Member

Choose a reason for hiding this comment

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

please move this to the change section under the unreleased version

@@ -1502,7 +1502,6 @@ public void WritesSerializerBody()
Assert.Contains("writeCollectionOfPrimitiveValues", result);
Assert.Contains("writeCollectionOfObjectValues", result);
Assert.Contains("writeEnumValue", result);
Assert.Contains("writeAdditionalData(this.getAdditionalData());", result);
Copy link
Member

Choose a reason for hiding this comment

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

can you provide more context on why this is being removed? it feels like we should keep it

Copy link
Contributor Author

@ramsessanchez ramsessanchez Nov 3, 2023

Choose a reason for hiding this comment

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

Via the change we add the additionalData serialization through the accessedProperty not on the class properties themselves, the test covers the case where the property is added, however that will not lead to the serialization since the getter is not present. The correct test would be to add the additionalData getter and show that the serializer will in fact generate this. I think the serializer method should rely on the accessedProperties of the available getters as this will ensure that the getSomeProperty() method will be available. For context this is the change:

        var additionalDataProperty = parentClass.GetPropertyOfKind(CodePropertyKind.AdditionalData);

        if (additionalDataProperty != null)
            writer.WriteLine($"writer.writeAdditionalData(this.get{additionalDataProperty.Name.ToFirstCharacterUpperCase()}());");

I considered the following where we actually have both conditions, let me know your thoughts

if (parentClass.Methods.Any(x => x.AccessedProperty?.IsOfKind(CodePropertyKind.AdditionalData) ?? false) || 
parentClass.Properties.Any(x => x?.IsOfKind(CodePropertyKind.AdditionalData) ?? false))

Copy link
Member

Choose a reason for hiding this comment

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

thanks for clarifying. Please make that change instead (getter + accessed property) and restore the line in the unit test

@ramsessanchez
Copy link
Contributor Author

@ramsessanchez I notice in the generation at microsoftgraph/msgraph-sdk-java#1600 there are still failures for the nullability annotations for contentType parameter added in requestbuilders. Any chance we can fix that first?

Yes, I noticed that as well, I believe this is another side effect of the backingStore being enabled as these parameters are not present in generation when backing store is disabled.

@ramsessanchez
Copy link
Contributor Author

Pausing on this work for now to focus on the async to sync revert work.

Copy link

sonarcloud bot commented Nov 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

92.0% 92.0% Coverage
0.0% 0.0% Duplication

@ramsessanchez
Copy link
Contributor Author

Superseded by #3702

@ramsessanchez ramsessanchez deleted the rsh/backingStore_bugfix_java branch November 16, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants