This repository was archived by the owner on Jul 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
fix duplicate setter methods #1322
Merged
XiaofeiCao
merged 11 commits into
Azure:main
from
XiaofeiCao:fix_duplicate_setter_methods
Jan 24, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
133c985
refactor and add test scaffold
XiaofeiCao b55ce59
feature add, test adjust
XiaofeiCao bd5f58e
fix code issue
XiaofeiCao c5a3e6a
remove unused code
XiaofeiCao da09ed8
revert unnecessary changes
XiaofeiCao cb0a208
variable name change
XiaofeiCao 5e91954
load code model
XiaofeiCao 3eba80c
Merge branch 'Azure:main' into fix_duplicate_setter_methods
XiaofeiCao 7f92006
add to fluent-tests
XiaofeiCao c6b98e8
fluent-tests add serialize and deserialize
XiaofeiCao a1ce372
clear unused imports
XiaofeiCao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
fluentgen/src/test/java/com/azure/autorest/fluent/template/ModelTemplateTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| */ | ||
|
|
||
|
|
||
| package com.azure.autorest.fluent.template; | ||
|
|
||
| import com.azure.autorest.extension.base.model.codemodel.CodeModel; | ||
| import com.azure.autorest.extension.base.plugin.JavaSettings; | ||
| import com.azure.autorest.fluent.FluentGenAccessor; | ||
| import com.azure.autorest.fluent.TestUtils; | ||
| import com.azure.autorest.mapper.ClientMapper; | ||
| import com.azure.autorest.model.clientmodel.Client; | ||
| import com.azure.autorest.model.clientmodel.ClientModel; | ||
| import com.azure.autorest.model.clientmodel.ClientModelPropertyAccess; | ||
| import com.azure.autorest.model.clientmodel.ClientModelPropertyReference; | ||
| import com.azure.core.util.CoreUtils; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ModelTemplateTests { | ||
|
|
||
| private final JavaSettings settings = JavaSettings.getInstance(); | ||
| private static FluentGenAccessor fluentGenAccessor; | ||
|
|
||
| @BeforeAll | ||
| public static void init(){ | ||
| TestUtils.MockFluentGen fluentgen = new TestUtils.MockFluentGen(); | ||
| fluentGenAccessor = new FluentGenAccessor(fluentgen); | ||
| } | ||
|
|
||
| /** | ||
| * Issue: https://github.com/Azure/autorest.java/issues/1320 | ||
| * Remove duplicate setter methods from child schema when parent schema contains same property | ||
| * mainly to test {@link com.azure.autorest.template.ModelTemplate#getParentSettersToOverride(ClientModel, JavaSettings, List)} | ||
| */ | ||
| @Test | ||
| public void deduplicateTest(){ | ||
| CodeModel codeModel = TestUtils.loadCodeModel(fluentGenAccessor, "code-model-fluentnamer-botservice.yaml"); | ||
| Client client = ClientMapper.getInstance().map(codeModel); | ||
| ClientModel model = client.getModels().stream().filter(clientModel -> clientModel.getName().equals("Site")).findAny().get(); | ||
| ModelTemplateAccessor templateAccessor = new ModelTemplateAccessor(); | ||
| List<ClientModelPropertyReference> propertyReferences = templateAccessor.getClientModelPropertyReferences0(model); | ||
| if (!CoreUtils.isNullOrEmpty(model.getPropertyReferences())) { | ||
| propertyReferences.addAll(model.getPropertyReferences()); | ||
| } | ||
| // real test here | ||
| List<ClientModelPropertyAccess> toOverride = templateAccessor.getParentSettersToOverride(model, settings, propertyReferences); | ||
| Assertions.assertEquals(toOverride.size(), 1); | ||
| } | ||
|
|
||
| private static class ModelTemplateAccessor extends FluentModelTemplate { | ||
|
|
||
| public List<ClientModelPropertyReference> getClientModelPropertyReferences0(ClientModel model) { | ||
| return super.getClientModelPropertyReferences(model); | ||
| } | ||
|
|
||
| public List<ClientModelPropertyAccess> getParentSettersToOverride(ClientModel model, JavaSettings settings, List<ClientModelPropertyReference> propertyReferences) { | ||
| return super.getParentSettersToOverride(model, settings, propertyReferences); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.