Skip to content

Commit

Permalink
Merge pull request #5632 from andreaTP/it-initial-fixes
Browse files Browse the repository at this point in the history
Initial fixes to restore Java IT
  • Loading branch information
andrueastman authored Oct 22, 2024
2 parents 422aabe + 5954807 commit 50bd8b6
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638)
- Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844)
- Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611)
- Fixed a bug where default boolean values with quotes would fail in Java/PHP/CSharp/Go.
- Fixed a bug where composed types wrappers would not build in CSharp.
- Fixed a bug where the type name for inherited inline models would be incorrect. [#5610](https://github.com/microsoft/kiota/issues/5610)
- Fixes typing inconsistencies in generated code and libraries in Python [kiota-python#333](https://github.com/microsoft/kiota-python/issues/333)

## [1.19.1] - 2024-10-11
Expand Down
102 changes: 33 additions & 69 deletions it/config.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,4 @@
{
"oas::petstore": {
"ExcludePatterns": [
{
"Pattern": "/gists",
"Rationale": "https://github.com/github/rest-api-description/issues/214"
},
{
"Pattern": "/gists/**",
"Rationale": "https://github.com/github/rest-api-description/issues/214"
},
{
"Pattern": "/users/*/gists",
"Rationale": "https://github.com/github/rest-api-description/issues/214"
},
{
"Pattern": "/orgs/*/migrations",
"Rationale": "https://github.com/github/rest-api-description/issues/2246"
},
{
"Pattern": "/orgs/*/migrations/**",
"Rationale": "https://github.com/github/rest-api-description/issues/2246"
},
{
"Pattern": "/user/migrations",
"Rationale": "https://github.com/github/rest-api-description/issues/2246"
},
{
"Pattern": "/user/migrations/**",
"Rationale": "https://github.com/github/rest-api-description/issues/2246"
},
{
"Pattern": "/users/*/gpg_keys",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
},
{
"Pattern": "/user/gpg_keys",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
},
{
"Pattern": "/user/gpg_keys/**",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
}
],
"Suppressions": [
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
}
]
},
"./tests/Kiota.Builder.IntegrationTests/InheritingErrors.yaml": {
"MockServerITFolder": "basic",
"Suppressions": [
Expand All @@ -58,14 +8,6 @@
}
]
},
"./tests/Kiota.Builder.IntegrationTests/NoUnderscoresInModel.yaml": {
"Suppressions": [
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2374"
}
]
},
"./tests/Kiota.Builder.IntegrationTests/GeneratesUritemplateHints.yaml": {
"MockServerITFolder": "query-params",
"Suppressions": [
Expand All @@ -79,8 +21,34 @@
"MockServerITFolder": "gh",
"Suppressions": [
{
"Language": "all",
"Rationale": "https://github.com/microsoft/kiota/issues/4241"
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/5634"
},
{
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5635"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/5636"
}
],
"ExcludePatterns": [
{
"Pattern": "/users/*/gpg_keys",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
},
{
"Pattern": "/user/gpg_keys",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
},
{
"Pattern": "/user/gpg_keys/**",
"Rationale": "https://github.com/github/rest-api-description/issues/2247"
}
]
},
Expand Down Expand Up @@ -151,10 +119,6 @@
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2484"
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/2957"
}
],
"IdempotencySuppressions": []
Expand Down Expand Up @@ -229,10 +193,6 @@
},
"apisguru::stripe.com": {
"Suppressions": [
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/5256"
},
{
"Language": "java",
"Rationale": "https://github.com/microsoft/kiota/issues/2842"
Expand All @@ -248,6 +208,10 @@
{
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5354"
},
{
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/5353"
}
],
"IdempotencySuppressions": [
Expand Down Expand Up @@ -281,7 +245,7 @@
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/3030"
"Rationale": "https://github.com/microsoft/kiota/issues/5637"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion it/exec-cmd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if ($mockServerTest) {
Pop-Location

# Provision Mock server with the right spec
$openapiUrl = Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml"
$openapiUrl = (Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml") -replace '\\', '/'

# provision MockServer to mock the specific openapi description https://www.mock-server.com/mock_server/using_openapi.html#button_open_api_filepath
Retry({ Invoke-WebRequest -Method PUT -Body "{ `"specUrlOrPayload`": `"$openapiUrl`" }" -Uri http://localhost:1080/mockserver/openapi -ContentType application/json })
Expand Down
2 changes: 1 addition & 1 deletion it/get-additional-arguments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if ($language -eq "csharp") {
$command = " --output `"./it/$language/client`" --namespace-name `"app.client`""
}
elseif ($language -eq "java") {
$command = " --output `"./it/$language/src`""
$command = " --output `"./it/$language/src/apisdk`""
}
elseif ($language -eq "go") {
$command = " --output `"./it/$language/client`" --namespace-name `"integrationtest/client`""
Expand Down
16 changes: 9 additions & 7 deletions it/java/gh/src/test/java/GHAPITest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import apisdk.ApiClient;
import com.microsoft.kiota.ApiException;
import apisdk.repos.item.item.generate.GeneratePostRequestBody;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
import com.microsoft.kiota.http.OkHttpRequestAdapter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

public class BasicAPITest {
public class GHAPITest {

@Test
void basicTest() throws Exception {
Expand All @@ -17,7 +13,13 @@ void basicTest() throws Exception {
var client = new ApiClient(adapter);

client.repos().byOrgId("my-owner").byRepoId("my-repo").get();
client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(null);
final GeneratePostRequestBody body = new GeneratePostRequestBody();
body.setDescription("my description");
body.setIncludeAllBranches(true);
body.setName("my-repo2");
body.setOwner("my-owner2");
body.setPrivate(false);
client.repos().byOrgId("my-owner").byRepoId("my-repo").generate().post(body);
}

}
2 changes: 1 addition & 1 deletion it/mockserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>0.0.1-SNAPSHOT</version>

<properties>
<mockserver.version>5.14.0</mockserver.version>
<mockserver.version>5.15.0</mockserver.version>
</properties>

<build>
Expand Down
5 changes: 4 additions & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,10 @@ private CodeClass CreateInheritedModelDeclaration(OpenApiUrlTreeNode currentNode
var inlineSchemas = Array.FindAll(flattenedAllOfs, static x => !x.IsReferencedSchema());
var referencedSchemas = Array.FindAll(flattenedAllOfs, static x => x.IsReferencedSchema());
var rootSchemaHasProperties = schema.HasAnyProperty();
var className = (schema.GetSchemaName(schema.IsSemanticallyMeaningful()) is string cName && !string.IsNullOrEmpty(cName) ?
// if the schema is meaningful, we only want to consider the root schema for naming to avoid "grabbing" the name of the parent
// if the schema has no reference id we're either at the beginning of an inline schema, or expanding the inheritance tree
var shouldNameLookupConsiderSubSchemas = schema.IsSemanticallyMeaningful() || string.IsNullOrEmpty(referenceId);
var className = (schema.GetSchemaName(shouldNameLookupConsiderSubSchemas) is string cName && !string.IsNullOrEmpty(cName) ?
cName :
(!string.IsNullOrEmpty(typeNameForInlineSchema) ?
typeNameForInlineSchema :
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CSharpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
_configuration.UsesBackingStore,
static s => s,
true,
AbstractionsNamespaceName,
SerializationNamespaceName,
"IComposedTypeWrapper"
);
cancellationToken.ThrowIfCancellationRequested();
Expand Down
9 changes: 6 additions & 3 deletions src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,15 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
{
defaultValue = $"{conventions.GetTypeString(propWithDefault.Type, currentMethod).TrimEnd('?')}.{defaultValue.Trim('"').CleanupSymbolName().ToFirstCharacterUpperCase()}";
}
// avoid setting null as a string.
if (propWithDefault.Type.IsNullable &&
else if (propWithDefault.Type.IsNullable &&
defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase))
{
{ // avoid setting null as a string.
defaultValue = NullValueString;
}
else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase))
{
defaultValue = defaultValue.TrimQuotes();
}
writer.WriteLine($"{propWithDefault.Name.ToFirstCharacterUpperCase()} = {defaultValue};");
}
if (parentClass.IsOfKind(CodeClassKind.RequestBuilder) &&
Expand Down
11 changes: 10 additions & 1 deletion src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,12 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
.OrderBy(static x => x.Name))
{
var defaultValueReference = propWithDefault.DefaultValue;
if (defaultValueReference.StartsWith('"'))
if (propWithDefault.Type.IsNullable &&
defaultValueReference.TrimQuotes().Equals("null", StringComparison.OrdinalIgnoreCase))
{// avoid setting null as a string.
defaultValueReference = "nil";
}
else if (defaultValueReference.StartsWith('"'))
{
defaultValueReference = $"{propWithDefault.Name.ToFirstCharacterLowerCase()}Value";
var defaultValue = propWithDefault.DefaultValue;
Expand All @@ -580,6 +585,10 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
enumDefinition.Options.FirstOrDefault(x => x.SerializationName.Equals(defaultValue, StringComparison.OrdinalIgnoreCase))?.Name ?? defaultValue;
defaultValue = $"{defaultValue.ToUpperInvariant()}_{enumDefinition.Name.ToUpperInvariant()}";
}
else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase))
{
defaultValue = defaultValue.TrimQuotes();
}
writer.WriteLine($"{defaultValueReference} := {defaultValue}");
defaultValueReference = $"&{defaultValueReference}";
}
Expand Down
9 changes: 6 additions & 3 deletions src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho
{
defaultValue = $"{enumDefinition.Name}.forValue({defaultValue})";
}
// avoid setting null as a string.
if (propWithDefault.Type.IsNullable &&
else if (propWithDefault.Type.IsNullable &&
defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase))
{
{// avoid setting null as a string.
defaultValue = NullValueString;
}
else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase))
{
defaultValue = defaultValue.TrimQuotes();
}
writer.WriteLine($"this.{setterName}({defaultValue});");
}
if (parentClass.IsOfKind(CodeClassKind.RequestBuilder) &&
Expand Down
11 changes: 7 additions & 4 deletions src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ private void WriteModelConstructorBody(CodeClass parentClass, LanguageWriter wri
{
defaultValue = $"new {enumDefinition.Name.ToFirstCharacterUpperCase()}({defaultValue})";
}
// avoid setting null as a string.
if (propWithDefault.Type.IsNullable &&
else if (propWithDefault.Type.IsNullable &&
defaultValue.TrimQuotes().Equals(NullValueString, StringComparison.OrdinalIgnoreCase))
{
{ // avoid setting null as a string.
defaultValue = NullValueString;
}
else if (propWithDefault.Type is CodeType propType && propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase))
{
defaultValue = defaultValue.TrimQuotes();
}
writer.WriteLine($"$this->{setterName}({defaultValue});");
}
}
Expand Down Expand Up @@ -241,7 +244,7 @@ private void WritePathParametersOptions(CodeMethod currentMethod, CodeClass pare
currentMethod.Parameters.Where(static parameter => parameter.IsOfKind(CodeParameterKind.Path)).ToList()
.ForEach(parameter =>
{
var key = String.IsNullOrEmpty(parameter.SerializationName)
var key = string.IsNullOrEmpty(parameter.SerializationName)
? parameter.Name
: parameter.SerializationName;
writer.WriteLine($"{UrlTemplateTempVarName}['{key}'] = ${parameter.Name.ToFirstCharacterLowerCase()};");
Expand Down
1 change: 1 addition & 0 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ private void WriteSerializerBodyForInheritedModel(bool inherits, CodeClass paren
{
if (inherits)
writer.WriteLine("super().serialize(writer)");
_codeUsingWriter.WriteInternalImports(parentClass, writer);
foreach (var otherProp in parentClass
.GetPropertiesOfKind(CodePropertyKind.Custom)
.Where(static x => !x.ExistsInBaseType && !x.ReadOnly)
Expand Down
Loading

0 comments on commit 50bd8b6

Please sign in to comment.