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

Fix bug from generation of model names #4817

Merged
merged 10 commits into from
Jul 2, 2024
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixes bug with model names in Go generated from camel case namespace. [https://github.com/microsoftgraph/msgraph-sdk-go/issues/721]
- Plugins OpenAPI extensions are only added when generating plugins to reduce the risk of parsing errors. [#4834](https://github.com/microsoft/kiota/issues/4834)
- TypeScript imports are now using ES6 imports with the .js extension.
- Remove LINQ usage in generated code.
- Ensures descriptions are not empty in sliced OpenApi file when generating a plugin.
- Plugins do not emit parameters anymore. [#4841](https://github.com/microsoft/kiota/issues/4841)
- References to C# types generated by kiota are prefixed with `global::` to avoid name collisions. [#4796](https://github.com/microsoft/kiota/issues/4796)


## [1.15.0] - 2024-06-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
{
cancellationToken.ThrowIfCancellationRequested();
DeduplicateErrorMappings(generatedCode);
NormalizeNamespaceNames(generatedCode);
MoveRequestBuilderPropertiesToBaseType(generatedCode,
new CodeUsing
{
Expand All @@ -40,13 +39,14 @@
FlattenNestedHierarchy(generatedCode);
FlattenGoParamsFileNames(generatedCode);
FlattenGoFileNames(generatedCode);
NormalizeNamespaceNames(generatedCode);
AddInnerClasses(
generatedCode,
true,
string.Empty,
false,
MergeOverLappedStrings);
if (_configuration.ExcludeBackwardCompatible) //TODO remove condition for v2

Check warning on line 49 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)

Check warning on line 49 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
RemoveRequestConfigurationClasses(generatedCode,
new CodeUsing
{
Expand Down Expand Up @@ -183,7 +183,7 @@
);
AddParsableImplementsForModelClasses(
generatedCode,
"Parsable"

Check warning on line 186 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'Parsable' 5 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)

Check warning on line 186 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'Parsable' 5 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
);
RenameInnerModelsToAppended(
generatedCode
Expand Down Expand Up @@ -240,7 +240,7 @@
return $"{start}{end}";
}

private void CorrectBackingStoreTypes(CodeElement currentElement)

Check warning on line 243 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 243 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (!_configuration.UsesBackingStore)
return;
Expand Down Expand Up @@ -381,7 +381,7 @@
.ToList();

// check if the last element contains current name and remove it
if (namespacePathSegments.Count > 0 && removeDuplicate && fileName.ToFirstCharacterUpperCase().Contains(namespacePathSegments.Last(), StringComparison.Ordinal))

Check warning on line 384 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Indexing at Count-1 should be used instead of the "Enumerable" extension method "Last" (https://rules.sonarsource.com/csharp/RSPEC-6608)
namespacePathSegments.RemoveAt(namespacePathSegments.Count - 1);

namespacePathSegments.Add(fileName.ToFirstCharacterUpperCase());
Expand Down Expand Up @@ -545,7 +545,7 @@
"UUID",
"Guid"
};
private static readonly AdditionalUsingEvaluator[] defaultUsingEvaluators = {

Check warning on line 548 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 24 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 548 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 24 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.RequestAdapter),
AbstractionsNamespaceName, "RequestAdapter"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestGenerator),
Expand Down Expand Up @@ -603,7 +603,7 @@
block.ReplaceImplementByName(KiotaBuilder.AdditionalHolderInterface, "AdditionalDataHolder");
block.ReplaceImplementByName(KiotaBuilder.BackedModelInterface, "BackedModel");
}
private static void CorrectMethodType(CodeMethod currentMethod)

Check warning on line 606 in src/Kiota.Builder/Refiners/GoRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
var parentClass = currentMethod.Parent as CodeClass;
if (currentMethod.IsOfKind(CodeMethodKind.RequestGenerator, CodeMethodKind.RequestExecutor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,12 @@ public async Task NormalizeNamespaceName()
root.Name = "github.com/OrgName/RepoName";
var models = root.AddNamespace("ApiSdk.models");
var submodels = models.AddNamespace("ApiSdk.models.submodels");
var camelCaseModel = submodels.AddNamespace("ApiSdk.models.submodels.camelCase");
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go, ClientNamespaceName = "github.com/OrgName/RepoName" }, root);
Assert.Equal("github.com/OrgName/RepoName.apisdk.models.submodels", submodels.Name);
Assert.Equal("github.com/OrgName/RepoName.apisdk.models", models.Name);
Assert.Equal("github.com/OrgName/RepoName.apisdk.models.submodels.camelcase", camelCaseModel.Name);
}

#endregion
}
Loading