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

Do not convert first char to upper on type names during code model construction #2861

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Use schematized types for 206 response codes instead of binary. [#2880](https://github.com/microsoft/kiota/issues/2880)
- Typenames are not changed to first char upper case in comments in some cases.

## [1.4.0] - 2023-07-07

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ public static class OpenApiReferenceExtensions
public static string GetClassName(this OpenApiReference? reference)
{
if (reference?.Id is string referenceId && !string.IsNullOrEmpty(referenceId))
return referenceId[(referenceId.LastIndexOf('.') + 1)..]
.ToFirstCharacterUpperCase();
return referenceId[(referenceId.LastIndexOf('.') + 1)..];
return string.Empty;
}
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
writer.StartBlock($"{errorMappingVarName}: Dict[str, ParsableFactory] = {{");
foreach (var errorMapping in codeElement.ErrorMappings)
{
writer.WriteLine($"\"{errorMapping.Key.ToUpperInvariant()}\": {errorMapping.Value.Name},");
writer.WriteLine($"\"{errorMapping.Key.ToUpperInvariant()}\": {errorMapping.Value.Name.ToFirstCharacterUpperCase()},");
}
writer.CloseBlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void GetsClassName()
{
Id = "microsoft.graph.user"
};
Assert.Equal("User", reference.GetClassName());
Assert.Equal("user", reference.GetClassName());
}
[Fact]
public void GetsClassNameDefensive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,6 @@ public void GetsClassNameWithSegmentsToSkipForClassNames()
.GetClassName(new() { "application/json" }, schema: responseSchema);

// validate that we get a valid class name
Assert.Equal("Json", responseClassName);
Assert.Equal("json", responseClassName);
}
}
24 changes: 12 additions & 12 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,7 @@ public void InheritedTypeWithInlineSchemaWorks()
Assert.NotNull(requestExecutorMethod);
var executorReturnType = requestExecutorMethod.ReturnType as CodeType;
Assert.NotNull(executorReturnType);
Assert.Contains("DerivedObject", requestExecutorMethod.ReturnType.Name);
Assert.Contains("derivedObject", requestExecutorMethod.ReturnType.Name);
var secondLevelDerivedClass = codeModel.FindChildByName<CodeClass>("derivedObject");
Assert.NotNull(secondLevelDerivedObject);
var factoryMethod = secondLevelDerivedClass.GetChildElements(true).OfType<CodeMethod>().FirstOrDefault(x => x.IsOfKind(CodeMethodKind.Factory));
Expand Down Expand Up @@ -4307,7 +4307,7 @@ public void AcceptVendorsTypes(string contentType)
Assert.NotNull(rbClass);
var executorMethod = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get);
Assert.NotNull(executorMethod);
Assert.Equal("Myobject", executorMethod.ReturnType.Name);
Assert.Equal("myobject", executorMethod.ReturnType.Name);
}
[Fact]
public void ModelsUseDescriptionWhenAvailable()
Expand Down Expand Up @@ -4374,15 +4374,15 @@ public void ModelsUseDescriptionWhenAvailable()
[InlineData("application/json", "205", false, "default", "void")]
[InlineData("application/json", "204", true, "default", "void")]
[InlineData("application/json", "204", false, "default", "void")]
[InlineData("application/json", "203", true, "default", "Myobject")]
[InlineData("application/json", "203", true, "default", "myobject")]
[InlineData("application/json", "203", false, "default", "binary")]
[InlineData("application/json", "202", true, "default", "Myobject")]
[InlineData("application/json", "202", true, "default", "myobject")]
[InlineData("application/json", "202", false, "default", "void")]
[InlineData("application/json", "201", true, "default", "Myobject")]
[InlineData("application/json", "201", true, "default", "myobject")]
[InlineData("application/json", "201", false, "default", "void")]
[InlineData("application/json", "200", true, "default", "Myobject")]
[InlineData("application/json", "200", true, "default", "myobject")]
[InlineData("application/json", "200", false, "default", "binary")]
[InlineData("application/json", "2XX", true, "default", "Myobject")]
[InlineData("application/json", "2XX", true, "default", "myobject")]
[InlineData("application/json", "2XX", false, "default", "binary")]
[InlineData("application/xml", "204", true, "default", "void")]
[InlineData("application/xml", "204", false, "default", "void")]
Expand Down Expand Up @@ -4410,7 +4410,7 @@ public void ModelsUseDescriptionWhenAvailable()
[InlineData("*/*", "200", false, "default", "binary")]
[InlineData("text/plain", "204", true, "default", "void")]
[InlineData("text/plain", "204", false, "default", "void")]
[InlineData("text/plain", "200", true, "default", "Myobject")]
[InlineData("text/plain", "200", true, "default", "myobject")]
[InlineData("text/plain", "200", false, "default", "string")]
[InlineData("text/plain", "204", true, "application/json", "void")]
[InlineData("text/plain", "204", false, "application/json", "void")]
Expand Down Expand Up @@ -4587,7 +4587,7 @@ public void Considers200WithSchemaOver2XXWithSchema()
Assert.NotNull(rbClass);
var executor = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor));
Assert.NotNull(executor);
Assert.Equal("Myobject", executor.ReturnType.Name);
Assert.Equal("myobject", executor.ReturnType.Name);
}
[Fact]
public void Considers2XXWithSchemaOver204WithNoSchema()
Expand Down Expand Up @@ -4660,7 +4660,7 @@ public void Considers2XXWithSchemaOver204WithNoSchema()
Assert.NotNull(rbClass);
var executor = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor));
Assert.NotNull(executor);
Assert.Equal("Myobject", executor.ReturnType.Name);
Assert.Equal("myobject", executor.ReturnType.Name);
}
[Fact]
public void Considers204WithNoSchemaOver206WithNoSchema()
Expand Down Expand Up @@ -4729,7 +4729,7 @@ public void Considers204WithNoSchemaOver206WithNoSchema()
Assert.NotNull(executor);
Assert.Equal("void", executor.ReturnType.Name);
}
[InlineData("application/json", true, "default", "Myobject")]
[InlineData("application/json", true, "default", "myobject")]
[InlineData("application/json", false, "default", "binary")]
[InlineData("application/xml", false, "default", "binary")]
[InlineData("application/xml", true, "default", "binary")] //MyObject when we support it
Expand All @@ -4744,7 +4744,7 @@ public void Considers204WithNoSchemaOver206WithNoSchema()
[InlineData("*/*", true, "default", "binary")]
[InlineData("*/*", false, "default", "binary")]
[InlineData("text/plain", false, "default", "binary")]
[InlineData("text/plain", true, "default", "Myobject")]
[InlineData("text/plain", true, "default", "myobject")]
[InlineData("text/plain", true, "application/json", "binary")]
[InlineData("text/plain", false, "application/json", "binary")]
[InlineData("text/yaml", true, "application/json", "binary")]
Expand Down