Skip to content

Commit

Permalink
Do not convert first char to upper on type names during code model co…
Browse files Browse the repository at this point in the history
…nstruction

Types are sometimes created with an upper case type name and sometimes
with a lower case type name. This has no functional effect on the
resulting code, because the writers will do this, but the converted name
can end up in the comment. The comment should follow the spec and should
be stable as much as possible.
  • Loading branch information
papegaaij committed Jul 6, 2023
1 parent 6c91138 commit 58a0865
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix failing PHP integration tests [2378](https://github.com/microsoft/kiota/issues/2378)
- Prevents method overloading for go getters and setters with different values. [#2719](https://github.com/microsoft/kiota/issues/2719)
- Fixed PHP request executor methods that return enums.
- Typenames are not changed to first char upper case in comments in some cases.

## [1.3.0] - 2023-06-09

Expand Down
3 changes: 1 addition & 2 deletions src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs
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;
}
}
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

0 comments on commit 58a0865

Please sign in to comment.