Skip to content

Commit

Permalink
fix optional body type and request configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
shemogumbe committed May 2, 2024
1 parent bc3dbe7 commit ec569b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
27 changes: 5 additions & 22 deletions src/Kiota.Builder/Refiners/PythonRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,15 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
Name = $"{AbstractionsPackageName}.base_request_configuration",
IsExternal = true
}
},
},
new CodeType
{
Name = "DefaultQueryParameters",
Name = "QueryParameters",
IsExternal = true,
},
keepRequestConfigurationClass: true,
addDeprecation: true
);

// RemoveRequestConfigurationClasses(generatedCode,
// new CodeUsing
// {
// Name = "RequestConfiguration",
// Declaration = new CodeType
// {
// Name = $"{AbstractionsPackageName}.base_request_configuration",
// IsExternal = true
// }
// },
// new CodeType
// {
// Name = "QueryParameters",
// IsExternal = true,
// },
// keepRequestConfigurationClass: true,
// addDeprecation: true
// );
);
AddDefaultImports(generatedCode, defaultUsingEvaluators);
CorrectCoreType(generatedCode, CorrectMethodType, CorrectPropertyType, CorrectImplements);
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -192,6 +173,8 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
$"{AbstractionsPackageName}.request_information", "RequestInformation"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestGenerator),
$"{AbstractionsPackageName}.request_option", "RequestOption"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestGenerator),
$"{AbstractionsPackageName}.default_query_parameters", "QueryParameters"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Serializer),
SerializationModuleName, "SerializationWriter"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Deserializer),
Expand Down
7 changes: 5 additions & 2 deletions src/Kiota.Builder/Writers/Python/PythonConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override string GetParameterSignature(CodeParameter parameter, CodeElemen
var defaultValueSuffix = string.IsNullOrEmpty(parameter.DefaultValue) ? string.Empty : $" = {parameter.DefaultValue}";
var deprecationInfo = GetDeprecationInformation(parameter);
var deprecationSuffix = string.IsNullOrEmpty(deprecationInfo) ? string.Empty : $"# {deprecationInfo}";
return $"{parameter.Name}: {(parameter.Type.IsNullable ? "Optional[" : string.Empty)}{GetTypeString(parameter.Type, targetElement, true, writer)}{(parameter.Type.IsNullable ? "] = None" : string.Empty)}{defaultValueSuffix}{deprecationSuffix}";
return $"{parameter.Name}: {(parameter.Optional ? "Optional[" : string.Empty)}{GetTypeString(parameter.Type, targetElement, true, writer)}{(parameter.Optional ? "] = None" : string.Empty)}{defaultValueSuffix}{deprecationSuffix}";
}
private static string GetTypeAlias(CodeType targetType, CodeElement targetElement)
{
Expand Down Expand Up @@ -87,7 +87,10 @@ public override string GetTypeString(CodeTypeBase code, CodeElement targetElemen
typeName = targetElement.Parent.Name;
if (code.ActionOf && writer != null)
return WriteInlineDeclaration(currentType, targetElement, writer);
return $"{collectionPrefix}{typeName}{collectionSuffix}";
var genericParameters = currentType.GenericTypeParameterValues.Count != 0 ?
$"[{string.Join(", ", currentType.GenericTypeParameterValues.Select(x => GetTypeString(x, targetElement, includeCollectionInformation)))}]" :
string.Empty;
return $"{collectionPrefix}{typeName}{genericParameters}{collectionSuffix}";
}

throw new InvalidOperationException($"type of type {code.GetType()} is unknown");
Expand Down

0 comments on commit ec569b3

Please sign in to comment.